折线图和子图操作

import pandas as pd
path=r"E:\北风\数据科学脚本\Python_book\5Preprocessing\sale.csv"
info=open(path)
info_1=pd.read_csv(info)
print(info_1)
info_1["date"]=pd.to_datetime(info_1["year"])
print(info_1.head(10))
    year market   sale  profit
0   2010      东  33912    2641
1   2010      南  32246    2699
2   2010      西  34792    2574
3   2010      北  31884    2673
4   2011      东  31651    2437
5   2011      南  30572    2853
6   2011      西  34175    2877
7   2011      北  30555    2749
8   2012      东  31619    2106
9   2012      南  32443    3124
10  2012      西  32103    2593
11  2012      北  31744    2962
   year market   sale  profit                          date
0  2010      东  33912    2641 1970-01-01 00:00:00.000002010
1  2010      南  32246    2699 1970-01-01 00:00:00.000002010
2  2010      西  34792    2574 1970-01-01 00:00:00.000002010
3  2010      北  31884    2673 1970-01-01 00:00:00.000002010
4  2011      东  31651    2437 1970-01-01 00:00:00.000002011
5  2011      南  30572    2853 1970-01-01 00:00:00.000002011
6  2011      西  34175    2877 1970-01-01 00:00:00.000002011
7  2011      北  30555    2749 1970-01-01 00:00:00.000002011
8  2012      东  31619    2106 1970-01-01 00:00:00.000002012
9  2012      南  32443    3124 1970-01-01 00:00:00.000002012
import matplotlib.pyplot as plt
import numpy as np
plt.plot(info_1["sale"],info_1["date"])
plt.xticks(rotation=45)
plt.xlabel("money")
plt.ylabel("year")
plt.title("year-sales")
plt.show()

在这里插入图片描述png

fig=plt.figure()
ax1=fig.add_subplot(4,4,1)
ax2=fig.add_subplot(4,4,3)
ax3=fig.add_subplot(4,4,8)
ax1.plot(np.random.randint(1,5,5),np.arange(5))
ax2.plot(np.arange(10)*3,np.arange(10))

plt.show()

在这里插入图片描述png

fig=plt.figure(figsize=(6,3))
info_1["Year"]=info_1["date"].dt.year
#print(info_1)
plt.figure(figsize=(6,3))
plt.plot(info_1[0:5]["year"],info_1[0:5]["sale"],c="red")
plt.plot(info_1[5:10]["year"],info_1[5:10]["sale"],c="blue")
plt.show()
<matplotlib.figure.Figure at 0x1e03f6b7048>

在这里插入图片描述png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值