禁用matplotlib pyplot的输出 [英] Disable the output of matplotlib pyplot

查看:149
本文介绍了禁用matplotlib pyplot的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个形状为(1000,2000)的数组A.我使用

I have an array A of shape (1000, 2000). I use matplotlib.pyplot to plot the array, which means 1000 curves, using

import matplotlib.pyplot as plt
plt(A)

这个数字很好,但是有一千行:

The figure is fine but there are a thousand lines of:

<matplotlib.lines.Line2D at 0xXXXXXXXX>

我可以禁用此输出吗?

推荐答案

此输出是plt函数返回的内容(我在这里假定您要编写plt.plot(A)).要取消显示此输出,请为返回对象分配一个名称:

This output is what the plt function is returning (I presume here you meant to write plt.plot(A)). To suppress this output assign the return object a name:

_ = plt.plot(A)

_通常用于指示一个临时对象,以后将不再使用它.请注意,您看到的此输出将仅显示在解释器中,而不是从解释器外部运行脚本时显示.

_ is often used to indicate a temporary object which is not going to be used later on. Note that this output you are seeing will only appear in the interpreter, and not when you run the script from outside the interpreter.

这篇关于禁用matplotlib pyplot的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆