1
$\begingroup$

I changed the original question, to clarify what I need

I have 2 Lists, e.g.

pData1=Table[{{i, i}}, {i, Range[1, 50, 2]}];
pData2=pData1;

and corresponding markers, e.g.

marker1=Table[Style["a" <> ToString[i], Red], {i, Range[1, 50, 2]}];
marker2=Table[Style["b" <> ToString[i], Blue], {i, Range[1, 50, 2]}];

The problem

consider the following

Show[
 ListPlot[pData1,
  PlotMarkers -> marker1,
  ImageSize -> Large],
 ListPlot[pData2,
  PlotMarkers -> marker2,
  ImageSize -> Large]
 ]

enter image description here

which clearly makes it impossible the read both marker entries, since they overlap overlapping.

My current solution

What I want to have is both lists in one plot with non-overlapping markers. Consider the following minimal working example. My idea so far, plot both separately using ListPlot but with slightly changed points, e.g. the red marker of {1,1} appears at {0,1} while the blue marker appears at {2,1}. Finally I combine both using Show.

Show[
 ListPlot[Map[# - {{1, 0}} &, pData1],
  PlotMarkers -> marker1,
  ImageSize -> Large],
 ListPlot[Map[# + {{1, 0}} &, pData2],
  PlotMarkers -> marker2,
  ImageSize -> Large]
 ]

enter image description here

I guess, there is a nicer and easier solution, which also represents the markers in a better way then my current idea does.

Note:

  • pData1 and pData2 can be different. Therefore it is not an option to just use, say pData1 and create a new marker list which account for marker1 and marker2.

  • there will be a lot of points in the plane, so the solution should use a minimum on space

Bob Hanlon's solution adjusted to my needs

For completeness I also add his solution. Which, unfortunately does not fit my needs completely since it's to space consuming when there are a lot of points. However its a nice way of labeling only certain points.

pData1 = Table[{i, i}, {i, Range[1, 50, 2]}];
pData2 = pData1;
ListPlot[
 {Callout[pData1[[#]], marker1[[#]], Above, CalloutStyle -> Red] & /@ 
   Range[Length[pData1]], 
  Callout[pData2[[#]], marker2[[#]], Below, CalloutStyle -> Blue] & /@
    Range[Length[pData2]]},
 PlotStyle -> {{AbsolutePointSize[8], Red}, {AbsolutePointSize[4], 
    Blue}},
 PlotLegends -> {"pData1", "pData2"},
 ImageSize -> Large]
$\endgroup$
4
  • $\begingroup$ Is it just two list of numbers or is it two list of pairs of numbers? $\endgroup$
    – Edmund
    Dec 19, 2016 at 1:58
  • $\begingroup$ To each list of pairs corresponds a list of numbers. I.e. marker1 are the marker for pData1 and the same for the other lists. $\endgroup$
    – Stefan
    Dec 19, 2016 at 7:01
  • $\begingroup$ Related Q/A: ListPlot with lots of same couples of values $\endgroup$
    – kglr
    Dec 19, 2016 at 9:28
  • $\begingroup$ @kglr - as far as I can tell, the solutions suggested in your post only counts the number of occurrences of a certain point. $\endgroup$
    – Stefan
    Dec 20, 2016 at 15:26

1 Answer 1

3
$\begingroup$

When the points overlap or are very close, then the markers will necessarily overlap. To ensure that you can see at least a portion of all markers, then make the earlier marker sets larger than the later marker sets so that a portion of the earlier sets are still visible when the later sets are shown. It also helps to choose colors that have more contrast than Red/Blue.

pData1 = Table[{i, i}, {i, Range[1, 50, 2]}];
pData2 = pData1;

ListPlot[{pData1, pData2},
 PlotStyle -> {
   {AbsolutePointSize[8], Red},
   {AbsolutePointSize[4], Green}},
 PlotLegends -> {"pData1", "pData2"}]

enter image description here

pData1 = Table[{i, i}, {i, Range[1, 50, 2]}]; pData2 = pData1;

EDIT: With version 11, you can also use Callout

ListPlot[{
  n = 1; Callout[#, n++, Above,
     CalloutStyle -> Red] & /@ pData1,
  n = 1; Callout[#, n++, Below,
     CalloutStyle -> Blue] & /@ pData2},
 PlotStyle -> {
   {AbsolutePointSize[8], Red},
   {AbsolutePointSize[4], Blue}},
 PlotLegends -> {"pData1", "pData2"}]

enter image description here

$\endgroup$
6
  • $\begingroup$ The current color scheme is cruel to Daltonists, however. $\endgroup$ Dec 18, 2016 at 16:10
  • $\begingroup$ @J.M. - Apologies to Daltonists. Color to taste. $\endgroup$
    – Bob Hanlon
    Dec 18, 2016 at 16:38
  • $\begingroup$ unfortunately, this does not answer my question, as I mentioned, my markers will also be lists (of numbers or strings) therefore just increasing the size does not help me... $\endgroup$
    – Stefan
    Dec 18, 2016 at 18:02
  • $\begingroup$ I wasn't aware of the function CallOut, which is a nice solution if there are not that many points. However since in my case there will be a lot of points it will get quite messy. But +1 for making me aware of CallOut. $\endgroup$
    – Stefan
    Dec 20, 2016 at 14:37
  • $\begingroup$ @Stefan - assuming that the overlaps are relatively infrequent, then apply the callouts only for the overlaps rather than all of the points. $\endgroup$
    – Bob Hanlon
    Dec 20, 2016 at 14:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.