【发布时间】:2021-10-06 06:14:21
【问题描述】:
我正在使用matplotlib 绘制来自.dat 文件的结果。
数据如下
1145, 2021-07-17 00:00:00, bob, rome, 12.75, 65.0, 162.75
1146, 2021-07-12 00:00:00, billy larkin, italy, 93.75, 325.0, 1043.75
114, 2021-07-28 00:00:00, beatrice, rome, 1, 10, 100
29, 2021-07-25 00:00:00, Colin, italy the third, 10, 10, 50
5, 2021-07-22 00:00:00, Veronica, canada, 10, 100, 1000
1149, 1234-12-13 00:00:00, Billy Larkin, 1123, 12.75, 65.0, 162.75
我想以正确的顺序打印一年的数据(1 月到 12 月),并让我的标签显示为月份,而不是长日期。
这是我的代码:
import matplotlib.pyplot as plt
import csv
x = []
y = []
with open('Claims.dat','r') as csvfile:
#bar = csv.reader(csvfile, delimiter=',')
plot = csv.reader(csvfile, delimiter=',')
for row in plot:
x.append(str(row[1]))
y.append(str(row[6]))
plt.plot(x,y, label='Travel Claim Totals!', color='red', marker="o")
plt.xlabel('Months', color="red", size='large')
plt.ylabel('Totals', color="red", size='large')
plt.title('Claims Data: Team Bobby\n Second Place is the First Looser', color='Blue', weight='bold', size='large')
plt.xticks(rotation=45, horizontalalignment='right', size='small')
plt.yticks(weight='bold', size='small', rotation=45)
plt.legend()
plt.subplots_adjust(left=0.2, bottom=0.40, right=0.94, top=0.90, wspace=0.2, hspace=0)
plt.show()
【问题讨论】:
-
仅供参考:彻底回答问题非常耗时。如果您的问题已解决,请通过接受最适合您的需求的解决方案表示感谢。 ✔ 位于答案左上角的 ▲/▼ 箭头下方。如果出现更好的解决方案,则可以接受新的解决方案。如果您的声望超过 15,您还可以使用 ▲/▼ 箭头对答案的有用性进行投票。 如果解决方案无法回答问题,请发表评论。 What should I do when someone answers my question?。谢谢。
标签: python pandas matplotlib