Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plot two implicit functions with plot_implicit

Tags:

plot

sympy

Is it possible to plot two implicit functions on the same canvas with sympys plot_implicit function?

E.g. have both lines from the two plots in the example be shown on one canvas.

from sympy import *
x,y = symbols('x y')
init_printing()
plot_implicit(Eq(abs(x)+abs(y), 1), (x,-1,1), (y, -1,1))
plot_implicit(Eq(x**2 + y**2, 1), (x,-1,1), (y, -1,1))
like image 330
snaut Avatar asked Oct 28 '25 04:10

snaut


1 Answers

To combine two plots with sympy's plotting, the plots are first created with show=False, then appended and ultimately shown:

from sympy import symbols, plot_implicit, Eq, Abs

x, y = symbols('x y')
plot1 = plot_implicit(Eq(Abs(x) + Abs(y), 1), (x, -1, 1), (y, -1, 1),
                      line_color='steelblue', show=False)
plot2 = plot_implicit(Eq(x ** 2 + y ** 2, 1), (x, -1, 1), (y, -1, 1),
                      line_color='crimson', show=False)
plot1.append(plot2[0])
plot1.show()

resulting plot

like image 143
JohanC Avatar answered Oct 30 '25 05:10

JohanC