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

11 篇文章 0 订阅
1 篇文章 0 订阅

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子区域之间的间距

  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 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值