0
$\begingroup$

Suppose I have two functions (the actual functions are different than these) defined as

f[i_,k_]:=i^(0.01*k), g[k_]:=2/k

I want to get many Listplots for f vs g. Therefore, I proceed as in the following

plot[j_, k_]:=ListPlot[Thread[{f[j, k], g[k]}], PlotTheme -> "Detailed",FrameLabel -> {"f", "g"}, Joined -> False, FrameTicksStyle -> Directive[Black, 10], PlotMarkers -> "OpenMarkers", Axes -> True, PlotRange -> All, LabelStyle -> Directive[Bold, 10], PlotLegends -> Placed[{k}, {0.15, 0.87}], ImageSize -> Medium]

Now to get a number of Listplots in one frame, I do Show[plot[1,3],plot[1,4],plot[1,5]] etc. The code runs fine, but the issue is with the colors of the plots. I am getting the same color for all plots where one can not distinguish among the correct functions. I tried this option PlotStyle -> {Directive[Green, PointSize[0.1]], Directive[Red, PointSize[0.05]], Directive[Blue, PointSize[0.01]], Directive[Yellow, PointSize[0.07]] too but no success. Is there an easy way so that I get the for each plot a different color while showing them in one frame?

$\endgroup$

1 Answer 1

1
$\begingroup$

There are multiple ways to archive this but one (using Mathematicas automatic coloring and marker styles) is to use just a single ListPlot command to plot all the points:

plot[jkList_List]:=ListPlot[
   {{f[#[[1]],#[[2]]],g[#[[2]]]}}&/@jkList,
   PlotTheme->"Detailed",
   FrameLabel->"f","g"},
   Joined->False,
   FrameTicksStyle->Directive[Black,10],
   PlotMarkers->"OpenMarkers",
   Axes->True,
   PlotRange->All,
   LabelStyle->Directive[Bold,10],
   PlotLegends->Placed[Row[{#[[1]],",",#[[2]]}]&/@jkList,Right,Top}],
   ImageSize->Medium
]

Which results for plot[{{1, 2}, {1, 3}, {2, 4}, {5, 6}}] in

Plot

$\endgroup$
1
  • $\begingroup$ Thanks, @N0va that makes sense. $\endgroup$ Commented May 8, 2022 at 22:37

Your Answer

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

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