msimet / Stile

Stile: the Systematics Tests In Lensing pipeline
BSD 3-Clause "New" or "Revised" License
9 stars 6 forks source link

Python cannot show the figures once import stile #122

Open Jeanne-jw opened 1 year ago

Jeanne-jw commented 1 year ago

Hello, I am now trying to use stile package. However, I found that once I import this package, the command plt.show() doesn't work anymore, with such a warning message:

UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.

Even with matplotlib.use('agg'), it doesn't work.

What should I do? Thank you very much!

msimet commented 10 months ago

Hello, sorry this is a late reply--thanks for your patience!

Stile by default assumes you're going to draw figures to a file, so it calls matplotlib.use('agg') as part of its import. Agg isn't designed to draw to the screen. To get figures drawn to the screen:

  1. import stile
  2. matplotlib.use('QtAgg') # or some other interactive backend -- see https://matplotlib.org/stable/users/explain/figure/backends.html for more options! This should override the .use() call in the stile code.
  3. continue with the rest of your code that uses stile

Let me know if that doesn't work, we'll see if we can figure something else out!