python - Jupyter 笔记本中未显示的绘图

标签 python matplotlib

我正在尝试为 Anscombe 数据集创建一个 2x2 的图

加载数据集并分离数据集中的每个类

import seaborn as sns
import matplotlib.pyplot as plt

anscombe = sns.load_dataset('anscombe')

dataset_1 = anscombe[anscombe['dataset'] == 'I']
dataset_2 = anscombe[anscombe['dataset'] == 'II']
dataset_3 = anscombe[anscombe['dataset'] == 'III']
dataset_4 = anscombe[anscombe['dataset'] == 'IV']

创建一个图形并分成 4 个部分
fig = plt.figure()

axes_1 = fig.add_subplot(2,2,1)
axes_2 = fig.add_subplot(2,2,2)
axes_3 = fig.add_subplot(2,2,3)
axes_4 = fig.add_subplot(2,2,4)

axes_1.plot(dataset_1['x'], dataset_1['y'], 'o')
axes_2.plot(dataset_2['x'], dataset_2['y'], 'o')
axes_3.plot(dataset_3['x'], dataset_3['y'], 'o')
axes_4.plot(dataset_4['x'], dataset_4['y'], 'o')

axes_1.set_title('dataset_1')
axes_2.set_title('dataset_2')
axes_3.set_title('dataset_3')
axes_4.set_title('dataset_4')

fig.suptitle('Anscombe Data')

fig.tight_layout()


我在每个图中得到的唯一输出是
[<matplotlib.lines.Line2D at 0x24592c94bc8>]

我究竟做错了什么?

最佳答案

如果您使用的是 Jupyter Notebook,那么您可以将以下行添加到您调用所有导入的顶部单元格。以下命令将呈现您的图形

%matplotlib inline

enter image description here

关于python - Jupyter 笔记本中未显示的绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61128143/

相关文章:

python - 有没有办法将字典的所有值设置为零?

python - Tornado PUT 请求丢失的正文

python - 防止正则表达式中的灾难性回溯

python - 如何通过 matplotlib 缩放直方图

python - 在pylab中显示X轴和y轴

python - 子集 pandas 数据框直到第一次满足条件时

python - Python 中的同时循环

python - 使用 matplotlib 在垂直横截面上绘制风矢量

python - matplotlib.pyplot 和 numpy 中的递减

Python/rq - 监控工作人员状态