我有一个名为 data
的 5D 数组
for i in range(10):
sns.distplot(data[i,0,0,0], hist=False)
但我想将它们放在子图中。我该怎么做?
试过这个:
plt.rc('figure', figsize=(4, 4))
fig=plt.figure()
fig, ax = plt.subplots(ncols=4, nrows=3)
for i in range(10):
ax[i].sns.distplot(data[i,0,0,0], hist=False)
plt.show()
这显然行不通。
最佳答案
您可能希望使用 seaborn distplot
函数的 ax
参数为其提供现有轴。可以通过在扁平的轴数组上循环来简化循环。
fig, axes = plt.subplots(ncols=4, nrows=3)
for i, ax in zip(range(10), axes.flat):
sns.distplot(data[i,0,0,0], hist=False, ax=ax)
plt.show()
关于python - 如何在循环中制作 seaborn 分布子图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53310228/