gpt4 book ai didi

python - 给定numpy ndarray的Seaborn fiddle 图随时间变化

转载 作者:行者123 更新时间:2023-12-04 00:58:48 26 4
gpt4 key购买 nike

我有一个随时间变化的分布,我想使用 seaborn 为每个时间步并排绘制 fiddle 图。我最初的尝试失败了,因为 violinplot 无法处理 y 参数的 np.ndarray:

import numpy as np
import seaborn as sns

time = np.arange(0, 10)
samples = np.random.randn(10, 200)

ax = sns.violinplot(x=time, y=samples) # Exception: Data must be 1-dimensional

海生documentation有一个按分类变量分组的垂直 fiddle 图的示例。但是,它使用长格式的 DataFrame。

我是否也需要将我的时间序列转换为 DataFrame?如果是这样,我该如何实现?

最佳答案

仔细查看文档后,我意识到完全省略 xy 参数会导致 data 参数被广泛解释-形式:

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt


samples = np.random.randn(20, 10)
ax = sns.violinplot(data=samples)
plt.show()

Violin plot over time

关于python - 给定numpy ndarray的Seaborn fiddle 图随时间变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60352519/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com