如何在 Matplotlib 中製作迴圈箭頭?
要在 Matplotlib 中製作迴圈箭頭,我們可以採取以下步驟 −
- 設定圖形大小並調整子圖之間的填充和周圍的填充。
- 要在 matplotlib 中製作迴圈箭頭,我們可以使用make_loop()方法。
- 使用center、radius、theta1、theta2和寬度製作一個楔形例項。
- 若要將箭頭放在迴圈頂部,請使用PathCollection。
- 將補丁集合新增到當前軸。
- 若要顯示圖形,請使用show()方法。
示例
from matplotlib import pyplot as plt, patches, collections plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True def make_loop(center, radius, theta1=-30, theta2=180): rwidth = 0.02 ring = patches.Wedge(center, radius, theta1, theta2, width=rwidth) offset = 0.02 xcent = center[0] - radius + (rwidth / 2) left = [xcent - offset, center[1]] right = [xcent + offset, center[1]] bottom = [(left[0] + right[0]) / 2., center[1] - 0.05] arrow = plt.Polygon([left, right, bottom, left]) p = collections.PatchCollection( [ring, arrow], edgecolor='orange', facecolor='red' ) ax.add_collection(p) fig, ax = plt.subplots() make_loop(center=(.5, .7), radius=.1) plt.show()
輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP