I would like to plot 2 curves in the same figure with the following code:
import sympy as syp
x, y = syp.symbols('x, y')
my_function = syp.exp(-(x-2)**2)*syp.exp(-(y-3)**2) + 2*syp.exp(-(x+1)**2)*syp.exp(-(y-1)**2)
gradient_1 = syp.diff(my_function, x)
gradient_2 = syp.diff(my_function, y)
curve_1 = syp.plot_implicit(syp.Eq(gradient_1, 0))
curve_2 = syp.plot_implicit(syp.Eq(gradient_2, 0))
What I see is only the first plot, while I would like to have both the curves in the same picture, maybe also with a grid if possible. Any ideas?
Note: with matplotlib it's very easy, but I cannot find any specific example for the function syp.plot_implicit
Another, perhaps more efficient way, would be to compute both at the same time using Or
plot_implicit(Or(Eq(gradient_1, 0), Eq(gradient_2, 0)))
It might work if you do:
>>> curve_1.extend(curve_2)
>>> curve_1.show()
However mixing implicit plots might not be implemented yet.
Be aware that your curve_1
and curve_2
are not what sympy considers "single curves" i.e. Series
instance, but rather "collections of a number of curves", i.e. Plot
instances.
You can also extract the matplotlib objects from curve_1._backend.fig
and other _backend
attributes.
In conclusion, there is a nice API to do what you want, but probably the methods behind it are not finished yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With