python画椭圆形_python绘制圆和椭圆

源自:https://blog.csdn.net/petermsh/article/details/78458585

1. 调用包函数绘制圆形Circle和椭圆Ellipse

from matplotlib.patches importEllipse, Circleimportmatplotlib.pyplot as plt

fig=plt.figure()

ax= fig.add_subplot(111)

ell1= Ellipse(xy = (0.0, 0.0), width = 4, height = 8, angle = 30.0, facecolor= 'yellow', alpha=0.3)

cir1= Circle(xy = (0.0, 0.0), radius=2, alpha=0.5)

ax.add_patch(ell1)

ax.add_patch(cir1)

x, y=0, 0

ax.plot(x, y,'ro')

plt.axis('scaled')

plt.axis('equal') #changes limits of x or y axis so that equal increments of x and y have the same length

plt.show()

1438899-20181106142935026-1420372677.png

importnumpy as npimportmatplotlib.pyplot as plt

x= y = np.arange(-4, 4, 0.1)

x, y=np.meshgrid(x,y)

plt.contour(x, y, x**2 + y**2, [9]) #x**2 + y**2 = 9 的圆形

plt.axis('scaled')

plt.show()

1438899-20181106143315516-381664068.png

2.用圆的参数方程画圆

from math importpifrom numpy importcos, sinfrom matplotlib importpyplot as pltif __name__ == '__main__':'''plot data margin'''angles_circle= [i * pi / 180 for i in range(0, 360)] #i先转换成double

x=cos(angles_circle)

y=sin(angles_circle)

plt.plot(x, y,'r')

plt.axis('equal')

plt.axis('scaled')

plt.show()

1438899-20181106143743498-1653332846.png

以下源自:https://blog.csdn.net/qq_35882901/article/details/79492640

3.参数方程的另一种写法:

importnumpy as npfrom matplotlib importpyplot as plt

r=2.0a,b=0.0,0.0

#方法一:参数方程

theta = np.arange(0, 2*np.pi, 0.01)

x= a + r *np.cos(theta)

y= b + r *np.sin(theta)

fig=plt.figure()

axes= fig.add_subplot(111)

axes.plot(x, y)

axes.axis('equal')

plt.show()

1438899-20181106144731530-1963679475.png

4.标准方程:

importnumpy as npfrom matplotlib importpyplot as plt

r=2.0a,b=0.0,0.0

#方法二:标准方程

x = np.arange(a-r, a+r, 0.01)

y= b + np.sqrt(r**2 - (x - a)**2)

fig=plt.figure()

axes= fig.add_subplot(111)

axes.plot(x, y)#上半部

axes.plot(x, -y) #下半部

axes.axis('equal')

plt.show()

1438899-20181106144842592-727059399.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值