python matplotlib畫形狀(矩形、圓等)

B站視頻:https://www.bilibili.com/video/av6989413/?p=6html

轉自:https://www.cnblogs.com/linblogs/p/9672769.htmlapi

import numpy as np import matplotlib.pyplot as plt import matplotlib.patches as mpathes fig,ax = plt.subplots() xy1 = np.array([0.2,0.2]) xy2 = np.array([0.2,0.8]) xy3 = np.array([0.8,0.2]) xy4 = np.array([0.8,0.8]) #圓形
circle = mpathes.Circle(xy1,0.05) ax.add_patch(circle) #長方形
rect = mpathes.Rectangle(xy2,0.2,0.1,color='r') ax.add_patch(rect) #多邊形
polygon = mpathes.RegularPolygon(xy3,5,0.1,color='g') ax.add_patch(polygon) #橢圓形
ellipse = mpathes.Ellipse(xy4,0.4,0.2,color='y') ax.add_patch(ellipse) plt.axis('equal') plt.grid() plt.show()
相關文章
相關標籤/搜索