how to change line color in a sympy plot within jupyter

6.9k Views Asked by At

I am trying to plot $\exp(x)\sin(2x)$ against its derivative. This is my code so far:

from sympy import symbols
from sympy.plotting import plot
x = symbols('x')

p3 = exp(x) * sin(2*x)
p4 = diff(p3, x)

plot(p3, p4, (x, 0, 10))

Which produces the plot:

<span class=$exp(x) * sin(2*x)$" />

How do I change the color of one of the lines? I understand .line_color = '[color]' should be in my code. I am doing this in the sagemath cloud

1

There are 1 best solutions below

1
On BEST ANSWER

I solved this problem with a bit of trial and error.

from sympy import symbols
from sympy.plotting import plot
x = symbols('x')

#Defined the function to be differentiated
f = exp(x) * sin(2*x)
#plot1 = f
p1 = f
#plot2 = f'
p2 = diff(f, x)
#P is the plot of f and f'
p = plot(p1, p2, (x, 0, 10), show=false)
#change the color of p2
p[1].line_color = 'r'

p.show()

produces: enter image description here