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

python繪制堆疊條形圖介紹

 更新時(shí)間:2021年12月19日 15:34:06   作者:lingan_Hong  
大家好,本篇文章主要講的是python繪制堆疊條形圖介紹,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽

目前在網(wǎng)絡(luò)上多是單個(gè)條形圖堆疊,沒(méi)看到一組的條形圖堆疊。
代碼如下:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

導(dǎo)入一組自己造的數(shù)據(jù)

data  = pd.read_excel('data.xlsx')
In [4]: data
Out[4]:

在這里插入圖片描述

多使用幾個(gè)plt.bar()函數(shù),就可以畫(huà)出來(lái)啦。。。

tick_label = list(data.columns)
tick_label.remove(‘類別')
x = np.arange(len(tick_label))

y1 = data.iloc[2,1:].values.tolist() #收入(剔除自己轉(zhuǎn)入)
y2 = data.iloc[3,1:].values.tolist() #支出(剔除自己轉(zhuǎn)入)
y3 = data.iloc[4,1:].values.tolist() #收入(自己轉(zhuǎn)入)
y4 = data.iloc[5,1:].values.tolist() #支出(自己轉(zhuǎn)入)
bar_with = 0.25 #柱體寬度plt.figure(figsize = (12,6)) #畫(huà)布大小
plt.bar(x, y1, width = bar_with, #柱體寬度
align = ‘center', #x軸上的坐標(biāo)與柱體對(duì)其的位置
color = ‘orangered', alpha = 0.6, #柱體透明度
label = ‘收入(剔除自己轉(zhuǎn)入)')
plt.bar(x,y3,width = bar_with, bottom = y1, #柱體基線的y軸坐標(biāo)
align = ‘center', color = ‘lightsalmon', alpha = 0.6, label = ‘收入(自己轉(zhuǎn)入)')
plt.bar(x + bar_with, y2, width = bar_with,
align = ‘center', color = ‘deepskyblue', alpha = 0.6, label = ‘支出(剔除自己轉(zhuǎn)入)')
plt.bar(x + bar_with, y4, width = bar_with, bottom = y2,
align = ‘center', color = ‘lightskyblue', alpha = 0.6, label = ‘支出(自己轉(zhuǎn)入)')
plt.title(‘月度收支表', fontsize = 10) #設(shè)置x軸標(biāo)題
plt.xticks(x + bar_with/2, tick_label, rotation = 70) #設(shè)置x軸坐標(biāo)
plt.xlabel(‘時(shí)間',fontsize = 8, verticalalignment = ‘top', horizontalalignment=‘right',rotation=‘horizontal')
plt.xlabel(‘時(shí)間',fontsize = 8, verticalalignment = ‘bottom', horizontalalignment=‘center')

#圖例設(shè)在圖形外面,控制坐標(biāo)參數(shù)
plt.legend(loc = ‘center', bbox_to_anchor = (0.77, 1.1), ncol=2)
plt.savefig(‘draw_bar.png', dpi=200, bbox_inches = ‘tight')
plt.close()

繪制如圖:

在這里插入圖片描述

是不是其實(shí)plt繪圖也沒(méi)有哪么辣眼睛了。。。

到此這篇關(guān)于python繪制堆疊條形圖介紹的文章就介紹到這了,更多相關(guān)python堆疊條形圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

芒康县| 静乐县| 镇坪县| 桐庐县| 米泉市| 合作市| 巴彦县| 安化县| 南京市| 通州区| 通化市| 韶山市| 谢通门县| 天峨县| 新疆| 噶尔县| 千阳县| 龙岩市| 南平市| 临西县| 凤台县| 资兴市| 荣成市| 曲阳县| 汾西县| 大理市| 庆元县| 广元市| 云霄县| 元氏县| 哈密市| 万山特区| 永定县| 遵化市| 新龙县| 台北县| 鄄城县| 重庆市| 皮山县| 柳林县| 阜南县|