Python绘图(一):坐标轴刻度及范围设置

python绘图一般使用matplotlib、pandas等,本示例使用matplotlib进行简单的python绘图的坐标轴设置

1 定义坐标轴字体
plt.rc('font',family='Times New Roman')
2 设置坐标轴刻度字号
plt.xticks(fontsize=14) 
plt.yticks(fontsize=14)
3 设置坐标轴显示范围
plt.xlim(0,1000)
plt.ylim(-3000,-400)
4 设置坐标轴线粗细
ax=plt.gca();#获得坐标轴的句柄
ax.spines['bottom'].set_linewidth(1);###设置底部坐标轴的粗细
ax.spines['left'].set_linewidth(1);####设置左边坐标轴的粗细
5 设置坐标轴标签
#front是标签属性:包括字体、大小等
font = {'family' : 'Times New Roman',
'weight' : 'normal',
'size'   : 18,
}
plt.xlabel("Episode",font)         
plt.ylabel(r"Average Reward",font) 
6 设置坐标轴科学计数法表示
plt.ticklabel_format(axis="y", style="sci", scilimits=(0,0))
7 设置坐标轴以固定间隔显示刻度
x_major_locator=MultipleLocator(15)#以每15显示
y_major_locator=MultipleLocator(3)#以每3显示
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
ax.yaxis.set_major_locator(y_major_locator)
  • 95
    点赞
  • 630
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

人生不过一闭一睁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值