Matplotlib 不会在 Databricks 上打印任何图?

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()

此代码不会在 azure data bricks 上给出任何绘图显示,仅显示

<Figure size 1100x900 with 2 Axes>

虽然相同的代码工作正常并且之前显示了一个正确的图,但不确定这里出了什么问题。 即使我尝试这个,我也会得到相同的输出。

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()

上面的 matplotlib 模块似乎有问题 3.3.0

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

根据我们的测试,您将在 3.3.0.

以上的 matplotlib 模块中遇到以下错误消息

如果你安装了3.3.0以上的matplotlib模块,我建议你使用3.2.2以下的matplotlib模块。

一旦你安装了matplotlib==3.2.2,我就可以成功显示剧情了。

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

如果内联似乎不起作用,请尝试 display(plt.show()) 作为替代方案