question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

displot instantly close upon display when using seaborn 0.11.2 with matplotlib 3.5.2

See original GitHub issue

I encountered a case of figure window closing instantly when trying to display a displot.

To reproduce, try the following with seaborn version 0.11.2 and matplotlib version 3.5.2

import seaborn
import matplotlib.pyplot as plt

sns.displot([0,0,1,1,2,3,3,1,0])
plt.show()

In seaborn version 0.11.2, a figure window will flash on the screen and instantly disappear, whereas in seaborn version 0.11.1, a histogram bar plot is displayed in a new window that persists until I closed it.

After some digging, I suspect that this is due to the handling of the backend entry of matplotlib.rcParams. rcParams["backend"] by default is initialized with a sentinel object matplotlib.rcsetup._auto_backend_sentinel. The first time someone tries to access rcParams["backend"] , matplotlib will call matplotlib.pyplot.switch_backend to swap in the actual backend object. The function matplotlib.pyplot.switch_backend, when called, will first close all currently open figures.

In seaborn version 0.11.2, displot will try to create a FacetGrid object in which to place the plot. In the constructor of FacetGrid, at line 408, it creates a Figure object within a context manager. As a result, the rcParams["backend"] gets reverted to the sentinel object upon exit from the with block. The created Figure would get automatically closed the next time the code tries to access rcParams["backend"].

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kailizcatmancommented, Jul 30, 2022

I tested the branch in #2925 in my environment with matplotlib 3.5.2. It worked as expected. Thank you for working on this.

There is probably a question of philosophy and intention when it comes to using rc_context. It seems that some matplotlib developers believe rcParams and related mechanisms should only be used by end users in a somewhat interactive context.

1reaction
kailizcatmancommented, Jul 23, 2022

Let me comment on the issue to see what the matplotlib people thinks. My naive thinking is that any workaround for this issue is bound to have some side-effect (i.e. rcParams["backend"] become updated).

Read more comments on GitHub >

github_iconTop Results From Across the Web

seaborn.displot — seaborn 0.12.1 documentation - PyData |
This function provides access to several approaches for visualizing the univariate or bivariate distribution of data, including subsets of data defined by ...
Read more >
Stop seaborn plotting multiple figures on top of one another
I'm trying to create two plots using seaborn , but it keeps saving the second on top of the first. How do I...
Read more >
[Bug]: get_backend() clears figures from Gcf.figs if they were ...
Bug summary calling matplotlib.get_backend() removes all figures from Gcf ... displot instantly close upon display when using seaborn 0.11.2 ...
Read more >
Seaborn Distplot: A Comprehensive Guide - DigitalOcean
In this article, we will be focusing on Seaborn Distplot in detail. What is a Seaborn Distplot? A Distplot or distribution plot, depicts...
Read more >
Data Visualization in a loop using Seaborn and Matplotlib
There were total 330 columns and plotting each column one by one was very hectic. So, I did a bit of research on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found