This question already has an answer here:

I have a 1D graph plotted using a certain set of colors and plotstyle. Is it possible for me to change the color(s) and the plotstyle without having to rerun the code.


marked as duplicate by Jason B., Karsten 7., bbgodfrey, m_goldberg, xyz Aug 20 '16 at 1:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    $\begingroup$ No, not in any reasonably simple way. You'd have to decompose the Graphics object and figure out what to change in it. Then you have to do the change manually. $\endgroup$ – Szabolcs Aug 19 '16 at 17:44
  • 2
    $\begingroup$ Can you give an example? It can be quite easy for simple ones: Plot[{Sin[x], Cos[x]}, {x, 0, 10}] /. {ColorData[97][1] -> Directive[Red, Dashed]} $\endgroup$ – Karsten 7. Aug 19 '16 at 17:53
  • 1
    $\begingroup$ Not sure what a 1D graph is, and not sure which code you don't want to rerun. If this is a list plot, you should always generate your data separately from the plot. Do you really have such an expensive plot to generate, given the data? $\endgroup$ – Alan Aug 19 '16 at 18:40

Some tips to get you started with a real simple example.

plot = Plot[{Sin[x], Cos[x]}, {x, 0, 2 π}]

Mathematica graphics

You can extract the colors via

Cases[plot, color_?ColorQ, Infinity]

Mathematica graphics


Mathematica graphics

Replace the colors using Replace

plot /. {RGBColor[0.368417`, 0.506779`, 0.709798`] -> Red, 
         RGBColor[0.880722`, 0.611041`, 0.142051`] -> Black}

Mathematica graphics

If you want to replace more complicated items you will need to dig down into the graphical output of plot. Typically there is a great deal of numerical data that swamps the screen if you look at the graphic in text form.

To reduce that and try to locate what you might want to edit try:

plot /. Graphics -> graphicHead /. {x_?NumericQ, y_?NumericQ} -> Nothing

Nothing is relatively new (started in 10.2). graphicsHead is a bogus Head that prevents the plot from displaying.

The output looks like

Mathematica graphics

which would be helpful in locating the parts that you might want to edit.

  • $\begingroup$ Nothing was introduced in 10.2 according to WolframLanguageData["Nothing", "VersionIntroduced"]. You could use ColorQ to get all colors. Your version misses GrayLevel[0.5, 0.4]. $\endgroup$ – Karsten 7. Aug 20 '16 at 0:22
  • $\begingroup$ @Karsten7 Thank you for the ColorQ tip, always learning something on StackExchange. Modified the answer and also corrected version where Nothing began. $\endgroup$ – Jack LaVigne Aug 20 '16 at 13:59
  • $\begingroup$ @JackLaVigne You can consider my shortInputForm function which is very handy for investigation of inner structure of graphics. I have it in my init.m. $\endgroup$ – Alexey Popkov Aug 21 '16 at 7:49
  • $\begingroup$ @AlexeyPopkov Thank you for sharing this with me. It works great!! $\endgroup$ – Jack LaVigne Aug 21 '16 at 14:00

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