python做圆_Python怎么画圆?

给你一个python使用matplotlib画图的模板,对于画圆这个问题来说利用参数方程会更简单。

equation?tex=%5Cbegin%7Bcases%7D+x%3DR%5Csin%5Ctheta+%5C%5C+y%3DR%5Ccos%5Ctheta%5C%5C+++%5Cend%7Bcases%7D%280%5Cleq+%5Ctheta%5Cleq+2%5Cpi%29%5C%5C

import numpy as np

import matplotlib.pyplot as plt

theta = np.linspace(0, 2 * np.pi, 200)

x = np.cos(theta)

y = np.sin(theta)

fig, ax = plt.subplots(figsize=(4, 4))

ax.plot(x, y, color="darkred", linewidth=2)

ax.xaxis.set_major_locator(plt.NullLocator()) # 删除x轴刻度,如需显示x轴刻度注释该行代码即可。

ax.yaxis.set_major_locator(plt.NullLocator()) # 删除y轴刻度,如需显示y轴刻度注释该行代码即可。

ax.axis("equal")

运行结果截图:

顺便提一下怎么使用python画三维球体吧,同理也是利用用球面的参数方程

equation?tex=%5Cbegin%7Bcases%7D+x%3DR%5Csin%5Cvarphi+%5Ccos%5Ctheta+%5C%5C+y%3DR%5Csin%5Cvarphi+%5Csin%5Ctheta%5C%5C+z%3DR%5Ccos%5Cvarphi%5Cend%7Bcases%7D%280%5Cleq+%5Ctheta%5Cleq+2%5Cpi+%2C+0%5Cleq+%5Cvarphi+%5Cleq+%5Cpi%29%5C%5C

import numpy as np

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure(figsize=(6, 5))

ax = Axes3D(fig)

u = np.linspace(0, 2 * np.pi, 100)

v = np.linspace(0, np.pi, 100)

u, v = np.meshgrid(u, v)

X = np.sin(v) * np.cos(u)

Y = np.sin(v) * np.sin(u)

Z = np.cos(v)

ax.plot_surface(X, Y, Z, cmap='rainbow')

# 去除刻度

ax.xaxis.set_major_locator(plt.NullLocator())

ax.yaxis.set_major_locator(plt.NullLocator())

ax.zaxis.set_major_locator(plt.NullLocator())

运行结果截图:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值