[Matplotlib-users] Efficiency in connecting two subplot.
Éric Depagne
eric at depagne.org
Mon Feb 19 09:37:38 EST 2018
Le vendredi 16 février 2018, 21:41:07 SAST vincent.adrien at gmail.com a écrit :
Hi Adrien,
Thanks for the answer, I'll have a look and will try to get things working a
bit more efficiently.
Cheers,
Éric.
> Hi Éric,
>
> I am not very used to play with interactive events, but I guess some
> blitting could help you with performance:
> -
> https://stackoverflow.com/questions/29277080/efficient-matplotlib-redrawing
> -
> https://matplotlib.org/users/event_handling.html#draggable-rectangle-exercis
> e (see the extra credit example)
>
> See the attached script that is inspired from your code and seems to
> less stress my CPU.
>
> Hopefully this helps.
>
> Best,
> Adrien
>
> On 02/16/2018 01:36 AM, Éric Depagne wrote:
> > Hi all,
> >
> > I have a gridspec plot and one of the subplot is a zoom on the part over
> > which the mouse hovers on another subplot.
> >
> > It works, but I think the way I implemented it is not very efficient,
> > since each time I use it, I see one CPU go to 100%.
> > Here is the code that does implement the zoom. Any idea on how to make it
> > (more) efficient or changes that I should implement welcome.
> >
> > Thanks.
> >
> > def plot(self):
> > gs = gridspec.GridSpec(6, 2)
> > ax1 = plt.subplot(gs[1:, 0])
> > plt1 = ax1.imshow(self.data, vmin=self.dataminzs,
> > vmax=self.datamaxzs)
> > ax1.set_label('AX1')
> > self.ax2 = plt.subplot(gs[0:3, 1])
> > zoomeddata = self.data[np.int(self.data.shape[0]/
> >
> > 2)-50:np.int(self.data.shape[0]/2)+50, np.int(self.data.shape[1]/
> > 2)-50:np.int(self.data.shape[1]/2)+50]
> >
> > self.plt2 = self.ax2.imshow(zoomeddata, vmin=self.dataminzs,
> >
> > vmax=self.datamaxzs)
> >
> > ax1.figure.canvas.mpl_connect('motion_notify_event',
> > self._on_move)
> >
> > def _on_move(self, event):
> > zoom1 = 100
> >
> > if event.inaxes:
> > ax = event.inaxes # the axes instance
> >
> > if 'AX1' in ax.get_label():
> > # Mouse is in subplot 1.
> > xinf2 = np.int(event.xdata - zoom1)
> > xsup2 = np.int(event.xdata + zoom1)
> > yinf2 = np.int(event.ydata - zoom1)
> > ysup2 = np.int(event.ydata + zoom1)
> > ax2data = self.data[yinf2:ysup2, xinf2:xsup2]
> > self.plt2.set_data(ax2data)
> > self.ax2.figure.canvas.draw()
--
Un clavier azerty en vaut deux
----------------------------------------------------------
Éric Depagne
More information about the Matplotlib-users
mailing list