Python-Matplotlib 23 形状
Python-Matplotlib 23 形状
EG1:
import numpy as np import matplotlib.pyplot as plt import matplotlib.patches as mpatches fig, ax = plt.subplots() xy1 = np.array([0.2 , 0.2]) xy2 = np.array([0.2, 0.8]) xy3 = np.array([0.6 , 0.2]) xy4 = np.array([0.6, 0.8]) print(xy1) circle = mpatches.Circle(xy1 , 0.05) ax.add_patch(circle) rect = mpatches.Rectangle(xy2 , 0.2 , 0.1 , color='r') ax.add_patch(rect) polygon = mpatches.RegularPolygon(xy3 , 10 , 0.1, color='g') # arg1-4 : position , regular nums , radius , color ax.add_patch(polygon) ellipse = mpatches.Ellipse(xy4, 0.3 , 0.2 , color='y') # arg1-4 : position , log radius , short radius , color ax.add_patch(ellipse) #ax.axis('equal') # circle , otherwise plt.show()