📄 table_demo.py
字号:
#!/usr/bin/env pythonimport matplotlibfrom pylab import *from colours import get_coloursaxes([0.2, 0.2, 0.7, 0.6]) # leave room below the axes for the tabledata = [[ 66386, 174296, 75131, 577908, 32015], [ 58230, 381139, 78045, 99308, 160454], [ 89135, 80552, 152558, 497981, 603535], [ 78415, 81858, 150656, 193263, 69638], [ 139361, 331509, 343164, 781380, 52269]]colLabels = ('Freeze', 'Wind', 'Flood', 'Quake', 'Hail')rowLabels = ['%d year' % x for x in (100, 50, 20, 10, 5)]# Get some pastel shades for the colourscolours = get_colours(len(colLabels))colours.reverse()rows = len(data)ind = arange(len(colLabels)) + 0.3 # the x locations for the groupscellText = []width = 0.4 # the width of the barsyoff = array([0.0] * len(colLabels)) # the bottom values for stacked bar chartfor row in xrange(rows): bar(ind, data[row], width, bottom=yoff, color=colours[row]) yoff = yoff + data[row] cellText.append(['%1.1f' % (x/1000.0) for x in yoff])# Add a table at the bottom of the axescolours.reverse()cellText.reverse()the_table = table(cellText=cellText, rowLabels=rowLabels, rowColours=colours, colLabels=colLabels, loc='bottom')ylabel("Loss $1000's")vals = arange(0, 2500, 500)yticks(vals*1000, ['%d' % val for val in vals])xticks([])title('Loss by Disaster')#savefig('table_demo_small', dpi=75)#savefig('table_demo_large', dpi=300)show()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -