向matplotlib中的地物添加文本

2024-09-28 20:44:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在三维线框图中添加一些文本。我从matplotlib库中this example的代码开始。从Axes文档中,我发现了一个^{}。如果我读对了,那么有4个必需的位置参数(包括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()

当我运行这个代码时

TypeError: text() missing 1 required positional argument: 's'

我该怎么解决这个问题?我做错什么了?你知道吗


Tags: 代码texttest文本importdatamatplotlibexample
2条回答

在本例中,您处理的不是^{}对象,而是^{}对象。因此,您需要为其^{}方法提供三个坐标数,而不仅仅是2。你知道吗

或者您也可以使用^{}方法,它只需要两个坐标数输入参数。你知道吗

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。你知道吗

相关问题 更多 >