ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 03 Mar 2019 00:26:20 +0100How to change color AFTER calling "plot"?https://ask.sagemath.org/question/45422/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!Mon, 11 Feb 2019 20:51:38 +0100https://ask.sagemath.org/question/45422/how-to-change-color-after-calling-plot/Comment by FrédéricC for <p>Suppose I have done</p>
<pre><code>p = plot(x^2) + plot(x^3)
</code></pre>
<p>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!</p>
https://ask.sagemath.org/question/45422/how-to-change-color-after-calling-plot/?comment=45501#post-id-45501probably not possibleMon, 18 Feb 2019 19:56:50 +0100https://ask.sagemath.org/question/45422/how-to-change-color-after-calling-plot/?comment=45501#post-id-45501Answer by dsejas for <p>Suppose I have done</p>
<pre><code>p = plot(x^2) + plot(x^3)
</code></pre>
<p>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!</p>
https://ask.sagemath.org/question/45422/how-to-change-color-after-calling-plot/?answer=45605#post-id-45605Hello, 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[0]`, 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[1] 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`.Sun, 03 Mar 2019 00:26:20 +0100https://ask.sagemath.org/question/45422/how-to-change-color-after-calling-plot/?answer=45605#post-id-45605