如何用python画圆?使用什么函数来画?

944次阅读
没有评论

在Python中,可以利用matplotlb库的“Circle()”来画圆,将其封装到plot_circle函数中调用即可画圆。方法是:1、利用figure确定画布大小;2、利用“Circle()”配置圆的相关信息。

如何用python画圆?使用什么函数来画?

代码如下:

from matplotlib.patches import Ellipse, Circle
import matplotlib.pyplot as plt

def plot_cicle():
    fig = plt.figure()
    ax = fig.add_subplot(111)

    cir1 = Circle(xy = (0.0, 0.0), radius=2, alpha=0.5)
    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()
 
plot_cicle()

推荐课程:Matplotlib图形绘制(Corey Schafer)

神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:Python基础教程2022-12-07发表,共计596字。
新手QQ群:570568346,欢迎进群讨论 Python51学习