【问题标题】:Subplot with text only仅包含文本的子图
【发布时间】:2020-06-08 10:56:27
【问题描述】:

我有一个由许多子图条组成的图。我希望我的一个子图只是一种文本框,它将列出我在所有图中使用的所有参数。

如何在 python 中做到这一点?

有没有像plt.textbox("my text") 这样的东西,我可以让它看起来完全像图中的任何情节。

我不希望图形中的文本,我想要一个仅由文本组成的子图。

【问题讨论】:

    标签: python matplotlib plot subplot


    【解决方案1】:

    您可以使用set_axis_off() 方法使子图为空,然后使用text() 方法添加文本,其前两个参数指定文本框左下角的坐标,默认为0-1子图的坐标系。

    import matplotlib.pyplot as plt
    
    fig, ax = plt.subplots(2, 2)
    x = [1, 2]
    y = [1, 2]
    
    ax[0, 0].plot(x, y)
    ax[0, 1].plot(x, y)
    ax[1, 0].plot(x, y)
    
    ax[1, 1].set_axis_off()
    ax[1, 1].text(0.5, 0.5, 'my text');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-26
      • 1970-01-01
      • 2013-04-10
      • 2019-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多