-1

I know that the threads ListPlot with each point a different color and a legend bar and Extracting the coordinate of a particular point of interest from a ListPlot are somehow the answers to my questions but I am having a hard time understanding them when trying to apply them to the following problem:

ListPlot[{{0,1},{0,0},{1,0},{1,1},{0.5,0.2}},
   PlotStyle->Directive[PointSize[Large]]]

The x-coordinate of the first four points won't change; only the y-coordinate will. {0,1} and {1,0} must have the same color; {0,0} and {1,1} must have the same colour but different from the first case and {0.5,0.2} a different color when compared to the other two cases. The resulting plot must also have the value of the y-coordinate for each point shown all the time (no need to click a mouse or the like).

I believe that the solution should be self-contained within ListPlot since I am planning to use it inside a Manipulate with other plots.

Ed Mendes
  • 618
  • 5
  • 11
  • not so clear to understand the question. make 5 points three different colors? – HyperGroups May 24 '13 at 14:45
  • Yes. The first and the fourth have the same colour; the second and third point have the same colour but different from the previous set of points and finally the fifth point has a different colour when compared to the other two set of points. – Ed Mendes May 24 '13 at 14:57
  • What's the role of Tooltip? another question is whether the 5 points generated by some pattern or just this case. My first thought is split 5-points list to 3 sublists, but if could be split by hand is much easier. If with some pattern, should,,, – HyperGroups May 24 '13 at 15:36

2 Answers2

2

You can split the list of points into sublists and apply a different style for each sublist using PlotStyle.

For the labeling, I have not found any ListPlot option capable of this, but you can render labels manually with Epilog and Text:

data = {{{0, 1}, {1, 0}}, {{0, 0}, {1, 1}}, {{0.5, 0.2}}};

ListPlot[data,
  PlotStyle -> {Directive[Red,PointSize[Large]], Blue, Gray},
  Epilog -> Map[Text[Round[Last@#, .1], # + .05] &, data, {Depth@data-2}]]

Comments and explanations:

  • Text is Mapped at level "Depth of data -2", so it will be compatible with lists of different depths.
  • By doing so, {x,y} is fed to the Text pure function, so Last@# yields the y value.
  • Replace Round[, .1] by any formatting function you like (e.g. NumberForm).
  • I have used # + .05 as the coordinate, so the label for the point {0,1} will be placed at {0.05, 1.05}. You might want to change this according to your plot and point size and use different values for x and y translation using +{x,y}.
Theo Tiger
  • 1,273
  • 8
  • 10
  • seems he need something tooltip? – HyperGroups May 24 '13 at 15:16
  • I know he wrote tooltip, but then: "The resulting ListPlot must also have the value of the y-coordinate for each point showed all the time." ... sounded more like a static label to me? – Theo Tiger May 24 '13 at 15:23
  • First of all, many thanks. Yes, it sounds like a static label. When I added PlotRange-> {{-0.5,1.5},{-0.5,1.5}} to see the labels, the size of the points have changed. Is that right? One final question - How can this solution be used inside Manipulate (y-values will change according to some rule) where only the plot is shown? – Ed Mendes May 24 '13 at 17:23
  • Hm, the point size does not change with PlotRange. To play with the point size, have a look at PointSize and AbsolutePointSize in the documentation.

    You can use something like: Manipulate[With[{data = {{0,1}, {1,manipulated+4}}}, (* -- your plot code here -- *)], {manipulated,0,10}]

    – Theo Tiger May 25 '13 at 13:18
1

Not so clear about tooltip and something else.

list={{0,1},{0,0},{1,0},{1,1},{0.5,0.2}}
listNew=(GatherBy[Most@list,OddQ[Position[list,#]]&])//Append[#,{Last@list}]&
ListPlot[listNew,PlotStyle->Directive[PointSize@Large]]

how to generate the sublists depend on the some patterns.

listNew=Partition[Permute[list,AlternatingGroup[3]]//Last,2,2,1,{}]

enter image description here

HyperGroups
  • 8,619
  • 1
  • 26
  • 63