给你一个python使用matplotlib画图的模板,对于画圆这个问题来说利用参数方程会更简单。
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画三维球体吧,同理也是利用用球面的参数方程
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())
运行结果截图: