sympy – changing graph color of plot()

plot() handles color names for RGB color codes. SymPy document doesn’t explain it clearly or sample codes don’t exit.

p = plot(sin(x), show=False)
# (red, green, blue)
# define lambda function for varying colors by coordinates or values.
# p[0].line_color = (0.9,0.0,0.0)
p[0].line_color = 'firebrick'  # royalblue
p.show()

sine

# 31. 
x = symbols('x')
y = (sqrt(x)/(1 + x))**2
dy = diff(y, x)
yl = 10
plot(y, (x, -5, 5), ylim=(-yl, 1), title=str(y), line_color='firebrick')

c2-pe-31

Here is another example.

#  65
# f(x) = x**2,  [-1, 0) and -x**2, [0, 1]
x = symbols('x')
f1 = x**2 
f2 = -x**2

# plot() allows only one line_color argument
p = plot((f1, (x, -1, 0)), (f2, (x, 0, 1)), title="x**2 for [-1, 0), -x**2 for [0, 1]", show=False) 
p[0].line_color = 'blue'
p[1].line_color = 'green'
p.show()

c2-pe-65

About janpenguin

Email: janpenguin [at] riseup [dot] net Every content on the blog is made by Free and Open Source Software in GNU/Linux.
This entry was posted in Python and tagged , , , , , , . Bookmark the permalink.

One Response to sympy – changing graph color of plot()

  1. David says:

    Thanks a million! I was not understanding what they ment by indexing the plots. Your examples made it all clear.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s