Python Matplotlib(一)——绘图区域设置

来源:互联网 发布:称重收银软件免费 编辑:程序博客网 时间:2024/05/14 09:32

Figure对象全局参数设置

from matplotlib import rcParams# rcParams['axes.edgecolor']='white'# rcParams['xtick.color']='black'# rcParams['ytick.color']='black'# rcParams['axes.labelcolor']='black'# rcParams['text.color']='black'# rcParams['figure.edgecolor']=(1, 1, 1, 1)rcParams['figure.facecolor']=(1, 1, 1, 1)rcParams['font.family']='simhei'rcParams['font.size']=13#获取全部带font字样的参数名及valuelist=[(param, value) for param, value in plt.rcParams.items() if 'font' in param]

子区域绘图

subplots方法

#返回Figure对象、子区域对象组成的list对象fig,axes=plt.subplots(2,1,figsize=(10,8))#在各个子区域绘图:ax=axes[i]letter_prop['M'].plot(kind='bar',rot=0,ax=axes[0],title='Male')letter_prop['F'].plot(kind='bar',rot=0,ax=axes[1],title='Female',legend=False)

调整subplots子区域之间的间距

  1. fig.tight_layout()
    自动排版

  2. subplots_adjust
    精确设置间距

plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None)<br>left  = 0.125  # the left side of the subplots of the figureright = 0.9    # the right side of the subplots of the figurebottom = 0.1   # the bottom of the subplots of the figuretop = 0.9      # the top of the subplots of the figurewspace = 0.2   # the amount of width reserved for blank space between subplotshspace = 0.2   # the amount of height reserved for white space between subplots

设置坐标轴范围

#方法1plt.axis([x_start,x_end,y_start,y_end])#方法2table.plot(yticks=np.linspace(0.4,1.2,9),xticks=range(1880,2020,10),figsize=(10,8))   #xticks需要传入一个list#range函数xticks=range(1880,2020,10)  #step=10,不包含2020xticks=range(1880,2021,10)  #需要2020时→2020+1
原创粉丝点击