How to plot 2 variables on a plane

妖精的绣舞 提交于 2020-01-05 04:14:07

问题


Let's say I have an equation:

x**2 + y**2 - 4 = 0

How can I see the circle using sympy, matplotplib or another python solution?

I know in sympy I can

from sympy import Plot
from sympy import Symbol
x = Symbol('x')
y = Symbol('y')
Plot(x**2 + y**2 - 4)

But then I get z = x**2 + y**2 - 4, a 3D graph instead of the planar intersection. I understand there may be a need to solve the equation.


回答1:


Yes KillianDS, I now understand this is a duplicate of Is it possible to plot implicit equations using Matplotlib?

Though I still don't know how to do it in sympy. The answer for matplotlib would be:

import matplotlib.pyplot
from numpy import arange
from numpy import meshgrid

delta = 0.025
xrange = arange(-3.0, 3.0, delta)
yrange = arange(-2.0, 2.0, delta)
X, Y = meshgrid(xrange,yrange)
F = X**2 + Y**2 -4
G = 0
matplotlib.pyplot.contour(X,Y,(F-G),[0])
matplotlib.pyplot.show()

I'm still having trouble, but I'll post it in a different question.



来源:https://stackoverflow.com/questions/6870472/how-to-plot-2-variables-on-a-plane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!