Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
Bug report
Bug summary
In matplotlib 2.1.0 it was possible to define a SpanSelector attached to an axes object,
then define another axes system connected to the first one with twinx or twiny.
The SpanSelector was still active and returning the values on the first axes object.
With matplotlib 2.1.1 this is no more working.
The SpanSelector works only if attached to the latest axes object defined.
The same effect happens also when using draggable annotate attached to an axes object.
After defining a twin axes, the annotations are no more draggable.
Code for reproduction
As an example, I include a slight modification of the matplotlib tutorial about the usage
of span_selector:
https://matplotlib.org/examples/widgets/span_selector.html
At the end of the code I added twin axes which neutralize the span selector.
After uncommenting the last three lines, the span selector works again.
With matplotlib 2.1.0, the code was working without uncommenting the lines.
#!/usr/bin/env python"""The SpanSelector is a mouse widget to select a xmin/xmax range and plot thedetail view of the selected region in the lower axes"""importnumpyasnpimportmatplotlib.pyplotaspltfrommatplotlib.widgetsimportSpanSelectorfig=plt.figure(figsize=(8,6))ax=fig.add_subplot(211,facecolor='#FFFFCC')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')ax2=fig.add_subplot(212,facecolor='#FFFFCC')line2,=ax2.plot(x,y,'-')defonselect(xmin,xmax):indmin,indmax=np.searchsorted(x, (xmin,xmax))indmax=min(len(x)-1,indmax)print(indmin,indmax)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()# set useblit True on gtkagg for enhanced performancespan=SpanSelector(ax,onselect,'horizontal',useblit=True,rectprops=dict(alpha=0.5,facecolor='red'))ax1=ax.twinx()ax1.get_yaxis().set_tick_params(labelright='on',right='on',direction='in')ax1.set_ylim([0,1])# Uncomment here to work with matplotlib 2.1.1 (possible bug)#span = SpanSelector(ax1, onselect, 'horizontal', useblit=True,# rectprops=dict(alpha=0.5, facecolor='red'))plt.show()
Actual outcome
The span selector does not work.
# If applicable, paste the console output here##
Expected outcome
I expected that the spanselector would work.
This was working with matplotlib 2.1.0
Matplotlib version
- Operating system: mac os-x
- Matplotlib version: 2.1.1
- Matplotlib backend (
print(matplotlib.get_backend())
): - Python version: 3.6.1
- Jupyter version (if applicable):
- Other libraries:
conda
default