python matplotlib绘制 Python使用matplotlib绘制圆形代码实例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

python matplotlib绘制 Python使用matplotlib绘制圆形代码实例

百里希文   2021-04-22 我要评论

1、定义一个画圆的函数

import numpy as np
import matplotlib.pyplot as plt
 
def plot_circle(center=(3, 3),r=2):
  x = np.linspace(center[0] - r, center[0] + r, 5000)
  y1 = np.sqrt(r**2 - (x-center[0])**2) + center[1]
  y2 = -np.sqrt(r**2 - (x-center[0])**2) + center[1]
     
  plt.plot(x, y1, c='k')
  plt.plot(x, y2, c='k')
  plt.show()

2、调用 plot_circle()

plot_circle((5, 5), r=3)

调整坐标轴,重新绘图

import matplotlib.pyplot as plt
plt.xlim(0, 15)
plt.ylim(0, 15)
plot_circle((5, 5),r=3)

只要将步骤 1 函数定义的复杂一些,还可以实现很多玩法。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们