Question

I have the following code:

import sympy as syp


x, y = syp.symbols('x, y')


Equation_1 = - 2*x + y**2 - 5
Equation_2 = x**3 + syp.sin(y) - 10


syp.plot_implicit(syp.Or(syp.Eq(Equation_1, 0), syp.Eq(Equation_2, 0)), (x, -50, 50), (y, -50, 50))

which provides this picture:

enter image description here

Do you know any hack that can be used to change the color of the second curve? I think it's not directly possible, according to Sympy's documentation.

Was it helpful?

Solution 2

This is your hack, the .extend() method of Sympy's Plot objects

import sympy as syp
x, y = syp.symbols('x, y')

Eq0 = - 2*x + y**2 - 5
Eq1 = x**3 + syp.sin(y) - 10

p0 = syp.plot_implicit(Eq0, (x, -50, 50), (y, -50, 50), show=False)
p1 = syp.plot_implicit(Eq1, (x, -50, 50), (y, -50, 50), show=False, line_color='r')
p0.extend(p1)
p0.show()

enter image description here

OTHER TIPS

It appears that passing any sort of color argument to the plot_implicit function is not currently implemented. This is true regardless of how many functions you are plotting. I suspect that it is possible to add this functionality, but it is not currently there.

On the other hand this can be done if you are only plotting lines. Here's how:

import sympy as sy
x = sy.symbols('x')
# Make two plots with different colors.
p1 = sy.plot(x**2, (x, -1, 1), show=False, line_color='b')
p2 = sy.plot(x**3, (x, -1, 1), show=False, line_color='r')
# Make the second one a part of the first one.
p1.extend(p2)
# Display the modified plot object.
p1.show()

A plot of two functions made using SymPy

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top