首页 > 解决方案 > matplotlib 中的用户警告

问题描述

我正在尝试使用以下代码绘制图表:

import numpy as np
import matplotlib.pyplot as plt
arr = np.random.randint(1,50,10)
print(arr)
y, x = np.histogram(arr,bins=np.arange(51))
fig, ax = plt.subplots()
ax.plot(x[:-1],y)
fig.show()

显示的错误是:

<ipython-input-4-31fe4acba862>:8: UserWarning: Matplotlib is currently using module://ipykernel.pylab.backend_inline, which is a non-GUI backend, so cannot show the figure.

虽然我仍然得到一个图表: 我得到的图表..

标签: python-3.xnumpymatplotlib

解决方案


警告来自fig.show(). 您可以在使用 jupyter 时将其删除。


推荐阅读