matplotlib画图9

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl
import seaborn as sns
import numpy as np
plt.rcParams['font.sans-serif']=['SimHei']


#年
year=[1949,1949,1949,1949,1949,1949,
      1950,1950,1950,1950,1950,1950,
      1951,1951,1951,1951,1951,1951,
      1952,1952,1952,1952,1952,1952,]
#月
month=['jan','feb','mar','apr','may','jun',
       'jan','feb','mar','apr','may','jun',
       'jan','feb','mar','apr','may','jun',
       'jan','feb','mar','apr','may','jun',]
#
pas=[112,118,132,128,121,115,
     112,145,132,134,121,115,
     112,118,132,128,121,115,
     112,118,132,154,133,115,]

#将列表数据变为dataframe,在变csv,dataframe

df=pd.DataFrame({"year":year,"month":month,"pas":pas})
df.to_csv('passengers.csv')
df2=pd.read_csv("passengers.csv")
#按年份分组
df3=df2.groupby('year').sum()
print(df3)
#画图
plt.subplot(1,2,1)
plt.plot(df3['pas'],marker='o')
plt.xlabel('年份')
plt.ylabel('乘客')
plt.title("年份——乘客曲线图")
#按月份
df4=df2.groupby('month').sum()
plt.subplot(1,2,2)
plt.bar(df2.loc[0:5,'month'],df4['pas'])
plt.xlabel('yue份')
plt.ylabel('乘客')
plt.title("yue份——乘客曲线图")
plt.show()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值