如何使用Matplotlib绘制半黑半白的圆? 要绘制半黑半白的圆,可以按照以下步骤进行操作: 设置图形大小并调整子图之间和周围的填充。 创建一个图形和一组子图。 初始化 theta1 和 theta2 来从theta1到theta2和从theta2到theta1画边缘。 在当前轴上添加楔形实例。 通过更改轴界限设置等比例缩放。 设置 x 和 y 比例尺。 使用 show() 方法显示图形。 示例 import matplotlib.pyplot as plt from matplotlib.patches import Wedge plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True fig, ax = plt.subplots() theta1, theta2 = 0, 0 + 180 radius = 2 center = (0, 0) w1 = Wedge(center, radius, theta1, theta2, fc='black', edgecolor='black') w2 = Wedge(center, radius, theta2, theta1, fc='white', edgecolor='black') for wedge in [w1, w2]: ax.add_artist(wedge) ax.axis('equal') ax.set_xlim(-5, 5) ax.set_ylim(-5, 5) plt.show() PythonCopy 输出