Python 显示每个打印点的刻度

Python 显示每个打印点的刻度,python,python-3.x,matplotlib,Python,Python 3.x,Matplotlib,一般来说,我对Python和编程都是新手 我试图在条形图上绘制每周的值。我希望在x轴上的每个打印点下都有记号,这样就很容易理解值和日期之间的关系 我有一个Pandasdataframe(df_clean)看起来像这样(很抱歉使用法语列名): 我的目标是为每个df_clean[“Cout comm.”]绘制df_clean[“Premier jour sem.TPA”]的总和。我希望它看起来像这样: 这是到目前为止的代码 #Group by first day of week sem_tpa_g

一般来说,我对Python和编程都是新手

我试图在条形图上绘制每周的值。我希望在x轴上的每个打印点下都有记号,这样就很容易理解值和日期之间的关系

我有一个Pandas
dataframe(df_clean)
看起来像这样(很抱歉使用法语列名):

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

这是到目前为止的代码

#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()
结果是:

有人能告诉我如何获取x轴上每个标绘点的刻度信息吗

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


非常感谢您所做的一切

类似于
plt.xticks(matplotlib.dates.date2num((sem\u tpa\u group[“Premier jour sem.tpa]”)的东西可能会起作用。很难说是什么单位。通常,matplotlib将日期表示为自0000-01-01起的摆动点天数。“所需”绘图很可能由
df.plot.bar
生成。熊猫酒吧的情节是绝对的。Matplotlib
bar
plot以及line
plot
s是数字图。通过在绘图之前将日期时间索引/列转换为字符串,您仍然可以使用matplotlib实现分类绘图。类似于
plt.xticks(matplotlib.dates.date2num((sem_tpa_group[“Premier jour sem.tpa”])
的方法可能有效。很难说是什么单位。通常,matplotlib将日期表示为自0000-01-01起的摆动点天数。“所需”绘图很可能由
df.plot.bar
生成。熊猫酒吧的情节是绝对的。Matplotlib
bar
plot以及line
plot
s是数字图。通过在打印前将日期时间索引/列转换为字符串,仍然可以使用matplotlib实现分类打印。
#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()