python--matplotlib--ax.set_xlim,ax.set_ylim、set_xlable,set_ylable,x_tickes,y_tickes,与x_tickelabels,y

按照顺序来:
1、ax.set_xlim,ax.set_ylim
设置x,y轴的最大值的上限

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
x=np.arange(10)
y=x
ax.plot(x,y)
#给x轴,y轴设置最大值的上限变量范围
ax.set_xlim(0,5)
ax.set_ylim(0,6)
plt.show()

结果如下:
在这里插入图片描述
2、set_xlable,set_ylable,设置x轴,y轴的标签,如果使用legend,可以在子图区域添加

import matplotlib.pyplot as plt
#只在一张图上面绘制
fig,ax=plt.subplots()
x=np.linspace(-np.pi,np.pi,256)
c,s=np.cos(x),np.sin(x)
#添加lengend,引用set_ylabel,
ax.plot(x,c)
ax.set_xlabel('cos')
ax.plot(x,s)
ax.set_ylabel('sin')
fig.legend(labels=('cos','sin'))
plt.show()

结果如下:
在这里插入图片描述
3、x_tickes,y_tickes,与x_tickelabels,y_tickelabels
xticks()和yticks()函数使用一个列表对象作为参数
用set_xticklabels([‘内容’])会在x轴下方显示,并会替换掉原来的数字
如下;

import matplotlib.pyplot as plt
#只在一张图上面绘制
fig,ax=plt.subplots()
x=np.linspace(0,np.pi*2,256)
c,s=np.cos(x),np.sin(x)
#添加lengend,引用set_ylabel,
ax.plot(x,c)
#在x轴设置标签
ax.set_xlabel('x轴')
#显示曲线
ax.plot(x,s)
#在y轴设置标签
ax.set_ylabel('y轴')
#x显示x轴下方
#第一步,先取x_tickes的位置
ax.set_xticks([1.4,3.14,6.28])
ax.set_xticklabels(['OEN','π','2π'])
fig.legend(labels=('cos','sin'))

plt.show()

结果如下:

在这里插入图片描述

  • 6
    点赞
  • 53
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值