900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > Python绘图(一):坐标轴刻度及范围设置

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

时间:2019-09-28 16:59:55

相关推荐

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)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。