无法在 google colab 中绘制图形

Posted

技术标签:

【中文标题】无法在 google colab 中绘制图形【英文标题】:Unable to plot graph in google colab 【发布时间】:2020-07-02 08:12:06 【问题描述】:

我正在尝试在 google colab 中绘制图表

fig = plt.figure()
plt.title("Weight matrices after model trained")
plt.subplot(1, 3, 1)
plt.title("Trained model Weights")
ax = sns.violinplot(y=h1_w,color='b')
plt.xlabel('Hidden Layer 1')

plt.subplot(1, 3, 2)
plt.title("Trained model Weights")
ax = sns.violinplot(y=h2_w, color='r')
plt.xlabel('Hidden Layer 2 ')

plt.subplot(1, 3, 3)
plt.title("Trained model Weights")
ax = sns.violinplot(y=out_w,color='y')
plt.xlabel('Output Layer ')
plt.show()

该图没有被绘制并且它还显示一个警告 - /usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:8: RuntimeWarning: 超过 20 个数字已打开。通过 pyplot 接口 (matplotlib.pyplot.figure) 创建的图形会一直保留到显式关闭,并且可能会消耗太多内存。 (要控制此警告,请参阅 rcParam figure.max_open_warning)。

如何解决这个问题

【问题讨论】:

这能回答你的问题吗? matplotlib get rid of max_open_warning output 现在,警告已被删除。但仍然没有绘制图表。 plt.show() 命令后没有显示任何内容 【参考方案1】:

听起来您无意中启用了不同的 matplotlib 绘图后端(也许您使用 %matplotlib 魔法更改了后端?)

要让您的绘图恢复正常,请重新启动运行时,或在当前运行时运行

%matplotlib inline
plt.close('all')

以后,避免更改绘图后端。

【讨论】:

以上是关于无法在 google colab 中绘制图形的主要内容,如果未能解决你的问题,请参考以下文章

MATLAB绘制二维图时如何使坐标轴名字显示在右侧?

如何在matlab同一个图形上绘制多条曲线

如何使用matlab在同一图形窗口绘制折线图和柱状图

MATLAB如何绘制三维隐函数图形

MATLAB画图工具中坐标外面的底色是灰的,该如修改?

matlab图形标注与修饰函数titlexlabelylabel matlab图行绘制二