4
$\begingroup$

Sometimes I run into a situation when there are graphics objects (mostly plots) that take a while to draw. Good practice would suggest you do all your evaluation outside Plot or whatever other plotting function, but sometimes one forgets or it is the drawing process that takes so much time. So the question is whether it is possible to change things such as PlotLabel font, PlotStyle or other strictly aesthetic properties of the plot without asking Mathematica to recalculate all the points.

$\endgroup$
  • $\begingroup$ You can still ask for the FullForm/InputForm and change the Options $\endgroup$ – Öskå Dec 17 '13 at 14:49
  • $\begingroup$ Oh wow, this works very well, I haven't worked much with FullForm so I didn't think of it. $\endgroup$ – Jānis Šmits Dec 17 '13 at 14:53
  • $\begingroup$ I feel that this question is a duplicate and that it would be better to gather all answers under the following question: (17250) $\endgroup$ – Mr.Wizard Dec 17 '13 at 14:59
8
$\begingroup$

It depends. Some options, like e.g. PlotStyle are directly incorporated into the graphics itself. Others, like PlotLabel, are still there as options in the graphics and can be changed.

gr = Plot[Sin[x], {x, 0, 2 Pi}];
Show[gr, PlotLabel -> "Boing"]

Mathematica graphics

Please have a look at AbsoluteOptions[gr] to see which options are still available. I'm not entirely sure whether the above approach with Show works always but there are of course many alternatives. One of them is to build a new Graphics object. For this you take the first part, which consists of all the graphics primitives and you use the AbsoluteOptions. To replace the GridLines for instance, you could use

Graphics[First[gr], 
 Sequence @@ (AbsoluteOptions[gr] /. 
 (GridLines -> _) :> (GridLines -> {{{Pi, Dashed}, {2 Pi, Thick}}, 
  {{-1, Orange}, -.5, .5, {1, Orange}}}))]

Mathematica graphics

Be aware that usually you don't need to replace the options. If you put the same option twice, it's always first comes first serves. Therefore, this works too

Graphics[First[gr], 
 GridLines -> {{{Pi, Dashed}, {2 Pi, Thick}}, {{-1, 
     Orange}, -.5, .5, {1, Orange}}}, Sequence @@ AbsoluteOptions[gr]]

Additionally, you should be aware that you can work with a Graphics object like with any other expression in Mathematica. Therefore, even if it is not as simple as setting an option, you can still change every detail of the graphics. this needs quite some knowledge about the structure of Graphics itself, but it is not impossible. Just like Öska said, look at the InputForm

gr /. _Hue :> Red

Mathematica graphics

$\endgroup$
  • $\begingroup$ So just to be clear - options shown under AbsoluteOptions are editable? There are some things you can change in the style of the plot by what @Öskå proposed (I managed to change the color of a particular line segment and such) but it is very bothersome and I can't think of the top of my head when redrawing wouldn't e be simpler. <b>Edited:</b> you updated your answer with the things I commented here. $\endgroup$ – Jānis Šmits Dec 17 '13 at 15:00
  • $\begingroup$ @JānisŠmits I'm not sure whether every option can be set with this simple Show[..] construct I used, but you can always build a new graphics with something like Graphics[First[gr], Sequence@@AbsoluteOptions[gr]] and here, you you simply replace an option by something you like. Should I give full example in the answer? $\endgroup$ – halirutan Dec 17 '13 at 15:07
  • $\begingroup$ If it isn't too much of a hassle, this is the first time I have heard of the Sequence function, I looked it up, but I think it would be very nice to have an example of how to do this in this situation. $\endgroup$ – Jānis Šmits Dec 17 '13 at 15:11
  • $\begingroup$ I feel that this question is a duplicate and that it would be better to gather all answers under the following question: (17250) $\endgroup$ – Mr.Wizard Dec 17 '13 at 15:50
  • $\begingroup$ @Mr.Wizard How do we do that except of closing this question here? The problem is that the title "Is it possible to change the color of plot in Show?" does not reflect what has been asked here (at least not, if you don't know the answer anyway). That might be one reason why the OP hasn't found the other thread. $\endgroup$ – halirutan Dec 17 '13 at 20:57

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