[英]Add text to a figure in matplotlib
我想在 3D 線框 plot 中添加一些文本。 我從 matplotlib 庫中此示例的代碼開始。 從Axes
文檔中,我找到了一個text()
。 如果我沒看錯,則需要 4 個位置 arguments (包括self
)。 我將示例修改如下:
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Grab some test data.
X, Y, Z = axes3d.get_test_data(0.05)
# Plot a basic wireframe.
ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10)
ax.text(0, 0, "I'm here")
plt.show()
當我運行這段代碼時,我得到
類型錯誤:文本()缺少 1 個必需的位置參數:'s'
我該如何解決? 我在這里做錯了什么?
help(ax.text)
提供了正確的文檔:
Help on method text in module mpl_toolkits.mplot3d.axes3d:
text(x, y, z, s, zdir=None, **kwargs) method of matplotlib.axes._subplots.Axes3DSubplot instance
...
所以你需要 3 個位置坐標,沒有self
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.