0
$\begingroup$

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:

$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
    This is probably not the right place to be asking this question as it doesn't really have to do with math.2017-02-24
  • 0
    I'm guessing, but have you tried issuing two separate plot commands and putting the command to change color in between them?2017-02-24
  • 0
    there are other questions in this community about using these tools because its intrinsically related to math.2017-02-24
  • 0
    @hardmath I have tried making a plot with a single red line but I haven't been able to do that.2017-02-24

1 Answers 1

3

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