import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.read_excel (r'C:\Users\ZiyuZhang\OneDrive - Bota Biosciences\Programm data\sugar consumption.xlsx' ,
sheet_name="Sheet1",
index_col=0)
df = df.dropna(how='all').T
plt.figure(figsize=(10,5))
plt.ylim(0, 7)
Timelist=[]
Median=[]
for i in df:
Timelist.append(str(i))
Median.append(np.median(df[i].dropna()))
plt.boxplot([df[i].dropna() for i in df],labels=Timelist)
plt.plot(Timelist,Median)
plt.show()
I am trying to draw a boxplot with median line, but the x-aixs of boxplot is not aligned with the line chart, why?