【20170707】雙坐標軸畫法和更改坐標軸刻度

# -*- coding: utf-8 -*-nn"""nnCreated on 2017/6/26nn讀取EXCEL中的數據nn@author: gaodannn"""nnimport numpy as npnfrom pandas import Series,DataFramenimport pandas as pdnimport xlrdnimport openpyxlnimport matplotlib.pyplot as pltnimport osnnplt.rcParams[font.sans-serif]=[SimHei] #用來正常顯示中文標籤nplt.rcParams[axes.unicode_minus]=False #用來正常顯示負號nnxls_file = pd.ExcelFile(慧網全年業績匯總表.xlsx)#選中EXCEL表nntable = xls_file.parse(貸款端明細)#選中某個SHEETnnframe = DataFrame(table) #把導入的EXCEL轉化為哦DataFramenn#print(frame)nnx1 = frame[審批借款金額].groupby([frame[月份],frame[案件標誌]]).sum()#處理數據nn#print(x1)nnx2 = x1.drop([審核中,待簽約])#繼續處理數據nn#print(x2)nnx3 = x2.unstack()#繼續處理數據nnx = x3/10000#除以10000,把單位變成萬元nny1 = x[展期件]ny2 = x[新進件]ny = y1 / (y1 + y2)ny = [float(i) for i in y]n#print(x)nprint(y1,y2,y)nnfig = plt.figure()#創建一個地盤nnax1 = fig.add_subplot(1,1,1)#畫一個框框nnx.plot(ax=ax1,kind = bar,stacked = True,alpha = 0.7,label = left)#畫圖,這邊有一個很重要的點,ax=某某某是可以n#限定圖畫在哪裡的,所以ax=ax 即限定圖畫在我剛剛畫的框框裡面nnax1.set_title(2017上半年貸款端業績) #標題名字(標題名字是跟著框框走的)nnax2 = ax1.twinx()#設置雙坐標軸nnax2.set_ylim([0, 0.5])#設置右邊的坐標軸的範圍nnax2.plot(y,ro-,label = right)nnplt.show()


推薦閱讀:

用Python編寫JSON解析器的概述
構建PyQt5.8/Python2.7
量化策略系列教程:04阿爾法策略
python與numpy使用的一些小tips(3)

TAG:Python入门 | Matplotlib | Python |