没有轴的空 matplotlib 图未显示在 Jupyter 笔记本中

时间:2021-07-02 07:28:17

标签: python matplotlib jupyter-notebook

我在装有 M1 芯片的 MacBook Pro 上使用 macOS 版本 11.4,软件版本低于:

  • Python 3.8.8
  • matplotlib 3.3.4
  • Jupyter 笔记本 6.3.0
  • jupyter 核心:4.7.1
  • ipython 7.22.0

笔记本中不会呈现空白图形,但笔记本中确实会显示具有至少 1 个子图或轴的图形。有人可以帮我理解为什么会这样吗?我以前在 Windows 笔记本电脑中尝试过同样的事情,甚至会出现空白数字。代码如下:

%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt

# the below line does not show any image
fig = plt.figure(facecolor=(1,0,0,0.1), figsize=plt.figaspect(0.5))
plt.show();
# the output is - "<Figure size 576x288 with 0 Axes>"

#whereas, if I add a subplot to the figure, it renders a figure inline in the notebook
fig = plt.figure(facecolor=(1,0,0,0.1), figsize=plt.figaspect(0.5))
ax = fig.add_subplot(111)
plt.show();

A subplot within the figure is displayed

0 个答案:

没有答案