對于一個個人專案,我想補充文本中的情節的右上角,但因為我顯示單杠,我沒有y坐標,因此,我也不能使用plt.text()或者ax.annotate()作為它們需要一個 y 坐標。
這是我所擁有的情節的圖片:

這是我想要的(左上角有文字):

uj5u.com熱心網友回復:
您可以使用text. 并且坐標“仍然存在”。請參閱以下示例:
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.subplots()
names = ["a", "b", "c"]
val = [23, 17, 5]
ax.barh(names, val)
ax.text(0.8, 0.95, "text 1", transform = ax.transAxes)
ax.text(20, 0, "text 2", transform = ax.transData)
ax.text(20, 2, "text 3", transform = ax.transData)
plt.show()
導致:

另見:https : //matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.text.html https://matplotlib.org/stable/tutorials/advanced/transforms_tutorial.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/357834.html
標籤:Python matplotlib
下一篇:如何將特定范圍之外的點設定為0
