Siddhesh Bhurke
Siddhesh Bhurke

Reputation: 105

Matplotlib does not print any plot on Databricks?

%matplotlib inline
corr = df.corr()
f, ax = plt.subplots(figsize=(11, 9))
ax = sns.heatmap(
    corr, 
    vmin=-1, vmax=1, center=0,
    cmap=sns.diverging_palette(20, 220, n=500),
    linewidths=.50, 
    cbar_kws={"shrink": .7},
    square=True
)

ax.set_xticklabels(
    ax.get_xticklabels(),
    rotation=45,
    horizontalalignment='right'
);
plt.show()

This code is does not give any plot display on azure data bricks, only displays

<Figure size 1100x900 with 2 Axes>

whereas the same code worked fine and displayed a corr plot earlier, not sure whats going wrong here. I get the same output even when I try this.

mask = np.triu(np.ones_like(corr, dtype=bool))

f, ax = plt.subplots(figsize=(11, 9))

cmap = sns.diverging_palette(20, 220, as_cmap=True)

sns.heatmap(corr, mask=mask, cmap=cmap, vmax=0.3, center=0,
            square=True, linewidths=.1, cbar_kws={"shrink": .7})
plt.show()

Upvotes: 6

Views: 6854

Answers (2)

WarlockQ
WarlockQ

Reputation: 181

It perhaps may have to do with your Databricks runtime https://docs.databricks.com/notebooks/visualizations/matplotlib.html

For an alternative, Try display(plt.show()) if inline doesn't seem to work

Upvotes: 7

CHEEKATLAPRADEEP
CHEEKATLAPRADEEP

Reputation: 12788

It looks like an issue with the matplotlib modules above 3.3.0.

To know the exact reason, I would suggest you to report here: https://github.com/matplotlib/matplotlib/issues

As per the test from our end, you will experience the following error message with the matplotlib modules above 3.3.0.

enter image description here

If you have installed matplotlib modules above 3.3.0, I would suggest you to use matplotlib modules below 3.2.2.

enter image description here

Once you have installed matplotlib==3.2.2, I'm able to successfully display the plot.

enter image description here

Upvotes: 8

Related Questions