Matplotlib jupyter笔记本即使在被抑制时也会打印输出

Matplotlib jupyter笔记本即使在被抑制时也会打印输出,matplotlib,ipython,Matplotlib,Ipython,为什么要从直方图打印箱子? 分号不应该抑制它吗 在[1] import numpy as np import matplotlib.pyplot as plt from IPython.core.interactiveshell import InteractiveShell InteractiveShell.ast_node_interactivity = "all"; 在[2] %matplotlib inline data ={'first':np.random.rand(100),

为什么要从直方图打印箱子? 分号不应该抑制它吗

在[1]

import numpy as np
import matplotlib.pyplot as plt
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all";
在[2]

%matplotlib inline
data ={'first':np.random.rand(100), 
       'second':np.random.rand(100)}
fig, axes = plt.subplots(2)
for idx, k in enumerate(data):
    axes[idx].hist(data[k], bins=20);

如果您阅读文档,您将确切地看到它返回的内容—下面描述的三项元组。您可以在笔记本中显示它,方法是放置?在调用直方图的末尾。看起来您的
交互式Shell
正在显示它。通常情况下,分号会抑制输出,尽管在循环中分号是不必要的

退换商品 n:数组或数组列表 直方图箱的值。请参见标准化权重 对于可能语义的描述。如果输入x是一个 数组,那么这是一个长度为nbins的数组。如果输入是 序列数组
[data1,data2,…]
,然后这是 具有每个数组的直方图值的数组 按同样的顺序

存储箱:阵列 垃圾箱的边缘。长度nbins+1(nbins左边缘和右边缘 最后一个箱子的边缘)。即使有多个数据,也始终使用单个数组 一套一套地传进来

补丁程序:列表或列表列表 用于创建直方图的单个面片的静默列表 或如果有多个输入数据集,则为此类列表的列表


您已经设置了
InteractiveShell.ast\u node\u interactivity=“all”,因此您已将所有节点设置为启用ast交互。因此您可以得到
data={..}

仅适用于最后一个顶级表达式,
轴[idx].hist(数据[k],bin=20)
不是顶级表达式,因为它嵌套在
中,最后一个顶级节点是
,这是一条语句

只需添加最后一条NOOP语句,并以
结束

%matplotlib inline
data ={'first':np.random.rand(100), 
       'second':np.random.rand(100)};
fig, axes = plt.subplots(2);
for idx, k in enumerate(data):
    axes[idx].hist(data[k], bins=20)
pass; # or None; 0; "foo"; ... 
你不会有任何输出

使用
%%ast
magic快速查看表达式的ast