【问题标题】:Place text label in 3D coordinates that are not data-dependent将文本标签放置在不依赖数据的 3D 坐标中
【发布时间】:2014-09-03 08:23:04
【问题描述】:

我有一个包含 2x2 3-D 图的子图。在此图中,我想放置一个文本框,以放置一些附加信息。 为此,我找到了 ma​​tplotlib.pyplot.text 函数。 但是,此函数使用数据坐标作为输入。由于我的四个子图都具有不同的 z 值范围,因此将文本放置在单个 z 坐标上将为它们提供其他相对位置。

MWE

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

def randrange(n, vmin, vmax):
    return (vmax-vmin)*np.random.rand(n) + vmin

fig = plt.figure()
for plotnr in [1,2,3,4]:
    ax = fig.add_subplot(2, 2, plotnr, projection='3d')
    n = 10
    for c, m, zl, zh in [('r', 'o', -50, -25), ('b', '^', -30, -5)]:
        xs = randrange(n, 23, 32)
        ys = randrange(n, 0, 100)
        zs = np.divide(randrange(n, zl, zh),1000/(10**(plotnr-1)))
        ax.scatter(xs, ys, zs, c=c, marker=m)
        ax.text(27, 60,3,'matplotlib', ha='center', va='center',transform=ax.transAxes)
plt.show()

正如您从图像中看到的那样,“matplotlib”正在四处移动,或者根本不存在。我认为这是因为 z 值的变化。

是否可以将文本框放置在相对于图像的坐标处,而不是相对于数据的坐标处?

【问题讨论】:

    标签: python matplotlib plot 3d label


    【解决方案1】:

    我找到了答案here,可以使用以下方法切换到二维标签放置:

    ax.text2D(0.05, 0.95, "2D Text", transform=ax.transAxes)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      • 2018-05-25
      相关资源
      最近更新 更多