Skip to content

Issues with popup qtagg and tkagg backends #244

Closed

Description

@Xunius

Description

Trying to create a basic contourf(). The figure window shows up, but it is shaking, and Python freezes.

It seems like proplot is adjusting sizes or something but ends up in an infinite loop.

Steps to reproduce

Installed proplot using conda install -c conda-forge proplot.
Then run this following script:

import numpy as np
import proplot as pplot

if __name__=='__main__':

    lons=np.arange(0, 360)
    lats=np.arange(-90, 90)
    lons, lats=np.meshgrid(lons, lats)
    var=np.random.random(lons.shape)

    fig,ax=pplot.subplots()
    cs=ax.contourf(lons, lats, var)
    ax.format(title='Test')
    ax.colorbar(cs)
    fig.show()

Expected behavior: A window pops up showing a global mean sea level pressure plot.

Actual behavior: A window pops up but the figure elements and the figure window itself are shaking. Python freezes.

I also created a screencapture showing the issue: https://github.com/Xunius/git_demo/blob/master/simplescreenrecorder-2021-02-10_20.33.19.mp4 (NOTE the example in the screencatpure is using cartopy, but the symptom is the same.)

Equivalent steps in matplotlib

Pretty sure this is proplot specific.

Proplot version

  • Proplot: 0.6.4
  • Python: 3.8.5
  • matplotlib: 3.3.2

The issue also happens in another environment:

  • Proplot: 0.6.4
  • Python: 3.7.9
  • matplotlib: 3.2.2

OS: Manjaro Linux

Activity

  1. lukelbd commented on Jun 30, 2021

    @lukelbd
    Collaborator

    Which backend are you using? Try printing from matplotlib import rcParams; print(rcParams['backend']) from your matplotilb session.

    Proplot struggles with a lot of "interactive" backends because its geometry algorithm automatically resizes figures (which can trigger a backend refresh, which can trigger a figure resize... have to work around these issues very carefully).

  2. Xunius commented on Jul 1, 2021

    @Xunius
    Author

    I was using Qt5Agg, and I tried TkAgg which is also unstable.

  3. lukelbd commented on Jul 1, 2021

    @lukelbd
    Collaborator

    Thanks. Just tried it out in an ipython session with %matplotlib qt and I also get very slow/laggy behavior, even though IIRC proplot used to work fine with the qt backend. These are always fun to debug...

    For now if you're on mac you can also try %matplotlib osx, seems to work fine for me. And proplot usually works really well with static inline jupyter notebook/console backends.

  4. Xunius commented on Jul 1, 2021

    @Xunius
    Author

    Thanks for replying. I'm afraid I don't have a mac machine. Most of the time I don't use ipython or jupyter, but plain python in a terminal. By "static inline console backends" did you mean backends likePS, Agg, PDF? With these I can only save the image to a file, but can't display it in a window using figure.show(), can I?

  5. lukelbd commented on Jul 1, 2021

    @lukelbd
    Collaborator

    By "static inline console backends" did you mean...

    I meant backends used in jupyter notebooks and consoles. Looks something like this:

    Screen Shot 2021-07-01 at 12 31 53 PM

    Screen Shot 2021-07-01 at 12 38 13 PM

    Most of the time I don't use ipython or jupyter, but plain python in a terminal.

    Will try to get on this, proplot should definitely work with the basic popup backends used when running naked python scripts.

  6. changed the title [-]Figure window keeps on shaking and python freezes[/-] [+]Issues with popup qtagg and tkagg backends[/+] on Jul 1, 2021
  7. lukelbd commented on Jul 4, 2021

    @lukelbd
    Collaborator

    Hmmm, I can't reproduce this behavior anymore... I think my "qt is laggy/frozen" observation the other day might have been due to the fact that qt is more resource intensive and I had more processes running that day. Just tried your example with qt5agg and tkagg in master and in v0.6.4 and they seems to work fine. Also I've never seen the "window shaking" behavior, could you re-upload the movie? Looks like the link is dead.

    I wonder if this could be platform-specific. Maybe your OS is for some reason automatically resizing the window slightly (or were you maybe trying to manually resize the figure by clicking and dragging)? When the window changes size, proplot tries to adjust the spacing, and for figures with dense graphics (like your example) this is always going to be pretty slow. A workaround would be to use fig.subplots(..., tight=False) and set spaces manually but that's obviously not ideal.

    Submitting a release soon so if this bug gets confirmed and eventually fixed it will probably go into the next minor release.

  8. Xunius commented on Jul 5, 2021

    @Xunius
    Author

    I forgot to make the repo where the video was uploaded to public. Could you try that link again and see if you can see the video?

    Setting the tight=False kwarg does solve the shaking window problem, but the colorbar is put too far away. I assume that wouldn't be a viable workaround.

  9. lukelbd commented on Jul 5, 2021

    @lukelbd
    Collaborator

    Wow that is... interesting. Yeah with tight=False you'd have to manually set all your spacings -- for the colorbar spacing you would use e.g. ax.colorbar(..., space='2em'), ax.colorbar(..., space=0.5), etc (see this page).

    Unfortunately it looks like this is probably OS specific so will be hard for me to debug but I'll take a close look at the auto spacing algorithm. Interesting that this happens with both Qt5Agg and TkAgg.

    And just to confirm, this doesn't happen in matplotlib plots with matplotlib's tight_layout algorithm enabled? Example:

    import matplotlib.pyplot as plt
    import numpy as np
    
    if __name__=='__main__':
    
        lons=np.arange(0, 360)
        lats=np.arange(-90, 90)
        lons, lats=np.meshgrid(lons, lats)
        var=np.random.random(lons.shape)
    
        fig,ax=plt.subplots()
        fig.set_tight_layout(True)  # adjust layout every time figure is drawn
        cs=ax.contourf(lons, lats, var)
        ax.set_title('Test')
        fig.colorbar(cs)
        fig.show()
  10. Xunius commented on Jul 6, 2021

    @Xunius
    Author

    Yes I can confirm that this doesn't happen to plain matplotlib plot with tight_layout on.

  11. lukelbd commented on Jul 12, 2021

    @lukelbd
    Collaborator

    FYI was able to reproduce this, but strangely, only for plots with certain content (e.g. everything was fine with 1 pcolor subplot and one empty subplot, but not 2 pcolor subplots).

    Definitely on my radar but will probably take a deep dive into my whole auto sizing algorithm to figure out. Maybe 0.7.1

  12. Xunius commented on Jul 12, 2021

    @Xunius
    Author

    Thanks for the update. Looking forward to seeing the new version.

  13. added this to the Version 0.8 milestone on Jul 21, 2021
  14. lukelbd commented on Aug 18, 2021

    @lukelbd
    Collaborator

    I've made some major changes to the internals for a v0.8 release, including improvements to the tight layout algorithm. Might be worth trying this again (try installing the dev version with pip install git+https://github.com/lukelbd/proplot.git). Haven't been able to reproduce this since the changes

  15. lukelbd commented on Jan 24, 2022

    @lukelbd
    Collaborator

    I think I'll close this for now, but if anyone reading this thread experiences issues with the qt backend, please let me know and I'll be happy to reopen.

  16. MarlenK7 commented on Jul 10, 2023

    @MarlenK7

    Hey! Is there any workaround solution regarding the changed auto_layout of matplotlib.pyplot after importing proplot, besides this tight_layout solution (or downgrading matplotlib)? A simple matplotlib.pyplot.plot(x) after the import still messes up the layout.
    Screenshot 2023-07-10 at 16 41 12

    Versions: matplotlib 3.4.3 / proplot 0.9.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions