python3 pandas matplotlib绘图

def test03():
    INPUTFILE1 = os.path.join(BASE_PATH, 'Students1.xlsx')
    datas = ExcelUntil.readExcelFile(INPUTFILE1, headerRow=0)
    for sheetname,sheetdatas in datas.items():
        print(sheetdatas.head(8))
        sheetdatas['Number'] = sheetdatas['Number'].astype('int')
        sheetdatas.sort_values(by='Number',ascending=True,inplace=True) # false 从大到小
        print(sheetdatas.head(8))
        plt.bar(sheetdatas['Field'],sheetdatas['Number'],color='orange',width=0.7)
        plt.xticks(sheetdatas['Field'],rotation='60')
        plt.title('International Students by Field',fontsize=16)
        plt.xlabel('Field')
        plt.ylabel('Number')
        plt.tight_layout()
        plt.show()

def test04():
    INPUTFILE1 = os.path.join(BASE_PATH, 'Students2.xlsx')
    datas = ExcelUntil.readExcelFile(INPUTFILE1, headerRow=0)
    for sheetname,sheetdatas in datas.items():
        print(sheetdatas.head(8))
        sheetdatas['2016'] = sheetdatas['2016'].astype('int')
        sheetdatas['2017'] = sheetdatas['2017'].astype('int')
        sheetdatas.sort_values(by='2016',ascending=True,inplace=True) # false 从大到小
        bar_width = 0.7
        x_pos = np.arange(len(sheetdatas) * 2, step=2)
        plt.bar(x_pos, sheetdatas['2016'], color='green', width=bar_width)
        plt.bar(x_pos + bar_width, sheetdatas['2017'], color='blue', width=bar_width)
        plt.xticks(x_pos + bar_width / 2, sheetdatas['Field'], rotation='90')
        plt.title('International Student by Field', fontsize=16)
        plt.xlabel('Field')
        plt.ylabel('Number')
        plt.tight_layout()
        plt.show()

def test05():
    INPUTFILE1 = os.path.join(BASE_PATH, 'Students2.xlsx')
    datas = ExcelUntil.readExcelFile(INPUTFILE1, headerRow=0)
    for sheetname,sheetdatas in datas.items():
        print(sheetdatas.head(8))
        sheetdatas['2016'] = sheetdatas['2016'].astype('int')
        sheetdatas['2017'] = sheetdatas['2017'].astype('int')
        sheetdatas.sort_values(by='2017',ascending=False,inplace=True) # false 从大到小
        sheetdatas.plot.bar('Field', ['2016', '2017'], color=['orange', 'Red'])
        plt.title('International Students by Field', fontsize=16)
        plt.xlabel('Field', fontweight='bold')
        plt.ylabel('Number', fontweight='bold')
        ax = plt.gca()
        ax.set_xticklabels(sheetdatas['Field'], rotation=40, ha='right')
        plt.gcf().subplots_adjust(left=0.2, bottom=0.42)
        plt.show()

def test06():
    INPUTFILE1 = os.path.join(BASE_PATH, 'Users.xlsx')
    datas = ExcelUntil.readExcelFile(INPUTFILE1, headerRow=0)
    for sheetname, sheetdatas in datas.items():
        print(sheetdatas.head(8))
        sheetdatas['Oct'] = sheetdatas['Oct'].astype('int')
        sheetdatas['Nov'] = sheetdatas['Nov'].astype('int')
        sheetdatas['Dec'] = sheetdatas['Dec'].astype('int')
        sheetdatas['Total']=sheetdatas['Oct']+sheetdatas['Nov']+sheetdatas['Dec']
        sheetdatas.sort_values(by='Total', ascending=False, inplace=True)  # false 从大到小
        sheetdatas.plot.bar(x='Name',y= ['Oct', 'Nov','Dec'], color=['orange', 'Red','yellow'])
        plt.tight_layout()
        plt.show()

def test07():
    INPUTFILE1 = os.path.join(BASE_PATH, 'Students3.xlsx')
    datas = ExcelUntil.readExcelFile(INPUTFILE1, headerRow=0,indexCol='From')
    for sheetname, sheetdatas in datas.items():
        print(sheetdatas.head(8))
        sheetdatas['2017'] = sheetdatas['2017'].astype('int')
        sheetdatas['2017'].plot.pie(fontsize=8,counterclock=False,startangle=-270)
        plt.title('Source of International Students', fontsize=16, fontweight='bold')
        plt.ylabel('2017',fontsize=12,fontweight='bold')
        plt.show()

def test08():
    INPUTFILE1 = os.path.join(BASE_PATH, 'Orders.xlsx')
    datas = ExcelUntil.readExcelFile(INPUTFILE1, headerRow=0,indexCol='Week')
    for sheetname, sheetdatas in datas.items():
        print(sheetdatas.head(8))
        sheetdatas['Accessories'] = sheetdatas['Accessories'].astype('float')
        sheetdatas['Bikes'] = sheetdatas['Bikes'].astype('float')
        sheetdatas['Clothing'] = sheetdatas['Clothing'].astype('float')
        sheetdatas['Components'] = sheetdatas['Components'].astype('float')
        sheetdatas['Grand Total'] = sheetdatas['Grand Total'].astype('float')
        # sheetdatas.plot(y=['Accessories','Bikes','Clothing','Components'])
        sheetdatas.plot.area(y=['Accessories','Bikes','Clothing','Components'])
        plt.title('Source of International Students', fontsize=16, fontweight='bold')
        plt.xticks(sheetdatas.index,fontsize=12)
        plt.show()


 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值