Python 两个图形交点的标记点

Python 两个图形交点的标记点,python,pandas,matplotlib,graphics,Python,Pandas,Matplotlib,Graphics,我对一个代码很难理解。这个想法是比较两个国家的两种新冠病毒病例数据。在图形的交叉点我必须放一个点,但问题是点不在确切的交叉点,而是有点移动,我在过去几天一直在思考,但我无法解决这个问题,如果你能帮助我,我很感激 代码如下: import pandas as pd import matplotlib.pyplot as plt import matplotlib.dates as mdates import numpy as np archivo = pd.read_csv ("ful

我对一个代码很难理解。这个想法是比较两个国家的两种新冠病毒病例数据。在图形的交叉点我必须放一个点,但问题是点不在确切的交叉点,而是有点移动,我在过去几天一直在思考,但我无法解决这个问题,如果你能帮助我,我很感激

代码如下:

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import numpy as np

archivo = pd.read_csv ("full_data.csv")
pd.set_option("display.max_columns", 10)

Pais1 = input("Ingrese el primer pais en ingles: ")
Pais2 = input("Ingrese el segundo pais en ingles: ")
a = input("Ingrese fecha inicial en formato aaaa-mm-dd: ")
b = input("Ingrese fecha final en formato aaaa-mm-dd: ")
df2 = archivo[ archivo['location'] == Pais1]
df3 = archivo[ archivo['location'] == Pais2]
Info1 = df2.to_dict("list")
Info2 = df3.to_dict("list")


gx = [Info1['date'][0]]
gy = [Info1['new_cases'][0]]
ax = [Info2['date'][0]]
ay = [Info2['new_cases'][0]]

crucex = []
crucey = []

for i in range(1, len(Info2['date'])): 
  gx.append(Info1['date'][i])
  gy.append(Info1['new_cases'][i])
  ax.append(Info2['date'][i])
  ay.append(Info2['new_cases'][i])
  if (ay[i] == gy[i]) or (ay[i] > gy[i] and ay[i-1] < gy[i-1]) or (ay[i] < gy[i] and ay[i-1] > gy[i-1]):
    crucex.append(ax[i])
    crucey.append(ay[i])

gy1 = [Info1['total_deaths'][0]]
ay1 = [Info2['total_deaths'][0]]

crucex1 = []
crucey1 = []

for i in range(1, len(Info2['date'])): 
  gy1.append(Info1['total_deaths'][i])
  ay1.append(Info2['total_deaths'][i])
  if (ay1[i] == gy1[i]) or (ay1[i] > gy1[i] and ay1[i-1] < gy1[i-1]) or (ay1[i] < gy1[i] and ay1[i-1] > gy1[i-1]):
    crucex1.append(ax[i])
    crucey1.append(ay[i])



fig, (ax1, ax2) = plt.subplots (2, figsize=(16, 8))

ax1.plot(gx, gy, label=Pais1)
ax1.plot(ax, ay, label=Pais2)
ax1.plot(crucex, crucey, 'k.', label="Cruces")
ax1.legend()
ax1.set_title("Casos")
ax1.set_xlim(a, b)

ax2.plot(gx, gy1, label=Pais1)
ax2.plot(ax, ay1, label=Pais2)
ax2.plot(crucex1, crucey1, 'k.', label="Cruces")
ax2.legend()
ax2.set_title("Fallecimientos")
ax2.set_xlim(a, b)


fig.autofmt_xdate()
fig.fmt_xdata = mdates.DateFormatter('%Y-%m-%d')
plt.show()`
将熊猫作为pd导入
将matplotlib.pyplot作为plt导入
将matplotlib.dates导入为mdates
将numpy作为np导入
archivo=pd.read\u csv(“full\u data.csv”)
pd.set_选项(“display.max_columns”,10)
Pais1=输入(“入口el底漆pais en ingles:”)
Pais2=输入(“入口和入口:”)
a=输入(“入口fecha专用格式aaaa mm dd:”)
b=输入(“入口fecha最终格式aaaa mm dd:”)
df2=archivo[archivo['location']==Pais1]
df3=archivo[archivo['location']==Pais2]
Info1=df2.对目录(“列表”)
Info2=df3.对目录(“列表”)
gx=[Info1['date'][0]]
gy=[Info1['新案例][0]]
ax=[Info2['date'][0]]
ay=[Info2['新案例][0]]
克鲁塞克斯=[]
克鲁西=[]
对于范围内的i(1,len(Info2['date']):
追加(Info1['date'][i])
gy.append(Info1['new_cases'][i])
ax.append(Info2['date'][i])
ay.追加(Info2['新案例][i])
如果(ay[i]==gy[i])或(ay[i]>gy[i]和ay[i-1]gy[i-1]):
crucex.append(ax[i])
crucey.append(ay[i])
gy1=[Info1['死亡总数][0]]
ay1=[Info2['死亡总数][0]]
crucex1=[]
CRUCECY1=[]
对于范围内的i(1,len(Info2['date']):
gy1.追加(Info1['死亡总数][i])
ay1.追加(Info2[‘总死亡人数’][i])
如果(ay1[i]==gy1[i])或(ay1[i]>gy1[i]和ay1[i-1]gy1[i-1]):
crucex1.append(ax[i])
crucey1.追加(ay[i])
图(ax1,ax2)=plt.子批次(2,figsize=(16,8))
ax1.绘图(gx,gy,标签=Pais1)
ax1.绘图(ax,ay,label=Pais2)
ax1.绘图(crucex,crucey,'k',label=“Cruces”)
ax1.legend()
ax1.设置标题(“Casos”)
ax1.set_xlim(a,b)
ax2.绘图(gx,gy1,标签=Pais1)
ax2.绘图(ax,ay1,label=Pais2)
ax2.绘图(crucex1,crucey1,'k',label=“Cruces”)
ax2.legend()
ax2.设置标题(“错误提示”)
ax2.set_xlim(a,b)
图autofmt_xdate()
fig.fmt_xdata=mdates.DateFormatter(“%Y-%m-%d”)
plt.show()`