Python 我需要使用Matplotlib在图中注释新冠病毒19(12-01-2020)的出现
在过去的4天里,我一直试图用Matplotlib在图表中注释新冠病毒(12-01-2020)的出现,但没有成功。我快到大学研讨会报告的截止日期了 csv文件: 我需要的是:Python 我需要使用Matplotlib在图中注释新冠病毒19(12-01-2020)的出现,python,matplotlib,Python,Matplotlib,在过去的4天里,我一直试图用Matplotlib在图表中注释新冠病毒(12-01-2020)的出现,但没有成功。我快到大学研讨会报告的截止日期了 csv文件: 我需要的是: x轴应以年为单位 在特定日期(12-01-2020)绘制垂直线 注释“新冠病毒爆发” 注意:当我尝试以年为单位在x轴上绘制图形时,我无法指定V线和注释值,因为在2020年和2021年之间没有可引用的值 谢谢你 import matplotlib.pyplot as plt import pandas as pd # Loa
import matplotlib.pyplot as plt
import pandas as pd
# Loading the data form the disk
read = pd.read_csv("Graph.csv", parse_dates=['date'],
index_col=['date'])
# Plotting the graph with custom properties
plt.plot(read.index.values,
read['Blockchain'],
color='purple',
label = "Carriage Services, Inc.")
# Annotate advent of covid in US
plt.annotate("Covid", xy=("12-01-2020", 20))
plt.tight_layout()
plt.show()
修复方法是数据中没有
12-01
,x轴规范必须采用时间戳格式
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
read = pd.read_csv('./data/Graph_20201225.csv', sep=',', parse_dates=\['date'\],index_col=\['date'\])
read.index = pd.to_datetime(read.index, format='%Y-%m-%d')
plt.plot(read.index.values,
read\['Blockchain'\],
color='purple',
label = "Carriage Services, Inc.")
# Annotate advent of covid in US
plt.annotate("Covid", xy=(pd.Timestamp('2020-12-06 00:00:00'), 20))
plt.tight_layout()
plt.show()
我也很高兴能帮助你。请接受我的回答。