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.
Asked
Active
Viewed 117 times
2
1 Answers
3
Some tips to get you started with a real simple example.
plot = Plot[{Sin[x], Cos[x]}, {x, 0, 2 π}]

You can extract the colors via
Cases[plot, color_?ColorQ, Infinity]

FullForm[%]

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

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

which would be helpful in locating the parts that you might want to edit.
Jack LaVigne
- 14,462
- 2
- 25
- 37
-
Nothingwas introduced in 10.2 according toWolframLanguageData["Nothing", "VersionIntroduced"]. You could useColorQto get all colors. Your version missesGrayLevel[0.5, 0.4]. – Karsten7 Aug 20 '16 at 00:22 -
@Karsten7 Thank you for the
ColorQtip, always learning something on StackExchange. Modified the answer and also corrected version whereNothingbegan. – Jack LaVigne Aug 20 '16 at 13:59 -
@JackLaVigne You can consider my
shortInputFormfunction which is very handy for investigation of inner structure of graphics. I have it in myinit.m. – Alexey Popkov Aug 21 '16 at 07:49 -
@AlexeyPopkov Thank you for sharing this with me. It works great!! – Jack LaVigne Aug 21 '16 at 14:00
Graphicsobject and figure out what to change in it. Then you have to do the change manually. – Szabolcs Aug 19 '16 at 17:44Plot[{Sin[x], Cos[x]}, {x, 0, 10}] /. {ColorData[97][1] -> Directive[Red, Dashed]}– Karsten7 Aug 19 '16 at 17:53