【问题标题】:Selectively disable mplcursors on matplotlib plots有选择地禁用 matplotlib 图上的 mplcursors
【发布时间】:2018-12-06 07:36:26
【问题描述】:

当我将鼠标悬停在绘图上的一条线上时,我目前正在使用 mplcursors 来显示一个标签,但它会在我的应用程序的另一个绘图上显示一个不需要的标签。

有没有办法在 1 个绘图上启用 mplcursors 而不是另一个?

这是我用来开启功能mplcursors.cursor(hover=True)

【问题讨论】:

    标签: python-3.x matplotlib mplcursors


    【解决方案1】:

    documentation 表示您可以使用artists_or_axes kwarg 将artistsaxes 作为mplcursors.cursor 的输入。

    因此,在您的情况下,您应该只给 mplcursors.cursor 一个您希望在其上看到光标的 Axes 实例,而不是另一个。

    例如,这样的事情应该只在ax1上显示光标:

    import matplotlib.pyplot as plt
    import mplcursors
    
    fig, (ax1, ax2) = plt.subplots(2)
    
    ax1.plot(range(5))
    ax2.plot(range(5))
    
    mplcursors.cursor(artists_or_axes=ax1, hover=True)
    
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2023-03-03
      • 2018-12-12
      • 2018-03-25
      • 1970-01-01
      • 2013-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      相关资源
      最近更新 更多