【问题标题】:Suppress output of object when plotting in ipython在 ipython 中绘图时抑制对象的输出
【发布时间】:2013-01-24 16:54:14
【问题描述】:

在ipython中绘制直方图时是否可以抑制数组输出?:

例如:

plt.hist(OIR['Range'], bins, named=True, histtype='bar')

在显示图形之前输出/打印数组信息。

【问题讨论】:

    标签: pandas ipython


    【解决方案1】:

    只需在代码后面加上;
    它仅适用于 ipython-notebook。

    plt.hist(...);

    【讨论】:

    • 绝妙的解决方案!之所以可行,是因为 notebook 显示了最后一个命令的返回值。通过添加;,最后一个命令为“nothing”,因此没有返回值可显示。
    【解决方案2】:

    将返回值分配给一个变量(我称之为_ 表示它未使用):

    _ = plt.hist(...)
    

    【讨论】:

    • 或者,您可以通过在最后一行末尾添加分号来抑制输出:plot(foo);
    【解决方案3】:

    你也可以加plt.show():

    plt.hist(OIR['Range'], bins, named=True, histtype='bar')
    plt.show() 
    

    【讨论】:

      猜你喜欢
      • 2017-11-02
      • 2014-07-04
      • 2020-11-03
      • 2019-11-01
      • 2011-11-21
      • 2015-08-28
      • 2020-04-17
      • 1970-01-01
      • 2015-04-21
      相关资源
      最近更新 更多