# How to change color AFTER calling "plot"?

Suppose I have done

p = plot(x^2) + plot(x^3)


and then I decide I want the image in grayscale. Is there a way to specify this without having to re-plot again? Thanks in advance for your answers!

edit retag close merge delete

Sort by » oldest newest most voted

Hello, everybody. I found a solution a few days after asking this question, but I couldn't post it until now. When we write

p = plot(x^2) + plot(x^3)


Sage creates a list of two "line groups". For example, if we write p, Sage answers something like "Line defined by 223 points". This is actually the set of points that define the curve for $x^2$. Similarly, p is the set of points for $x^3$ .

Now, we can access the options associated with each line set with

p[i].options()


where i=0 or i=1 in this case. We will receive an answer like

{'alpha': 1, 'legend_color': None, 'legend_label': None, 'rgbcolor': (0, 0, 1), 'thickness': 1}

As we can see, there is a field called "rgbcolor", which has a triplet associated. We can change that with any values we want, and use the set_options command to set the new configurations. (There are other properties that can be manually changed.)

Next, I give an example of how to change the color of both function graphs to green:

p = plot(x^2) + plot(x^3)
for plt in p:
opt = plt.options()
opt['rgbcolor'] = Color('green')
plt.set_options(opt)


I hope this helps to whoever needs to change colors (or other attributes) AFTER calling plot.

more