Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 594
Siddhesh Bhurke Avatar asked Aug 29 '26 14:08

Siddhesh Bhurke


2 Answers

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

like image 63
CHEEKATLAPRADEEP-MSFT Avatar answered Aug 31 '26 06:08

CHEEKATLAPRADEEP-MSFT


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

like image 28
WarlockQ Avatar answered Aug 31 '26 04:08

WarlockQ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!