3
$\begingroup$

I am trying to show a number of plots, which are indexed, and which all have the same marker type except when the error is under a certain threshold. Any plot on its own looks as expected, but when I put multiple plots under Show, the order in which the plots is listed affects the appearance, with markers seemingly being replaced by points. How can I keep them as markers?

Do[datatest[j] = Table[{k, j*k, 0.15*k}, {k, 10}], {j, 2}];(*Makes 2 tables with 10 points each*)

Do[dataFormat[j] = 
   Table[{{{datatest[j][[i, 1]], datatest[j][[i, 2]]}, 
   ErrorBar[datatest[j][[i, 3]]]}}, {i, 1, 
   Length[datatest[j]]}], {j,2}];(*puts in format for ErrorListPlot*)

colortable = {{1, Blue}, {2, Red}};(*one data set will be blue, the other red*)
markersize1 = 15; 
markersize2 = 30;
(*anything with an error bigger than 0.5 will get a bigger marker size (filtered below)*)

Do[datatestPlot[j] = 
   ErrorListPlot[dataFormat[j](*,PlotStyle\[Rule]{colortable[[j,2]]}*),
   Epilog -> {(Text[Style[Graphics`PlotMarkers[][[1, 1]], markersize2, 
   colortable[[j, 2]]], #] & /@ (Select[
   datatest[j], #[[3]] > 0.5 &][[All, {1, 
   2}]])), (Text[Style[Graphics`PlotMarkers[][[1, 1]], markersize1, 
   colortable[[j, 2]]], #] & /@ (Select[
   datatest[j], #[[3]] <= 0.5 &][[All, {1, 
   2}]])) }], {j, 2}];

Show[datatestPlot[1], datatestPlot[2]]
Show[datatestPlot[2], datatestPlot[1]]

Show12

Show21

$\endgroup$
2
  • $\begingroup$ I don't recommend you write your code with Do. This is a much more efficient form, and easier to read: datatest = Table[{k, j*k, 0.15*k}, {k, 10}, {j, 2}]; Having easy to read code will make people more eager to help. $\endgroup$
    – Feyre
    Dec 26 '16 at 17:48
  • $\begingroup$ Some duplicates: (128), (44541), (72308), (82471), (110984) $\endgroup$
    – Michael E2
    Dec 28 '16 at 0:19
3
$\begingroup$

you can only have one Epilog in a Show. Show takes the Epilog from the first plot and ignores the rest. One way to handle this is to store all the epilog graphics and join them in the show:

Do[
  datatestPlot[j] = 
   ErrorListPlot[dataFormat[j](*,PlotStyle\[Rule]{colortable[[j,2]]}*)];
  ep[j] = {(Text[
        Style[Graphics`PlotMarkers[][[1, 1]], markersize2, 
         colortable[[j, 2]]], #] & /@ (Select[
         datatest[j], #[[3]] > 0.5 &][[All, {1, 2}]])), (Text[
        Style[Graphics`PlotMarkers[][[1, 1]], markersize1, 
         colortable[[j, 2]]], #] & /@ (Select[
         datatest[j], #[[3]] <= 0.5 &][[All, {1, 2}]]))}, {j, 2}];

Show[datatestPlot[1], datatestPlot[2], Epilog -> Join[ep[1], ep[2]]]

enter image description here

If you wanted each plot to have its own epilog you can join them in Show something like this (using your original code):

Show[#, Epilog -> ((Epilog /. AbsoluteOptions[#] ) & /@ #)] &@
 Table[datatestPlot[i], {i, 2}]

same plot

$\endgroup$
0
$\begingroup$

You can also do:

ErrorListPlot[Join @@ dataFormat /@ {1, 2}, 
 Epilog -> 
  Table[{(Text[
        Style[Graphics`PlotMarkers[][[1, 1]], markersize2, 
         colortable[[j, 2]]], #] & /@ (Select[
         datatest[j], #[[3]] > 0.5 &][[All, {1, 2}]])), (Text[
        Style[Graphics`PlotMarkers[][[1, 1]], markersize1, 
         colortable[[j, 2]]], #] & /@ (Select[
         datatest[j], #[[3]] <= 0.5 &][[All, {1, 2}]]))}, {j, 2}]]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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