显示每个打印点的记号

2024-06-16 10:45:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Python和编程都是新手

我试图在条形图上描绘每周的价值。我想在x轴上的每个标绘点下有记号,这样就很容易理解值和日期之间的关系

我有一个熊猫dataframe(df_clean)看起来是这样的(很抱歉使用法语列名):

Data columns (total 20 columns):
Statut                    23467 non-null object
P.O                       23467 non-null object
Fournisseur               23467 non-null object
Date Comm.                23467 non-null object
Date Annul.               23466 non-null object
Date TPA                  23467 non-null object
Qté Comm.                 23467 non-null float64
Courant comm.             23467 non-null float64
Cout comm.                23467 non-null float64
Qté recue                 23467 non-null float64
Courant recue             23467 non-null float64
Cout recue                23467 non-null float64
Qté souff.                23467 non-null float64
Courant souff.            23467 non-null float64
Cout souff.               23467 non-null float64
% recue                   23467 non-null float64
% MB                      23467 non-null float64
Premier jour sem. TPA     23467 non-null object
Year TPA                  23467 non-null int64
Jour de la semaine TPA    23467 non-null object

我的目标是为每个df_clean["Premier jour sem. TPA"]绘制df_clean["Cout comm."]之和。我希望它看起来像这样:

Desired result

这是到目前为止的代码

#Group by first day of week
sem_tpa_group = df_clean.groupby("Premier jour sem. TPA").agg("sum")
sem_tpa_group.reset_index(inplace=True)

#Limit the amount of week to show
sem_tpa_group = sem_tpa_group[sem_tpa_group["Premier jour sem. TPA"] > date.today()]

#Create graph
fig = plt.figure()
ax = plt.subplot(111)
plt.plot(sem_tpa_group["Premier jour sem. TPA"], sem_tpa_group["Cout comm."],'o-',label='Ord. cost')
plt.plot(sem_tpa_group["Premier jour sem. TPA"], sem_tpa_group["Cout recue"],'o-',label='Rec. cost')
plt.legend(loc=1)
plt.ylabel('Cost')
plt.xlabel('Week date')
plt.grid()
plt.show()

结果是:

Result

有人能告诉我如何获得x轴上每个标绘点的记号信息吗

我尝试了plt.xticks(),但没有任何结果,尽管我不确定我是否正确使用了它

非常感谢你所做的一切


Tags: cleandfobjectgrouppltnullnonfloat64