我正在尝试为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>]
我在做什么错了?
答案 0 :(得分:0)
添加%matplotlib inline
或使用matplotlib.pyplot.ion()
导入matplotlib之后。
从IPython 5.0和matplotlib 2.0开始,您可以避免使用 IPython的特殊魔术和用法 matplotlib.pyplot.ion()/ matplotlib.pyplot.ioff()具有 在IPython之外工作的好处。
答案 1 :(得分:0)