pandas可视化叠加柱状图---excel
本帖最后由 rsj0315 于 2020-6-4 09:53 编辑import pandas as pd
import matplotlib.pyplot as plt
#函数
def to_time(x):
return int(x)+round(int(x)/60,2)
data = pd.read_excel(r'performance.xlsx')
data['up_time']=data['up_time'].astype('str').str.split(':')
data['down_time']=data['down_time'].astype('str').str.split(':')
# 计算开车时间和停车时间
data['up_time']=data['up_time'].apply(to_time)
data['down_time']=data['down_time'].apply(to_time)
#绘制叠加柱状图
data.plot.bar(x='date',y=['up_time','down_time'],stacked=True)
#绘制横向的叠加柱状图
# data.plot.barh(x='date',y=['up_time','down_time'],stacked=True)
#设置标题
plt.xlabel('hour',fontsize=12,fontweight='bold')
plt.ylabel('date_shift',fontsize=12,fontweight='bold')
plt.xticks(rotation='45',ha='right')
plt.title ('C line up_time vs dow_time per shift',fontsize=16,fontweight='bold')
#紧凑型标签
plt.tight_layout()
plt.show()
不错 帮你顶下
页:
[1]