在Jupyter Notebook中隐藏Matplotlib描述

38

我不确定这个术语的正确称呼,但是当我绘制图形时,会看到以下内容:

enter image description here

实际上,图形就是我想要看到的,但 jupyter notebook 也输出了一些文本:<matplotlib.axes._subplots.AxesSubplot at 0x1263354d0><matplotlib.figure.Figure at 0x1263353d0>,我正在尝试摆脱它们。

经过一些搜索,我唯一找到的一个方法是使用plt.ioff() ,但是它对我没有帮助。有没有办法摆脱这些文本?


1
https://dev59.com/Al8e5IYBdhLWcg3wZpvw - Luis
2个回答

75
您可以在相应的(matplotlib)代码行末尾加上分号;来完成该行。

3
也适用于 seabornsns.lineplot(data=data, palette="tab10", linewidth=2.5); - silkfire
4
多么出色的回答! - rohaldb

15
这是一个折中方案,但它应该可以始终正常工作: 1. 将绘图函数分配到一个变量中(如果以后需要访问一些绘图元素,这也可能很有用)
plt.figure(figsize=(3, 3))

plot = plt.plot(range(10),
                [x*x for x in range(10)],
                'o-')

2. 在单元格底部添加“pass”(或等效的操作,没有任何后果)

plt.figure(figsize=(3, 3))

plt.plot(range(10),
         [x*x for x in range(10)],
         'o-')
pass

3. 在最后一个语句的结尾添加一个分号

plt.figure(figsize=(3, 3))

plt.plot(range(10),
         [x*x for x in range(10)],
         'o-');

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接