如何使用 Matplotlib 在繪圖外部的資料座標中編寫註釋?
我們可以使用 annotate() 方法將註釋放在繪圖外部。
步驟
設定圖形大小,並調整子圖之間的間距和周圍的間距。
使用 numpy 建立 x 和 y 資料點。
使用 subplots() 方法建立圖形和一組子圖。
使用 scatter() 方法使用星形標記和銅色對映繪製 x 和 y 資料點。
若要將註釋放在繪圖外部,請相應地使用 xy 座標元組。
若要顯示圖形,請使用 show() 方法。
示例
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.random.rand(100)
y = np.random.rand(100)
fig, ax = plt.subplots()
ax.scatter(x, y, c=y, marker="*", cmap="copper")
ax.annotate('Scatter points(outside the drawing)', xy=(0.30, 1.05), xycoords=ax.get_xaxis_transform())
plt.show()輸出

廣告
資料結構
網路拓撲
關係型資料庫管理系統
作業系統
Java
iOS
超文字標記語言
層疊樣式表
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP