【问题标题】:Matplotlib multicursor.py for loop-generated subplotsMatplotlib multicursor.py 用于循环生成的子图
【发布时间】:2016-05-19 13:18:29
【问题描述】:

我正在尝试在 matplotlib 中使用多游标,如示例 here 中所示。 问题是我的子图是循环生成的,这意味着我没有 ax1、ax2、... 但是一个代码胜过千言万语:

t = 0
fig = plt.figure()
while t < 16 :
     ax = fig.add_subplot(4,4,t+1)
     p1 = plot(...)
     p2 = plot(...)
     p3 = plot(...)
     p4 = plot(...)
     t = t+1
show()

有人有想法吗?谢谢!

【问题讨论】:

    标签: python python-2.7 matplotlib matplotlib-widget


    【解决方案1】:

    为什么不制作一个轴列表并将其传递给多光标?

    t = 0
    fig = plt.figure()
    axes_list = []
    while t < 16 :
         ax = fig.add_subplot(4,4,t+1)
         axes_list.append(ax)
         p1 = plot(...)
         p2 = plot(...)
         p3 = plot(...)
         p4 = plot(...)
         t = t+1
    multi = MultiCursor(fig.canvas, axes_list, color='r', lw=1)
    show()
    

    【讨论】:

    • 好吧,我总是使用数组,所以我忘记了列表可以解决问题。非常感谢,它有效!
    猜你喜欢
    • 1970-01-01
    • 2017-12-21
    • 2021-12-29
    • 1970-01-01
    • 2021-12-18
    • 2013-11-26
    • 2015-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多