【问题标题】:displaying hypertools plots in subplots在子图中显示超工具图
【发布时间】:2018-01-27 06:05:19
【问题描述】:

我想将一些 oh hypertools 的图安排到 matplotlib 子图的网格中。通常hypertools.plot 会立即呈现,但可以通过传递show=False. It also returns ahypertools.DataGeometry` 对象来停止。如何让它呈现为网格中的子图而不是独立图形?

【问题讨论】:

    标签: matplotlib subplot hypertools


    【解决方案1】:

    为 matplotlib 编写一些绘图包装器的常用方法是允许将轴提供给包装器,例如

    def plot(data, ax=None):
        if not ax:
            fig, ax = plt.subplots()
        else:
            fig = ax.figure
        # plot to ax ...
    

    hypertools 不遵循此标准方法,这会使将其中一个图放入现有图形变得非常麻烦。 将其作为一个问题放在他们的 GitHub 跟踪器上可能是值得的。


    您可以选择将轴从超级工具创建的图形移动到您自己的图形。

    这可以使用this answer 中的方法来完成。 (我无法测试以下内容,因为我没有可用的超级工具)

    import matplotlib.pyplot as plt
    import hypertools
    
    datageom = hypertools.plot(..., show=False)
    
    ax = datageom.ax
    ax.remove()
    
    fig2 = plt.figure()
    ax.figure=fig2
    fig2.axes.append(ax)
    fig2.add_axes(ax)
    
    dummy = fig2.add_subplot(231)
    ax.set_position(dummy.get_position())
    dummy.remove()
    # possibly:
    # plt.close(datageom.fig)
    
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-08
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多