Closed NickCH-K closed 1 year ago
I suspect there is something different in the way that seaborn.objects prints things as opposed to how matplotlib prints things
This is indeed the case; Plot
is rendered through IPython's rich display hooks, specifically see the code here for PNG output (there is also SVG output on master but not in 0.12.2).
Most of your fact pattern makes sense; lineplot
and friends are just fully riding on top of the pyplot hooks, and Plot
doesn't care at all about the %matplotlib
magic mode.
specifically on Mac I guess
This part doesn't make any sense to me though. Seaborn is just returning a bytestream of the PNG data. It's up to IPython to display it / put it in the .ipynb file. That mechanism ends up being quite similar to the matplotlib inline hook, but not identical. E.g., you'll notice that you don't see the object identifier being printed in the REPL output with Plot
, that's because the png is the object representation, whereas the inline backend inserts the png data through a separate process. But at the end of the day, they should both have base64-encoded PNG data in the json data structure. Not sure why that would vary on a Mac.
This is all fairly experimental so I'm open to it being an issue in the way seaborn is using the system, but if you can see the plot in the Jupyter interface but not in the Quarto output that makes me suspect it's an issue where Quarto is not properly grabbing rich outputs from all the places they could be. (Doesn't really explain why it works on Windows, but are you certain you have the same versions of Quarto and the relevant Jupyter libraries in both places?)
FWIW the seaborn docs are based on notebooks (using a custom nbconvert
-> sphinx
bridge) so I know at least some static export pathways handle them fine. Which again implicates Quarto in my mind.
FYI you can work around this if necessary by calling Plot.show()
, which does hook into pyplot. Although then you won't get the nice HiDPI figures by default (you can still enable this through the matplotlib inline display config).
Good to know! Thanks for taking a look at this. Given how you've described it it does sound like a Quarto issue (and very curious the Mac/Windows distinction). Thank you!
Alright, this one involves like four different pieces of software to isolate. But I think the issue here is in seaborn rather than one of those other places. Here's the issue:
fig = plt.figure()
, thenso.Plot().on(fig)
. The second one is printed usingseaborn.objects
directly (without.on(fig)
). These graphs render properly in Jupyter.Note:
objects
seaborn graphs.sns.lineplot()
works fine.inline
ornotebook
) doesn't seem to matter.I suspect there is something different in the way that seaborn.objects prints things as opposed to how matplotlib prints things (specifically on Mac I guess?) that is causing this, which is what makes me thing this is a seaborn.objects issue as opposed to, say, a Quarto issue.
Here is the code for a Jupyter notebook that exhibits the issue. Note that I am using
p.plot()
here, but the same issue occurs if you don't save the plot asp
and instead just haveso.Plot()
on a line by itself.(code chunk 1, this renders properly on both Windows and Mac)
(code chunk 2, this does not show up in the resulting document on Mac, but it works fine on Windows)