一、柱狀圖
matplotlib.pyplot.bar(x, height, width=0.8, bottom=None, *, align=‘center’, data=None, **kwargs)
1、主要引數:
x: 柱形x的坐標,一般可采用arange函式產生一個序列
height: 柱形的高度,即需要展示的資料
width: 柱形的寬度,默認值0.8
bottom: 柱形基座的y坐標,默認值0
align: 橫坐標數字在柱形的位置,可選{‘center’, ‘edge’},默認: ‘center’,若想標在右邊,則可以通過width=負值,align=‘edge’實作
2、其他引數:
alpha: 透明度,數值為 float 型別或者默認
color/facecolor: 柱形顏色
label: 每個柱形圖代表的含義,要加陳述句:plt.legend(loc=“upper left”) 才能顯示label
附:matplotlib.pyplot.bar官方檔案
二、添加資料標簽
matplotlib.pyplot.text(x, y, s, fontdict=None, withdash=False, **kwargs)
1、主要引數:
x、y: 放置文本的位置,默認情況下,這是資料坐標,
s: str型別,文本內容
2、其他引數:
horizontalalignment: 水平對齊,ha={‘center’…}
verticalalignment: 垂直對齊,va={‘center’,‘bottom’…}
fontsize: 字體大小
附:matplotlib.pyplot.text官方檔案
三、例子
法1:
plt.bar(X, Y, width=0.5)
for x, y in zip(X, Y): # 在直方圖上方標注資料
plt.text(x, 1.03*y, '%s' % float(y), ha='center')
法2:
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))
rect = plt.bar(left = (0, 1), height = (1, 0.5), width = 0.2, align="center")
autolabel(rect)
四、python中字串list轉為數值型
? 如:recordNum=[‘1’, ‘2’],將recordNum中資料轉為int型別并存進串列
Num = list(map(int, recordNum))
五、Python 操作 MySQL 資料庫
? Python操作MySQL資料庫官方檔案
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/252687.html
標籤:python
上一篇:【Python】給PDF添加水印
