2

Typically if I want to make an interactive plot, I use %matplotlib qt, such that I can explore, zoom, add to the figure etc. I wanted to make an area plot, and with the release of seaborn objects, this is easy. Only, it always plots "inline" in my console (spyder), which I find really user-unfriendly as compared with the interactive plotting I normally do (with the normal seaborn plots which are built on matplotlib, there is no problem). Is there anyone who knows a solution for this?

fig, ax = plt.subplots(nrows = 1, ncols = 1, figsize=(15,8))
p = so.Plot(sumstat, "date", "std")
p.add(so.Area())
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
iadriaens
  • 56
  • 5
  • The code shown is not a complete [mre]. You should probably update spyder in Anaconda. The graphics backend is set in Preferences, IPython console, Graphics tab, and graphics backend - select Qt5. Additionally, the code never tells `p` to use `ax`. It needs `.on(ax)`. In spyder this works to have an interactive plot appear, however, nothing is plotted into the figure. I think this needs to be addressed by @mwaskom, who is the package author. If seen [Duplicate plots are output when using seaborn.objects with subplots in jupyter](https://stackoverflow.com/q/75935491/7758804), but doesn't help. – Trenton McKinney Jun 12 '23 at 17:27
  • [How do I get interactive plots again in Spyder/IPython/matplotlib?](https://stackoverflow.com/a/31488324/7758804) – Trenton McKinney Jun 12 '23 at 17:29
  • With an inline plot, nothing appears on the [plot](https://i.stack.imgur.com/0wmpD.png). With an interactive plot, the interactive figure appears, but nothing shows on the [plot](https://i.stack.imgur.com/VVJeZ.png) – Trenton McKinney Jun 12 '23 at 17:41

1 Answers1

0

To compile the Plot using the axes that you have created, you want Plot.on:

fig, ax = plt.subplots(nrows = 1, ncols = 1, figsize=(15,8))
(
    so.Plot(sumstat, "date", "std")
    .add(so.Area())
    .on(ax)
)

Or you can keep the entire specification within the objects interface but hook into pyplot for the display using Plot.show:

(
    so.Plot(sumstat, "date", "std")
    .add(so.Area())
    .layout(size=(15, 8))
    .show()
)
mwaskom
  • 46,693
  • 16
  • 125
  • 127