Python数据分析 2.Matplotlib绘图—常用统计图
1.绘制散点图
from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font = font_manager. FontProperties( fname = "C:/Windows/Fonts/simhei.ttf" )
y_3 = [ 6 , 20 , 7 , 13 , 8 , 14 , 6 , 17 , 6 , 7 , 9 , 8 , 20 , 19 , 17 , 13 , 17 , 10 , 12 , 12 ]
y_10 = [ 25 , 26 , 30 , 26 , 13 , 27 , 15 , 22 , 23 , 28 , 20 , 22 , 28 , 12 , 21 , 29 , 14 , 21 , 15 , 26 ]
x_3 = range ( 1 , 21 )
x_10 = range ( 31 , 51 )
plt. figure( figsize= ( 20 , 8 ) , dpi= 80 )
plt. scatter( x_3, y_3, label= "3月份" )
plt. scatter( x_10, y_10, label= "10月份" )
_x = list ( x_3) + list ( x_10)
_xtick_labels = [ "3月{}日" . format ( i) for i in range ( 1 , 21 ) ]
_xtick_labels += [ "10月{}日" . format ( i) for i in range ( 1 , 21 ) ]
plt. xticks( _x[ : : 2 ] , _xtick_labels[ : : 2 ] , fontproperties = my_font, rotation = 45 )
plt. xlabel( "时间" , fontproperties = my_font)
plt. xlabel( "温度" , fontproperties = my_font)
plt. title( "3月与10月温度比较" , fontproperties = my_font, size = 20 )
plt. legend( loc= "upper left" , prop= my_font)
2.绘制条形图
from matplotlib import pyplot as plt
from matplotlib import font_manager
my_font = font_manager. FontProperties( fname = "C:/Windows/Fonts/simhei.ttf" )
a = [ "战狼2" , "速度与激情8" , "功夫瑜伽" , "西游伏妖篇" , "变形金刚5:\n最后的骑士" , "摔跤吧!爸爸" , "加勒比海盗5:\n死无对证" , "金刚:骷髅岛" , "极限特工:\n终极回归" , "生化危机6:\n终章" , "乘风破浪