Ask Your Question
1

How to change color AFTER calling "plot"?

asked 2019-02-11 20:51:38 +0100

dsejas gravatar image

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 flag offensive close merge delete

Comments

probably not possible

FrédéricC gravatar imageFrédéricC ( 2019-02-18 19:56:50 +0100 )edit

1 Answer

Sort by » oldest newest most voted
4

answered 2019-03-03 00:26:20 +0100

dsejas gravatar image

updated 2019-03-12 02:02:00 +0100

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[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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-02-11 20:51:38 +0100

Seen: 727 times

Last updated: Mar 12 '19