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

python繪制柱形圖的方法

 更新時(shí)間:2022年04月21日 12:02:04   作者:Wayne0926  
這篇文章主要為大家詳細(xì)介紹了python繪制柱形圖的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了python繪制柱形圖的具體代碼,供大家參考,具體內(nèi)容如下

#柱形圖
import pandas
import numpy
import matplotlib?
from matplotlib import pyplot as plt
#導(dǎo)入數(shù)據(jù)
data_columns=pandas.read_csv('D://Python projects//reference data//6.4//data.csv')
#定義中文格式
font={'family':'MicroSoft Yahei',
? ? ? 'weight':'bold',
? ? ? 'size':12}
matplotlib.rc('font',**font)
#使用手機(jī)品牌作為分組列,月消費(fèi)作為統(tǒng)計(jì)列
result_columns=data_columns.groupby(
? ? ? ? by=['手機(jī)品牌'],
? ? ? ? as_index=False)['月消費(fèi)(元)'
? ? ? ? ? ? ? ? ? ? ? ].agg({'月總消費(fèi)':numpy.sum
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? })
#生成一個(gè)間隔為1的序列
index=numpy.arange(result_columns.月總消費(fèi).size)
#繪制縱向柱形圖
plt.bar(index,result_columns['月總消費(fèi)'])
#%matplotlib qt
plt.show()
#配置顏色
maincolor=(42/256,87/256,141/256,1)
plt.bar(index,
? ? ? ? result_columns['月總消費(fèi)'])
plt.show()
#配置X軸標(biāo)簽
plt.bar(index,
? ? ? ? result_columns['月總消費(fèi)'])
plt.xticks(index,result_columns.手機(jī)品牌)
plt.show()
#對(duì)數(shù)據(jù)進(jìn)行降序排序后展示
result_asd=result_columns.sort_values(
? ? ? ? by='月總消費(fèi)',
? ? ? ? ascending=False)
plt.bar(index,
? ? ? ? result_asd.月總消費(fèi),
? ? ? ? color=maincolor)
plt.xticks(index,result_asd.手機(jī)品牌)
plt.show()

結(jié)果為:

#橫向柱形圖
result_asd=result_columns.sort_values(
? ? ? ? by='月總消費(fèi)',
? ? ? ? ascending=False)
plt.barh(index,
? ? ? ? result_asd.月總消費(fèi),
? ? ? ? color=maincolor)
plt.yticks(index,result_asd.手機(jī)品牌)
plt.show()

結(jié)果為:

#計(jì)算出交叉表的數(shù)據(jù)
result=data_columns.pivot_table(
? ? ? ? values='月消費(fèi)(元)',
? ? ? ? index='手機(jī)品牌',
? ? ? ? columns='通信品牌',
? ? ? ? aggfunc=numpy.sum)

結(jié)果為:

#定義三個(gè)顏色
index=numpy.arange(len(result))
mincolor=(42/256,87/256,141/256,1/3)
midcolor=(42/256,87/256,141/256,2/3)
maxcolor=(42/256,87/256,141/256,1)
#建立簇狀柱形圖
plt.bar(
? ? ? ? index,
? ? ? ? result['全球通'],
? ? ? ? color=mincolor,
? ? ? ? width=1/4)
plt.bar(
? ? ? ? index+1/4,
? ? ? ? result['動(dòng)感地帶'],
? ? ? ? color=midcolor,
? ? ? ? width=1/4)
plt.bar(
? ? ? ? index+1/2,
? ? ? ? result['神州行'],
? ? ? ? color=maxcolor,
? ? ? ? width=1/4)
plt.xticks(index+1/3,result.index)
#添加圖例
plt.legend(['全球通','動(dòng)感地帶','神州行'])
plt.show()

結(jié)果為:

#重新排序進(jìn)行繪制
result=result.sort_values(
? ? ? ? by='神州行',
? ? ? ? ascending=False)
plt.bar(
? ? ? ? index,
? ? ? ? result['全球通'],
? ? ? ? color=mincolor,
? ? ? ? width=1/4)
plt.bar(
? ? ? ? index+1/4,
? ? ? ? result['動(dòng)感地帶'],
? ? ? ? color=midcolor,
? ? ? ? width=1/4)
plt.bar(
? ? ? ? index+1/2,
? ? ? ? result['神州行'],
? ? ? ? color=maxcolor,
? ? ? ? width=1/4)
plt.xticks(index+1/3,result.index)
plt.legend(['全球通','動(dòng)感地帶','神州行'])
plt.show()

結(jié)果為:

#繪制堆疊柱形圖
result=result.sort_values(
? ? ? ? by='神州行',
? ? ? ? ascending=False)
plt.bar(
? ? ? ? index,
? ? ? ? result['全球通'],
? ? ? ? color=maxcolor)
plt.bar(
? ? ? ? index,
? ? ? ? result['動(dòng)感地帶'],
? ? ? ? bottom=result['全球通'],
? ? ? ? color=midcolor)
plt.bar(
? ? ? ? index,
? ? ? ? result['神州行'],
? ? ? ? bottom=result['全球通']+result['動(dòng)感地帶'],
? ? ? ? color=mincolor)
plt.xticks(index,result.index)
plt.legend(['全球通','動(dòng)感地帶','神州行'])
plt.show()

結(jié)果為:

#繪制雙向柱形圖
plt.barh(
? ? ? ? index,
? ? ? ? result['神州行'],
? ? ? ? color=midcolor)
plt.barh(
? ? ? ? index,
? ? ? ? -result['動(dòng)感地帶'],
? ? ? ? color=maxcolor)
plt.yticks(index,
? ? ? ? ? ?result.index)
plt.legend(['動(dòng)感地帶','神州行'])
plt.show()

結(jié)果為:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python實(shí)現(xiàn)的本地文件搜索功能示例【測(cè)試可用】

    Python實(shí)現(xiàn)的本地文件搜索功能示例【測(cè)試可用】

    這篇文章主要介紹了Python實(shí)現(xiàn)的本地文件搜索功能,涉及Python針對(duì)文件與目錄的遍歷、判斷、編碼轉(zhuǎn)換、查找等相關(guān)操作技巧,需要的朋友可以參考下
    2018-05-05
  • python的程序分支結(jié)構(gòu)用法及說(shuō)明

    python的程序分支結(jié)構(gòu)用法及說(shuō)明

    這篇文章主要介紹了python的程序分支結(jié)構(gòu)用法及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • 深入理解python對(duì)json的操作總結(jié)

    深入理解python對(duì)json的操作總結(jié)

    Json最廣泛的應(yīng)用是作為AJAX中web服務(wù)器和客戶端的通訊的數(shù)據(jù)格式,本篇文章主要介紹了python對(duì)json的操作總結(jié),具有一定的參考價(jià)值,有興趣的可以了解一下。
    2017-01-01
  • 使用PyTorch實(shí)現(xiàn)MNIST手寫體識(shí)別代碼

    使用PyTorch實(shí)現(xiàn)MNIST手寫體識(shí)別代碼

    今天小編就為大家分享一篇使用PyTorch實(shí)現(xiàn)MNIST手寫體識(shí)別代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-01-01
  • python實(shí)現(xiàn)掃描日志關(guān)鍵字的示例

    python實(shí)現(xiàn)掃描日志關(guān)鍵字的示例

    下面小編就為大家分享一篇python實(shí)現(xiàn)掃描日志關(guān)鍵字的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-04-04
  • Django中幾種重定向方法

    Django中幾種重定向方法

    這篇文章主要介紹了Django中幾種重定向方法,本文講解了使用HttpResponseRedirect、redirect、reverse以及配置文件中配置URL等方法,需要的朋友可以參考下
    2015-04-04
  • Python多線程threading模塊實(shí)例詳解

    Python多線程threading模塊實(shí)例詳解

    這篇文章主要介紹了Python多線程threading模塊,對(duì)于一個(gè)python程序,如果需要同時(shí)大量處理多個(gè)任務(wù),有使用多進(jìn)程和多線程兩種方法,在python中,實(shí)現(xiàn)多線程主要通過(guò)threading模塊,需要的朋友可以參考下
    2025-04-04
  • Python實(shí)現(xiàn)比較兩個(gè)文件夾中代碼變化的方法

    Python實(shí)現(xiàn)比較兩個(gè)文件夾中代碼變化的方法

    這篇文章主要介紹了Python實(shí)現(xiàn)比較兩個(gè)文件夾中代碼變化的方法,實(shí)例分析了Python讀取文件夾中文件及字符串操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-07-07
  • Jupyter Notebook 實(shí)現(xiàn)正常顯示中文和負(fù)號(hào)

    Jupyter Notebook 實(shí)現(xiàn)正常顯示中文和負(fù)號(hào)

    這篇文章主要介紹了Jupyter Notebook 實(shí)現(xiàn)正常顯示中文和負(fù)號(hào),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-04-04
  • Python中easy_install 和 pip 的安裝及使用

    Python中easy_install 和 pip 的安裝及使用

    本篇文章主要介紹了Python中easy_install 和 pip 的安裝及使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06

最新評(píng)論

出国| 龙口市| 宜兴市| 萨嘎县| 北京市| 西华县| 景谷| 丁青县| 雅江县| 宜良县| 滨州市| 阜康市| 青龙| 固阳县| 房山区| 祁阳县| 平湖市| 临泽县| 咸丰县| 大英县| 饶河县| 云梦县| 长武县| 天柱县| 商城县| 怀远县| 汝州市| 高台县| 新密市| 渑池县| 通江县| 芜湖县| 长沙市| 铁岭市| 湟源县| 陇南市| 黄浦区| 巩留县| 色达县| 宣汉县| 九江市|