画出一个圆的方程式 [英] Plot equation showing a circle

查看:81
本文介绍了画出一个圆的方程式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下公式用于对二维空间中的点进行分类:

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:

  1. x^2并不意味着您认为在python中所做的,您必须使用x**2.
  2. (对我来说)
  3. x1x2极具误导性,尤其是当您声明x2必须在y轴上时.
  4. (感谢Dux),可以添加plt.gca().set_aspect('equal'),使轴相等,使图形实际上看起来是圆形的.
  1. x^2 does not mean what you think it does in python, you have to use x**2.
  2. x1 and x2 are terribly misleading (to me), especially if you state that x2 has to be on the y-axis.
  3. (Thanks to Dux) You can add plt.gca().set_aspect('equal') to make the figure actually look circular, by making the axis equal.

这篇关于画出一个圆的方程式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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