i'm trying to make a 2x1 subplot figure in seaborn using:
data = pandas.DataFrame({"x": [1, 2, 4],
"y": [10,20,40],
"s": [0.01,0.1,1.0]})
plt.figure()
plt.subplot(2, 1, 1)
sns.pointplot(x="x", y="y", data=data)
plt.errorbar(np.arange(len(data["x"])), data["y"], yerr=data["s"])
plt.subplot(2, 1, 2)
sns.factorplot(x="x", y="y", data=data)
plt.show()
it produces two separate figures instead of a single figure with two subplots. why does it do this and how can seaborn be called multiple times for separate subplots?
i tried looking at the post referenced below but i cannot see how the subplots can be added even if factorplot
is called first. can someone show an example of this? it would be helpful. my attempt:
data = pandas.DataFrame({"x": [1, 2, 4],
"y": [10,20,40],
"s": [0.01,0.1,1.0]})
fig = plt.figure()
sns.pointplot(x="x", y="y", data=data)
ax = sns.factorplot(x="x", y="y", data=data)
fig.add_subplot(212, axes=ax)
plt.errorbar(np.arange(len(data["x"])), data["y"], yerr=data["s"])
plt.show()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…