首页 > 解决方案 > Matplotlib 不在 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 数据块上显示任何绘图,仅显示

<Figure size 1100x900 with 2 Axes>

而相同的代码工作得很好,并且更早地显示了一个 corr 图,但不确定这里出了什么问题。即使我尝试这个,我也会得到相同的输出。

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

标签: pythonmatplotlibseabornazure-databricks

解决方案


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

要知道确切的原因,我建议你在这里报告:https ://github.com/matplotlib/matplotlib/issues

根据我们的测试,您将在上面的 matplotlib 模块中遇到以下错误消息3.3.0

在此处输入图像描述

如果您在上面安装了 matplotlib 模块3.3.0,我建议您使用下面的 matplotlib 模块3.2.2

在此处输入图像描述

安装matplotlib==3.2.2后,我就可以成功显示该图了。

在此处输入图像描述


推荐阅读