组合matplotlib小部件时出现的图形问题:span选择器、光标、填充\u之间:

组合matplotlib小部件时出现的图形问题:span选择器、光标、填充\u之间:,matplotlib,widget,cursor,html,Matplotlib,Widget,Cursor,Html,在小部件之间使用span选择器、光标和fill_时,我发现了一些小的图形问题,我想与大家分享一下 所有这些都可以在我从matplolib示例中获取的代码中体验到 """ The SpanSelector is a mouse widget to select a xmin/xmax range and plot the detail view of the selected region in the lower axes """ import numpy as np import matplo

在小部件之间使用span选择器、光标和fill_时,我发现了一些小的图形问题,我想与大家分享一下

所有这些都可以在我从matplolib示例中获取的代码中体验到

"""
The SpanSelector is a mouse widget to select a xmin/xmax range and plot the
detail view of the selected region in the lower axes
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import SpanSelector
import matplotlib.widgets as widgets

Fig = plt.figure(figsize=(8,6))
Fig.set_facecolor('w')
Fig.set
Ax = Fig.add_subplot(211)


x = np.arange(0.0, 5.0, 0.01)
y = np.sin(2*np.pi*x) + 0.5*np.random.randn(len(x))

Ax.plot(x, y, '-')
Ax.set_ylim(-2,2)
Ax.set_title('Press left mouse button and drag to test')

RegionIndices = []

ax2 = Fig.add_subplot(212)
line2, = ax2.plot(x, y, '-')


def onselect(xmin, xmax):
    if len(RegionIndices) == 2:
        Ax.fill_between(x[:], 0.0, y[:],facecolor='White',alpha=1)
        del RegionIndices[:]


    indmin, indmax = np.searchsorted(x, (xmin, xmax))
    indmax = min(len(x)-1, indmax)

    Ax.fill_between(x[indmin:indmax], 0.0, y[indmin:indmax],facecolor='Blue',alpha=0.30)

    thisx = x[indmin:indmax]
    thisy = y[indmin:indmax]
    line2.set_data(thisx, thisy)
    ax2.set_xlim(thisx[0], thisx[-1])
    ax2.set_ylim(thisy.min(), thisy.max())
    Fig.canvas.draw()

    RegionIndices.append(xmin)
    RegionIndices.append(xmax)

# set useblit True on gtkagg for enhanced performance
span = SpanSelector(Ax, onselect, 'horizontal', useblit = True,rectprops=dict(alpha=0.5, facecolor='purple') )
cursor = widgets.Cursor(Ax, color="red", linewidth = 1, useblit = True)

plt.show()
我想知道是否有办法避免这两个小问题:

1您可以看到,当您选择一个区域时,span选择器框会出现紫色小故障。在这段代码中,效果几乎不明显,但在有许多行的绘图中,效果相当令人讨厌。我已经尝试了所有trueblit组合,以避免产生效果

2在该代码中,当您选择一个区域时,直线和水平轴之间的上部绘图区域用蓝色填充。选择新区域时,旧区域将填充为白色以清除,新区域将再次填充为蓝色。然而,当我这样做的时候,绘制的线,以及水平轴,变得更厚。。。有没有办法在不发生这种情况的情况下清除由fill_-between生成的区域。。。还是有必要重新打印图表?起初,我反对这样做,因为我有一个结构良好的代码,再次将所有数据导入spanselector方法似乎有点混乱。。。在python中,删除绘图的选定区域的正确方法是什么

任何建议都欢迎