matplotlib5---设置轴范围limits,标度tick, 刻度符号 tick label, 轴居中

本文只要讲述绘图中轴的相关设置

  1. 设置轴的范围 setting limits
  2. 设置轴的刻度 setting ticks
  3. 设置轴刻度的标记 setting tick labels
  4. 将x,y轴居中
  5. 设置x, y轴的label
x = np.linspace(-np.pi, np.pi, 128,endpoint=True)
cosx,sinx,x_3 = np.cos(x), np.sin(x), x / 3

1. 设置轴的范围

matplotlib.pyplot.xlim(*args, **kwargs)
matplotlib.pyplot.ylim(*args, **kwargs)

参数传递:

  • xlim((xmin, xmax))
  • xlim(xmin, xmax)
  • xlim(xmin=xmin, xmax=xmax)

个人推荐使用axes.set_xlim(), 显然是对于每一个axes设置轴属性,用法与上述相同
在使用关键字参数时,可以只指定一个值,而保持另一个值使用默认值

fig = plt.figure(1)
axes0 = plt.subplot(111)
line1, line2 = axes0.plot(x, cosx, 'w',x, x_3, 'c')

line1.set_linewidth(2.5)
line2.set_linewidth(1)
# plt.xlim(x.min() *2, x.max()*2)
axes0.set_xlim(x.min() *2, x.max()*2)
axes0.set_ylim(cosx.min() * 1.5, cosx.max() * 1.5)
plt.show()

在这里插入图片描述

2. 设置刻度 setting ticks

matplotlib.pyplot.xticks(*args, **kwargs)

matplotlib.pyplot.yticks(*args, **kwargs)

Tick containers

Tick containers

fig = plt.figure(1)
axes0 = plt.subplot(111)
line1
  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值