How to Solve the Problem of Seaborn Plots Not Showing

Manav Narula Feb 02, 2024
  1. Use the matplotlib.pyplot.show() Function
  2. Use the matplotlib.pyplot.figure() Function
  3. Use the %matplotlib inline Command
How to Solve the Problem of Seaborn Plots Not Showing

The seaborn function returns a figure containing your desired plot. However, you may feel that your code is correct, but your figure is not showing up. It can be a common occurrence, especially if you work in Python notebook files.

It may be a little hard to understand why this may happen without actually looking at the code. Nevertheless, in this tutorial, we will discuss some common methods that can be used to resolve this.

Use the matplotlib.pyplot.show() Function

Since the seaborn module is built on top of the matplotlib library, it is compatible with many matplotlib functions. The show() function is used to display all the current graphs and plots in the figure. We have to call this function after creating the plot, and it displays your figure.

Note that for Python 2, one can also use sns.plt.show() but not for Python 3.

Use the matplotlib.pyplot.figure() Function

In many cases, we can use the figure() function to resolve this. It activates the current figure or creates a new one. It should be used before creating the seaborn plot.

Use the %matplotlib inline Command

It is used to activate the matplotlib backend. It is used commonly in Python notebooks. In this way, the show function is called at the end of every cell, and the plot is displayed inside the Python notebook. Note that it overrides the show() function, so if this command is used, the seaborn plot will only be displayed inside the notebook.

Author: Manav Narula
Manav Narula avatar Manav Narula avatar

Manav is a IT Professional who has a lot of experience as a core developer in many live projects. He is an avid learner who enjoys learning new things and sharing his findings whenever possible.

LinkedIn