Efficiency in connecting two subplot.

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Efficiency in connecting two subplot.

Éric Depagne
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                            



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency in connecting two subplot.

vincent.adrien@gmail.com
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-exercise 
(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()
>

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

playground_blit.py (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency in connecting two subplot.

Éric Depagne
Le vendredi 16 février 2018, 21:41:07 SAST [hidden email] 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


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency in connecting two subplot.

Benjamin Root
You might want to consider not having the limits change at *every* mouse motion over the axes. You can add a function state variable and maybe have it refresh every other motion or so.

```
    def _on_move(self, event):
        zoom1 = 100
        if event.inaxes:

            ax = event.inaxes  # the axes instance
            if 'AX1' in ax.get_label():
                _on_move.counter += 1
                if _on_move.counter % 2:
                    return
                # 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()
    _on_move.counter = 0
```
Another approach could be done where you capture the timestamp of when this function was last used for updating the limits, and only do a new limit update if a certain amount of time passed, such as half a second or so.

Cheers!
Ben Root


On Mon, Feb 19, 2018 at 9:37 AM, Éric Depagne <[hidden email]> wrote:
Le vendredi 16 février 2018, 21:41:07 SAST [hidden email] 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


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency in connecting two subplot.

Éric Depagne
In reply to this post by vincent.adrien@gmail.com
Le vendredi 16 février 2018, 21:41:07 SAST [hidden email] a écrit :
Hi Adrien,

Many thanks for your code, I've modified mine in order to take advantage of the
blitting, and it works beautifully.

É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


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency in connecting two subplot.

Éric Depagne
In reply to this post by Benjamin Root
Le lundi 19 février 2018, 17:04:28 SAST Benjamin Root a écrit :
Hi Ben,

Thanks for the idea.
I'll see how my code runs on a slower computer than mine, and I'll implement
it should I find my current solution too slow.

Éric.

> You might want to consider not having the limits change at *every* mouse
> motion over the axes. You can add a function state variable and maybe have
> it refresh every other motion or so.
>
> ```
>     def _on_move(self, event):
>         zoom1 = 100
>         if event.inaxes:
>
>             ax = event.inaxes  # the axes instance
>             if 'AX1' in ax.get_label():
>                 _on_move.counter += 1
>                 if _on_move.counter % 2:
>                     return
>                 # 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()
>     _on_move.counter = 0
> ```
> Another approach could be done where you capture the timestamp of when this
> function was last used for updating the limits, and only do a new limit
> update if a certain amount of time passed, such as half a second or so.
>
> Cheers!
> Ben Root
>
> On Mon, Feb 19, 2018 at 9:37 AM, Éric Depagne <[hidden email]> wrote:
> > Le vendredi 16 février 2018, 21:41:07 SAST [hidden email] 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
> >
> >
> > _______________________________________________
> > Matplotlib-users mailing list
> > [hidden email]
> > https://mail.python.org/mailman/listinfo/matplotlib-users


--
Un clavier azerty en vaut deux
----------------------------------------------------------
Éric Depagne                            



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency in connecting two subplot.

Christophe BAL (via GMAIL)
Hello. 

Can you post the final code for us ?


Christophe BAL
Enseignant Agrégé de Mathématiques
Programmeur Python Amateur

Le 20 févr. 2018 09:01, "Éric Depagne" <[hidden email]> a écrit :
Le lundi 19 février 2018, 17:04:28 SAST Benjamin Root a écrit :
Hi Ben,

Thanks for the idea.
I'll see how my code runs on a slower computer than mine, and I'll implement
it should I find my current solution too slow.

Éric.

> You might want to consider not having the limits change at *every* mouse
> motion over the axes. You can add a function state variable and maybe have
> it refresh every other motion or so.
>
> ```
>     def _on_move(self, event):
>         zoom1 = 100
>         if event.inaxes:
>
>             ax = event.inaxes  # the axes instance
>             if 'AX1' in ax.get_label():
>                 _on_move.counter += 1
>                 if _on_move.counter % 2:
>                     return
>                 # 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()
>     _on_move.counter = 0
> ```
> Another approach could be done where you capture the timestamp of when this
> function was last used for updating the limits, and only do a new limit
> update if a certain amount of time passed, such as half a second or so.
>
> Cheers!
> Ben Root
>
> On Mon, Feb 19, 2018 at 9:37 AM, Éric Depagne <[hidden email]> wrote:
> > Le vendredi 16 février 2018, 21:41:07 SAST [hidden email] 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
> >
> >
> > _______________________________________________
> > Matplotlib-users mailing list
> > [hidden email]
> > https://mail.python.org/mailman/listinfo/matplotlib-users


--
Un clavier azerty en vaut deux
----------------------------------------------------------
Éric Depagne



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency in connecting two subplot.

Éric Depagne
Hi Christophe,

I am not sure it's what Ben had in mind (if not, I'm happy to know  how it
should have been done), but here is the way I did it.

(my _on_move() method is a member of a class)
I added this to the __init__() :
self.counter = 0

Then I added the following lines to _on_move():
self.counter += 1
if self.counter %2 :
        return
[snip all the details of the update of the plots)
self.counter = 0

And it updates the plot every other move.

Éric.

--
Un clavier azerty en vaut deux
----------------------------------------------------------
Éric Depagne


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency in connecting two subplot.

Christophe BAL (via GMAIL)
Thanks

Christophe BAL
Enseignant Agrégé de Mathématiques
Programmeur Python Amateur

Le 20 févr. 2018 20:02, "Éric Depagne" <[hidden email]> a écrit :
Hi Christophe,

I am not sure it's what Ben had in mind (if not, I'm happy to know  how it
should have been done), but here is the way I did it.

(my _on_move() method is a member of a class)
I added this to the __init__() :
self.counter = 0

Then I added the following lines to _on_move():
self.counter += 1
if self.counter %2 :
        return
[snip all the details of the update of the plots)
self.counter = 0

And it updates the plot every other move.

Éric.

--
Un clavier azerty en vaut deux
----------------------------------------------------------
Éric Depagne



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency in connecting two subplot.

Benjamin Root
Yup, that's pretty much it. Since you have it all in a class, then doing `self.counter` makes a lot of sense. You can also tune it accordingly to do only every 3rd, 4th, 5th or what-have-you.

Cheers!
Ben Root

On Tue, Feb 20, 2018 at 3:03 PM, Christophe Bal <[hidden email]> wrote:
Thanks

Christophe BAL
Enseignant Agrégé de Mathématiques
Programmeur Python Amateur

Le 20 févr. 2018 20:02, "Éric Depagne" <[hidden email]> a écrit :
Hi Christophe,

I am not sure it's what Ben had in mind (if not, I'm happy to know  how it
should have been done), but here is the way I did it.

(my _on_move() method is a member of a class)
I added this to the __init__() :
self.counter = 0

Then I added the following lines to _on_move():
self.counter += 1
if self.counter %2 :
        return
[snip all the details of the update of the plots)
self.counter = 0

And it updates the plot every other move.

Éric.

--
Un clavier azerty en vaut deux
----------------------------------------------------------
Éric Depagne



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Efficiency in connecting two subplot.

tcaswell
It looks like you are redrawing the _whole_ figure every time.

You can use blitting (see https://matplotlib.org/api/animation_api.html#funcanimation for details) to only re-draw the axes that is changing.

Tom

On Tue, Feb 20, 2018 at 3:28 PM Benjamin Root <[hidden email]> wrote:
Yup, that's pretty much it. Since you have it all in a class, then doing `self.counter` makes a lot of sense. You can also tune it accordingly to do only every 3rd, 4th, 5th or what-have-you.

Cheers!
Ben Root

On Tue, Feb 20, 2018 at 3:03 PM, Christophe Bal <[hidden email]> wrote:
Thanks

Christophe BAL
Enseignant Agrégé de Mathématiques
Programmeur Python Amateur

Le 20 févr. 2018 20:02, "Éric Depagne" <[hidden email]> a écrit :
Hi Christophe,

I am not sure it's what Ben had in mind (if not, I'm happy to know  how it
should have been done), but here is the way I did it.

(my _on_move() method is a member of a class)
I added this to the __init__() :
self.counter = 0

Then I added the following lines to _on_move():
self.counter += 1
if self.counter %2 :
        return
[snip all the details of the update of the plots)
self.counter = 0

And it updates the plot every other move.

Éric.

--
Un clavier azerty en vaut deux
----------------------------------------------------------
Éric Depagne



_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users

_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users