gpt4 book ai didi

python - Seaborn tsplot 没有显示任何内容

转载 作者:太空宇宙 更新时间:2023-11-04 00:45:58 25 4
gpt4 key购买 nike

我有一个名为 amounts_month 的数据框,属于这种类型:

    product accounting_month    amount
0 A 201404 204748.0
1 A 201405 445064.0
2 B 201404 649326.0
3 B 201405 876738.0
4 C 201404 1046336.0

但是当我评估

import seaborn as sns
import matplotlib.pyplot as plt

sns.tsplot(data=amounts_month,
time='accounting_month',
value='amount',
condition='product'
)

我得到一个空图。我的代码有什么问题?

最佳答案

您可以尝试为产品 C 添加一个数据

product accounting_month    amount
A 201404 204748.0
A 201405 445064.0
B 201404 649326.0
B 201405 876738.0
C 201404 1046336.0
C 201405 1046336.0

然后试试下面的代码:

import seaborn as sns
import matplotlib as mpl
#change the `accounting_month` to datatime
amounts_month['accounting_month']= pd.to_datetime(amounts_month['accounting_month'], format="%Y%m")

fig, ax = plt.subplots()
sns.tsplot(data=amounts_month,
time='accounting_month',
value='amount',
unit='product', # add a unit
condition='product',
ax=ax)
def myFormatter(x, pos):
return pd.to_datetime(x)

# assign locator and formatter for the xaxis ticks.
ax.xaxis.set_major_formatter(mpl.ticker.FuncFormatter(myFormatter))

# put the labels at 45deg since they tend to be too long
fig.autofmt_xdate()
plt.show()

结果:

enter image description here

关于python - Seaborn tsplot 没有显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39569582/

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