国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - python繪制條形圖方法代碼詳解

python繪制條形圖方法代碼詳解

2020-12-26 00:37-dragon- Python

這篇文章主要介紹了python繪制條形圖方法代碼詳解,具有一定借鑒價值,需要的朋友可以參考下。

1.首先要繪制一個簡單的條形圖

?
1
2
3
4
5
6
7
8
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import mlab
from matplotlib import rcParams
fig1 = plt.figure(2)
rects =plt.bar(left = (0.2,1),height = (1,0.5),width = 0.2,align="center",yerr=0.000001)
plt.title('Pe')
plt.show()

python繪制條形圖方法代碼詳解

1.1上面中rects=plt.bar(left=(0.2,1),height=(1,0.5),width=0.2,align=”center”,yerr=0.000001)這句代碼是最重要的,其中left表示直方圖的開始的位置(也就是最左邊的地方),height是指直方圖的高度,當直方圖太粗時,可以通過width來定義直方圖的寬度,注意多個直方圖要用元組,yerr這個參數是防止直方圖觸頂。

2.增加直方圖腳注

?
1
2
3
4
5
6
7
8
9
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import mlab
from matplotlib import rcParams
fig1 = plt.figure(2)
rects =plt.bar(left = (0.2,1),height = (1,0.5),width = 0.2,align="center",yerr=0.000001)
plt.title('Pe')
plt.xticks((0.2,1),('frst','second'))
plt.show()

python繪制條形圖方法代碼詳解

3.條形圖上顯示具體的數字(自動編號)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import mlab
from matplotlib import rcParams
fig1 = plt.figure(2)
rects =plt.bar(left = (0.2,1),height = (1,0.5),width = 0.2,align="center",yerr=0.000001)
plt.title('Pe')
def autolabel(rects):
  for rect in rects:
    height = rect.get_height()
    plt.text(rect.get_x()+rect.get_width()/2., 1.03*height, '%s' % float(height))
autolabel(rects)
plt.xticks((0.2,1),('frst','second'))
plt.show()

python繪制條形圖方法代碼詳解

4.改變顏色

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import mlab
from matplotlib import rcParams
fig1 = plt.figure(2)
rects =plt.bar(left = (0.2,1),height = (1,0.5),color=('r','g'),width = 0.2,align="center",yerr=0.000001)
plt.title('Pe')
def autolabel(rects):
  for rect in rects:
    height = rect.get_height()
    plt.text(rect.get_x()+rect.get_width()/2., 1.03*height, '%s' % float(height))
autolabel(rects)
plt.xticks((0.2,1),('frst','second'))
plt.show()

python繪制條形圖方法代碼詳解

5.添加圖注

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import mlab
from matplotlib import rcParams
fig1 = plt.figure(2)
rects1 =plt.bar(left = (0.2),height = (0.5),color=('g'),label=(('no1')),width = 0.2,align="center",yerr=0.000001)
rects2 =plt.bar(left = (1),height = (1),color=('r'),label=(('no2')),width = 0.2,align="center",yerr=0.000001)
plt.legend()
plt.xticks((0.2,1),('frst','second'))
plt.title('Pe')
 
def autolabel(rects):
  for rect in rects:
    height = rect.get_height()
    plt.text(rect.get_x()+rect.get_width()/2., 1.03*height, '%s' % float(height))
autolabel(rects1)
autolabel(rects2)
plt.show()

python繪制條形圖方法代碼詳解

6大家根據自己的需要自己來繪制自己的條形圖

下面回答網友提問,如何畫在條形圖上垂直顯示數據:

下面這個函數是用來垂直顯示的,其中設置角度就可以以任意方式來顯示。

?
1
2
3
4
def autolabel(rects,Num=1.12,rotation1=90,NN=1):
    for rect in rects:
      height = rect.get_height()
      plt.text(rect.get_x()-0.04+rect.get_width()/2., Num*height, '%s' % float(height*NN),rotation=rotation1)

調用方式如下

?
1
2
rects1 =plt.bar(left = (0.05),height = (Pe_FH),color=('b'),label=('FHMM'),width = 0.1,align="center",yerr=0.000001);
autolabel(rects1,1.09);

下面是效果圖

python繪制條形圖方法代碼詳解

總結

以上就是本文關于python繪制條形圖方法代碼詳解的全部內容,希望對大家有所幫助。如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!

原文鏈接:http://blog.csdn.net/yywan1314520/article/details/50818471

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 久久久中文字幕 | 中文在线a在线 | 国产欧美精品一区二区三区 | 色综合天天综合网国产成人网 | 久久精彩 | 精品久久国产老人久久综合 | 日韩在线视频免费观看 | 在线欧美 | 久久久免费视频播放 | 国产欧美日韩在线观看 | 成人午夜在线 | 久久99视频 | 国产精品乱码一区二区三区 | 亚洲黄色成人 | 伊人天堂在线 | 欧美成人毛片 | 欧美国产日韩在线 | 日日夜夜草草 | 亚洲激情久久 | 久久影院免费观看 | 免费一区二区 | 老师的朋友2 | 99精品视频在线 | 91久色| 一区二区视频在线 | 久久av资源 | 国产精品久久久久久久久久久久久 | 视频1区 | 国产综合在线视频 | 欧美高清免费 | 曰韩在线 | 欧美日韩一区二区电影 | 亚洲天堂中文字幕在线观看 | 久久不卡 | 国产激情| 国产精品不卡一区二区三区 | 欧美1级| 91超碰在线观看 | 亚洲午夜成激人情在线影院 | 国产一区二区免费 | 国产高潮久久 |