Seaborn plot display in Databricks

SergeyIvanchuk
Databricks Partner

I am using Seaborn version 0.7.1 and matplotlib version 1.5.3

The following code does not display a graph in the end. Any idea how to resolve ? (works in Python CLI on my local computer)

import seaborn as sns
sns.set(style="darkgrid")
tips = sns.load_dataset("tips")
color = sns.color_palette()[2]
g = sns.jointplot("total_bill", "tip", data=tips, kind="reg",
                  xlim=(0, 60), ylim=(0, 12), color=color, size=7)
import matplotlib.pyplot as plt
display(plt.show())

Instead of an image, I get the words "None" shown

chrislill
New Contributor II

Duplicate of https://forums.databricks.com/questions/13369/databricks-wont-display-new-plot-seaborn.html. This confused me for a bit as well.

If you create the figure and axes in matplotlib then seaborn will automatically add the plot to it. The figure can then be displayed in the databricks notebook.

fig, ax = plt.subplots()
sns.jointplot("total_bill", "tip", data=tips, kind="reg", xlim=(0, 60), ylim=(0, 12),
          color=color, size=7)
display(fig)

migueldhr
New Contributor II

Try changing the last line in your code:

display(plt.show())

to

display(g.fig)

My results doing that:

help-databircks.png

DavidLin
Databricks Employee
Databricks Employee

As of DBR 6.4+, %matplotlib inline is supported, and you no longer need to call display().

AbbyLemon
New Contributor II

I found that you create a similar comparison plot as what you get from seaborn by using the display(sparkdf) and adding multiple columns to the 'Values' section while creating a 'Scatter plot'. You get to the 'Customize Plot' by clicking on the icon of the bar chart, then the 'Plot Options...' button will show up.

displaydf.pngplotoptions.png