是否可以使用 Matplotlib 绘制隐式方程? [英] Is it possible to plot implicit equations using Matplotlib?

查看:44
本文介绍了是否可以使用 Matplotlib 绘制隐式方程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Matplotlib 中绘制隐式方程(形式为 f(x, y)=g(x, y) 例如.X^y=y^x).这可能吗?

I would like to plot implicit equations (of the form f(x, y)=g(x, y) eg. X^y=y^x) in Matplotlib. Is this possible?

推荐答案

我不认为有很好的支持,但你可以尝试类似的东西

I don't believe there's very good support for this, but you could try something like

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

delta = 0.025
xrange = arange(-5.0, 20.0, delta)
yrange = arange(-5.0, 20.0, delta)
X, Y = meshgrid(xrange,yrange)

# F is one side of the equation, G is the other
F = Y**X
G = X**Y

matplotlib.pyplot.contour(X, Y, (F - G), [0])
matplotlib.pyplot.show()

请参阅 API 文档 for contour:如果第四个参数是一个序列,那么它指定要绘制的轮廓线.但情节只会与您的范围的分辨率一样好,并且某些特征可能永远不会正确,通常在自相交点处.

See the API docs for contour: if the fourth argument is a sequence then it specifies which contour lines to plot. But the plot will only be as good as the resolution of your ranges, and there are certain features it may never get right, often at self-intersection points.

这篇关于是否可以使用 Matplotlib 绘制隐式方程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆