2
$\begingroup$

This is a extension to this question and the answer from Jason B.

Consider a list of plots

    (Evaluate[Symbol["plt" <> IntegerString[#]]] = 
     Plot[(x - 4*# + 16)^2, {x, -20, 20}]) & /@ Range[7];
    Show[{plt1, plt2, plt3, plt4, plt5, plt6, plt7}]

enter image description here

Say, we want to change the color of the plots, which are previously defined. Here is the solution from Jason.

Show[MapIndexed[#1 /. {{a__, Line[b__]} :> {a, 
   ColorData[97, First@#2], Line[b]}} &, {plt1, plt2, plt3, plt4,plt5, plt6, plt7}], Graphics[{PointSize[0.01], Point[Table[{-16 + 4*ii, 0}, {ii, 7}]]}] ] 

enter image description here

Now, suppose we need to add some points to the plot (see Fig. above) so that every point corresponds to a plot. How do I make the colors of the points to match the colors of the corresponding plots?

$\endgroup$
  • $\begingroup$ You can put it in: {a, ColorData[97, First@#2], Line[b]}}. #2 is an index of a plot so you can use it to extract expected point from your list. $\endgroup$ – Kuba Apr 9 '18 at 11:03
2
$\begingroup$
Show[MapIndexed[#1 /. {{a__, Line[b__]} :> {a, 
       ColorData[97, First@#2], Line[b]}} &, {plt1, plt2, plt3, plt4, plt5, plt6, plt7}], 
 Graphics[{PointSize[0.02], Table[{ColorData[97, ii], Point@{-16 + 4*ii, 0}}, {ii, 7}]}]]

or

Show[MapIndexed[#1 /. {{a__, Line[b__]} :> {a, 
   ColorData[97, First@#2], Line[b], PointSize[.02], Point@{-16 + 4* First@#2 , 0} }} &, 
 {plt1, plt2, plt3, plt4, plt5, plt6, plt7}] ]

enter image description here

$\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.