Seaborn plots not showing up
Plots created using seaborn need to be displayed like ordinary matplotlib plots.
This can be done using the
plt.show()
function from matplotlib.
Originally I posted the solution to use the already imported matplotlib object from seaborn (sns.plt.show()
) however this is considered to be a bad practice. Therefore, simply directly import the _matplotlib.pyplot_
module and show your plots with
import matplotlib.pyplot as plt
plt.show()
If the IPython notebook is used the inline backend can be invoked to remove the necessity of calling show after each plot. The respective magic is
%matplotlib inline
Seaborn plot is not showing
As mentioned above in the other answer, running in IPython will allow you to see it, but that isn't the only way.
The last line of your method returns a FacetGrid object, which is silently discarded after your method exits, which is why you are seeing nothing other than the warning which is produced. You will need to do something with this object (IPython automatically "prints" it when it is produced).
Change your method like so:
def run_example(self):
sns.set(color_codes=True)
np.random.seed(sum(map(ord, "regression")))
tips = sns.load_dataset("tips")
sns.lmplot(x="size", y="tip", data=tips, x_estimator=np.mean).fig.show()
Now your example will open a graphical window showing the figure
If you want to save it instead, change that last line to
sns.lmplot(x="size", y="tip", data=tips, x_estimator=np.mean).savefig("testing.png")
This sort of behavior is typical of matplotlib and thus seaborn which is built on top of matplotlib. You will have to specify what needs to be done with graphics objects (the %matplotlib inline call in IPython is actually telling IPython to catch these objects and display them).
Seaborn plot not showing all plots with a loop
Because you do not show the plot in each iteration, you can do it using matplotlib
:
import matplotlib.pyplot as plt
sns.set(style="darkgrid")
parm = ['ALTERSKATEGORIE_GROB', 'ANREDE_KZ', 'CJT_GESAMTTYP', 'FINANZ_MINIMALIST', 'FINANZ_SPARER', 'FINANZ_VORSORGER']
for y in parm:
sns.countplot(x=y, data=azdias_under_20)
plt.show()
UPDATE
You asked why your code didn't work. plt.show()
is a method that shows all of the plots you draw before you show. so if you draw one plot and write plt.show()
it will show it. but if you draw many plots, and then you write plt.show()
it will mix all of them and show them all. for more information check this link . look at the following example :
>>> import matplotlib.pyplot as plt
>>> a = [1,2,3,4,5]
>>> b = [1,2,3,4,5]
>>> c = [2,3,4,5,6]
>>> d = [1,4,9,16,25]
>>> plt.plot(a,b)
[<matplotlib.lines.Line2D object at 0x00000180CF934C18>]
>>> plt.plot(a,c)
[<matplotlib.lines.Line2D object at 0x00000180CB39AA58>]
>>> plt.plot(a,d)
[<matplotlib.lines.Line2D object at 0x00000180CF934F60>]
>>> plt.show()
the resulting plot would be :
Seaborn not showing full plot
here data="tips"
is not a string
so you need to change the following line:
sns.jointplot(x='total_bill', y='tip', data=tips)
Seaborn pairplot data not shown
You have encountered a bug in matplotlib 1.3. The solution is to upgrade your matplotlib.
Related Topics
Python Regular Expression Re.Match, Why This Code Does Not Work
Fill Between Two Vertical Lines in Matplotlib
How to Disable SQLalchemy Caching
Can You Give a Django App a Verbose Name for Use Throughout the Admin
Google Search from a Python App
How to Edit a Seaborn Legend Title and Labels for Figure-Level Functions
How to Read Two Lines from a File at a Time Using Python
Why Is Exponentiation Applied Right to Left
Datetime from String in Python, Best-Guessing String Format
Difference Between Type(Obj) and Obj._Class_
Why Do Attribute References Act Like This with Python Inheritance
Print Statement Inside of Input Returns with a "None"