画出一个圆的方程式 [英] Plot equation showing a circle
本文介绍了画出一个圆的方程式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下公式用于对二维空间中的点进行分类:
The following formula is used to classify points from a 2-dimensional space:
f(x1,x2) = np.sign(x1^2+x2^2-.6)
所有点都在空间X = [-1,1] x [-1,1]
中,并且有选择每个x的统一概率.
All points are in space X = [-1,1] x [-1,1]
with a uniform probability of picking each x.
现在我想形象化等于的圆圈:
Now I would like to visualize the circle that equals:
0 = x1^2+x2^2-.6
x1的值应在x轴上,x2的值应在y轴上.
The values of x1 should be on the x-axis and values of x2 on the y-axis.
这一定有可能,但我很难将方程式转换成图.
It must be possible but I have difficulty transforming the equation to a plot.
推荐答案
You can use a contour plot, as follows (based on the examples at http://matplotlib.org/examples/pylab_examples/contour_demo.html):
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-1.0, 1.0, 100)
y = np.linspace(-1.0, 1.0, 100)
X, Y = np.meshgrid(x,y)
F = X**2 + Y**2 - 0.6
plt.contour(X,Y,F,[0])
plt.show()
这将产生下图
最后,一些一般性声明:
Lastly, some general statements:
-
x^2
并不意味着您认为在python中所做的,您必须使用x**2
.
(对我来说) -
x1
和x2
极具误导性,尤其是当您声明x2
必须在y轴上时. - (感谢Dux),可以添加
plt.gca().set_aspect('equal')
,使轴相等,使图形实际上看起来是圆形的.
x^2
does not mean what you think it does in python, you have to usex**2
.x1
andx2
are terribly misleading (to me), especially if you state thatx2
has to be on the y-axis.- (Thanks to Dux) You can add
plt.gca().set_aspect('equal')
to make the figure actually look circular, by making the axis equal.
这篇关于画出一个圆的方程式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文