【发布时间】:2021-07-27 10:23:42
【问题描述】:
我在 Python3 中使用 seaborn 和 matplotlib 来可视化两个不同数组的分布。我使用的代码是:
# Create two matrices (can be 'n' dimensional)-
x = np.random.normal(size = (5, 5))
y = np.random.normal(size = (5, 5))
# On using seaborn, it creates two different plots-
sns.displot(data = x.flatten(), label = 'x')
sns.displot(data = y.flatten(), label = 'y')
plt.legend(loc = 'best')
plt.show()
# Whereas, matplotlib merges these two distributions into one plot-
plt.hist(x = x.flatten(), label = 'x')
plt.hist(x = y.flatten(), label = 'y')
plt.legend(loc = 'best')
plt.show()
如何获得将 matplotlib 中实现的这两个分布合并到 seaborn 中的结果?
谢谢!
【问题讨论】:
-
displot是一个图形级别的函数,用一个或多个子图创建自己的图形。您可以改为使用坐标轴级别histplot。
标签: python-3.x matplotlib seaborn distribution