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字样的参数名及value
list=[(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子区域之间的间距
fig.tight_layout()
自动排版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 figure
right = 0.9 # the right side of the subplots of the figure
bottom = 0.1 # the bottom of the subplots of the figure
top = 0.9 # the top of the subplots of the figure
wspace = 0.2 # the amount of width reserved for blank space between subplots
hspace = 0.2 # the amount of height reserved for white space between subplots
设置坐标轴范围
#方法1
plt.axis([x_start,x_end,y_start,y_end])
#方法2
table.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,不包含2020
xticks=range(1880,2021,10) #需要2020时→2020+1