最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實(shí)現(xiàn)雙軸組合圖表柱狀圖和折線圖的具體流程

 更新時(shí)間:2021年08月26日 14:56:42   作者:bellin124  
這篇文章主要介紹了Python雙軸組合圖表柱狀圖+折線圖,Python繪制雙軸組合的關(guān)鍵在plt庫(kù)的twinx()函數(shù),具體實(shí)例代碼跟隨小編一起看看吧

Python繪制雙軸組合的關(guān)鍵在plt庫(kù)的twinx()函數(shù),具體流程:

1.先建立坐標(biāo)系,然后繪制主坐標(biāo)軸上的圖表;

2.再調(diào)用plt.twinx()方法;

3.最后繪制次坐標(biāo)軸圖表。

import cx_Oracle
import xlrd
import xlwt
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import FuncFormatter

plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
#設(shè)置坐標(biāo)軸數(shù)值以百分比(%)顯示函數(shù)
def to_percent(temp, position):
  return '%1.0f'%(1*temp) + '%'
#字體設(shè)置
font2 = {'family' : 'Times New Roman',
'weight' : 'normal',
'size'   : 25,
}

conn=cx_Oracle.connect('用戶名/密碼@IP:端口/數(shù)據(jù)庫(kù)')
c=conn.cursor()
#sql查詢語(yǔ)句,多行用()括起來(lái)
sql_detail=("select substr(date1,6,10)date1,round(avg(r_qty))r_qty,round(avg(e_qty))e_qty,""round(avg(r_qty)/avg(e_qty),2)*100 userate,round(avg(uptime),2)*100 uptime from 表tp "
"tp where 條件  "
"group by date1 order by date1 ")  
                              
x=c.execute(sql_detail)
#獲取sql查詢數(shù)據(jù)                         
data=x.fetchall()
#print(data)

#新建Excel保存數(shù)據(jù)
xl=xlwt.Workbook()
ws=xl.add_sheet("ROBOT 30 DAYS MOVE ")
#ws.write_merge(0,1,0,4,"ROBOT_30_DAYS_MOVE")
for i,item in enumerate(data):
    for j,val in enumerate(item):
        ws.write(i,j,val)
xl.save("E:\\ROBOT_30_DAYS_MOVE.xls")

#讀取Excel數(shù)據(jù)
data1 = xlrd.open_workbook( "E:\\ROBOT_30_DAYS_MOVE.xls")
sheet1=data1.sheet_by_index(0)

date1=sheet1.col_values(0)
r_qty=sheet1.col_values(1)
e_qty=sheet1.col_values(2)
userate=sheet1.col_values(3)
uptime=sheet1.col_values(4)

#空值處理
for a in r_qty:
    if a=='':
        a=0
for a in e_qty:
    if a=='':
        a=0
for a in userate:
    if a=='':
        a=0
for a in uptime:
    if a=='':
        a=0
#將list元素str轉(zhuǎn)int類型
r_qty = list(map(int, r_qty))
e_qty = list(map(int, e_qty))
userate = list(map(int, userate))
uptime = list(map(int, uptime))
#添加平均值mean求平均
r_qty.append(int(np.mean(r_qty))) 
e_qty.append(int(np.mean(e_qty))) 
userate.append(int(np.mean(userate))) 
uptime.append(int(np.mean(uptime))) 
date1.append('AVG')

#x軸坐標(biāo)
x=np.arange(len(date1))
bar_width=0.35

plt.figure(1,figsize=(19,10))
#繪制主坐標(biāo)軸-柱狀圖
plt.bar(np.arange(len(date1)),r_qty,label='RBT_MOVE',align='center',alpha=0.8,color='Blue',width=bar_width)
plt.bar(np.arange(len(date1))+bar_width,e_qty,label='EQP_MOVE',align='center',alpha=0.8,color='orange',width=bar_width)

#設(shè)置主坐標(biāo)軸參數(shù)
plt.xlabel('')
plt.ylabel('Move',fontsize=18)
plt.legend(loc=1, bbox_to_anchor=(0,0.97),borderaxespad = 0.) 
#plt.legend(loc='upper left')
for x,y in enumerate(r_qty):
    plt.text(x,y+100,'%s' % y,ha='center',va='bottom')
for x,y in enumerate(e_qty):
    plt.text(x+bar_width,y+100,'%s' % y,ha='left',va='top') 
plt.ylim([0,8000])

#調(diào)用plt.twinx()后可繪制次坐標(biāo)軸
plt.twinx()

#次坐標(biāo)軸參考線
target1=[90]*len(date1)
target2=[80]*len(date1)

x=list(range(len(date1)))
plt.xticks(x,date1,rotation=45)

#繪制次坐標(biāo)軸-折線圖
plt.plot(np.arange(len(date1)),userate,label='USE_RATE',color='green',linewidth=1,linestyle='solid',marker='o',markersize=3)
plt.plot(np.arange(len(date1)),uptime,label='UPTIME',color='red',linewidth=1,linestyle='--',marker='o',markersize=3)

plt.plot(np.arange(len(date1)),target1,label='90%target',color='black',linewidth=1,linestyle='dashdot')
plt.plot(np.arange(len(date1)),target2,label='80%target',color='black',linewidth=1,linestyle='dashdot')

#次坐標(biāo)軸刻度百分比顯示
plt.gca().yaxis.set_major_formatter(FuncFormatter(to_percent))

plt.xlabel('')
plt.ylabel('Rate',fontsize=18)
#圖列
plt.legend(loc=2, bbox_to_anchor=(1.01,0.97),borderaxespad = 0.) 
plt.ylim([0,100])
for x,y in enumerate(userate):
    plt.text(x,y-1,'%s' % y,ha='right',va='bottom',fontsize=14)
for x,y in enumerate(uptime):
    plt.text(x,y+1,'%s' % y,ha='left',va='top',fontsize=14) 

plt.title("ROBOT 30 DAYS MOVE")

#圖表Table顯示plt.table()
listdata=[r_qty]+[e_qty]+[userate]+[uptime]#數(shù)據(jù)
table_row=['RBT_MOVE','EQP_MOVE','USE_RATE(%)','UPTIME(%)']#行標(biāo)簽
table_col=date1#列標(biāo)簽
print(listdata)
print(table_row)
print(table_col)

the_table=plt.table(cellText=listdata,cellLoc='center',rowLabels=table_row,colLabels=table_col,rowLoc='center',colLoc='center')
#Table參數(shù)設(shè)置-字體大小太小,自己設(shè)置
the_table.auto_set_font_size(False)
the_table.set_fontsize(12)
#Table參數(shù)設(shè)置-改變表內(nèi)字體顯示比例,沒有會(huì)溢出到表格線外面
the_table.scale(1,3)
#plt.show()

plt.savefig(r"E:\\ROBOT_30_DAYS_MOVE.png",bbox_inches='tight')
#關(guān)閉SQL連接
c.close()                                                      
conn.close()

結(jié)果顯示:

到此這篇關(guān)于Python實(shí)現(xiàn)雙軸組合圖表柱狀圖和折線圖的具體流程的文章就介紹到這了,更多相關(guān)python柱狀圖和折線圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python中open函數(shù)對(duì)文件處理的使用教程

    python中open函數(shù)對(duì)文件處理的使用教程

    open()函數(shù)的作用是打開一個(gè)文件,并返回一個(gè)file對(duì)象(即文件對(duì)象),下面這篇文章主要給大家介紹了關(guān)于python中open函數(shù)對(duì)文件處理的相關(guān)資料,需要的朋友可以參考下
    2022-06-06
  • python調(diào)用cmd命令行制作刷博器

    python調(diào)用cmd命令行制作刷博器

    這篇文章主要介紹了Python制作一個(gè)簡(jiǎn)單的刷博器,可以學(xué)習(xí)Python線程、調(diào)用cmd命令行、打開網(wǎng)頁(yè)的知識(shí)點(diǎn),大家參考使用吧
    2014-01-01
  • python選擇排序算法的實(shí)現(xiàn)代碼

    python選擇排序算法的實(shí)現(xiàn)代碼

    這篇文章主要介紹了python選擇排序算法的實(shí)現(xiàn)代碼,大家參考
    2013-11-11
  • Python使用xlrd實(shí)現(xiàn)讀取合并單元格

    Python使用xlrd實(shí)現(xiàn)讀取合并單元格

    這篇文章主要介紹了Python使用xlrd實(shí)現(xiàn)讀取合并單元格,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-07-07
  • Python中語(yǔ)音轉(zhuǎn)文字相關(guān)庫(kù)介紹(最新推薦)

    Python中語(yǔ)音轉(zhuǎn)文字相關(guān)庫(kù)介紹(最新推薦)

    Python的speech_recognition庫(kù)是一個(gè)用于語(yǔ)音識(shí)別的Python包,它可以使Python程序能夠識(shí)別和翻譯來(lái)自麥克風(fēng)、音頻文件或網(wǎng)絡(luò)流的語(yǔ)音,這篇文章主要介紹了Python中語(yǔ)音轉(zhuǎn)文字相關(guān)庫(kù)介紹,需要的朋友可以參考下
    2023-05-05
  • python裝飾器相當(dāng)于函數(shù)的調(diào)用方式

    python裝飾器相當(dāng)于函數(shù)的調(diào)用方式

    今天小編就為大家分享一篇python裝飾器相當(dāng)于函數(shù)的調(diào)用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-12-12
  • 深度Q網(wǎng)絡(luò)DQN(Deep Q-Network)強(qiáng)化學(xué)習(xí)的原理與實(shí)戰(zhàn)

    深度Q網(wǎng)絡(luò)DQN(Deep Q-Network)強(qiáng)化學(xué)習(xí)的原理與實(shí)戰(zhàn)

    深度Q學(xué)習(xí)將深度神經(jīng)網(wǎng)絡(luò)與強(qiáng)化學(xué)習(xí)相結(jié)合,解決了傳統(tǒng)Q學(xué)習(xí)在高維狀態(tài)空間下的局限性,通過(guò)經(jīng)驗(yàn)回放和目標(biāo)網(wǎng)絡(luò)等技術(shù),DQN能夠在復(fù)雜環(huán)境中學(xué)習(xí)有效的策略,本文通過(guò)CartPole環(huán)境的完整實(shí)現(xiàn),展示了DQN的核心思想和實(shí)現(xiàn)細(xì)節(jié)
    2025-04-04
  • Python簡(jiǎn)單實(shí)現(xiàn)阿拉伯?dāng)?shù)字和羅馬數(shù)字的互相轉(zhuǎn)換功能示例

    Python簡(jiǎn)單實(shí)現(xiàn)阿拉伯?dāng)?shù)字和羅馬數(shù)字的互相轉(zhuǎn)換功能示例

    這篇文章主要介紹了Python簡(jiǎn)單實(shí)現(xiàn)阿拉伯?dāng)?shù)字和羅馬數(shù)字的互相轉(zhuǎn)換功能,涉及Python針對(duì)字符串與列表的遍歷、運(yùn)算等相關(guān)操作技巧,需要的朋友可以參考下
    2018-04-04
  • python中的hashlib模塊使用實(shí)例

    python中的hashlib模塊使用實(shí)例

    這篇文章主要介紹了python中的hashlib模塊使用實(shí)例,hashlib是一個(gè)提供字符串加密功能的模塊,包含MD5和SHA的算法,MD5和SHA是摘要算法,文中以實(shí)例代碼講解hashlib模塊的基本用法,需要的朋友可以參考下
    2023-08-08
  • django 開發(fā)忘記密碼通過(guò)郵箱找回功能示例

    django 開發(fā)忘記密碼通過(guò)郵箱找回功能示例

    這篇文章主要介紹了django 開發(fā)忘記密碼通過(guò)郵箱找回功能示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-04-04

最新評(píng)論

泰州市| 磴口县| 西峡县| 普定县| 固阳县| 聊城市| 阿图什市| 潮安县| 高碑店市| 海晏县| 彭水| 商洛市| 富民县| 礼泉县| 台南市| 太保市| 衡阳市| 梧州市| 英山县| 廊坊市| 綦江县| 奉新县| 金山区| 西乡县| 谷城县| 卢湾区| 泰安市| 沛县| 枣阳市| 监利县| 威信县| 武平县| 彭山县| 柘荣县| 普洱| 格尔木市| 中山市| 繁昌县| 南安市| 上饶县| 麻城市|