matplotlib lim ticks 设置xy轴的刻度和范围
【摘要】 所属的课程名称及链接[AI基础课程--常用框架工具]环境信息* ModelArts * Notebook - Multi-Engine 2.0 (python3) * JupyterLab - Notebook - Conda-python3 * matplotlib 2.1.0matplotlib lim ticks 设置xy轴的刻度和范围import numpy as ...
所属的课程名称及链接
环境信息
- * ModelArts
- * Notebook - Multi-Engine 2.0 (python3)
- * JupyterLab - Notebook - Conda-python3
- * matplotlib 2.1.0
- * JupyterLab - Notebook - Conda-python3
- * Notebook - Multi-Engine 2.0 (python3)
matplotlib lim ticks 设置xy轴的刻度和范围
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-np.pi,np.pi,256,endpoint=True)
y = np.sin(x)
plt.plot(x,y,color="red",linestyle="-.")
plt.xlim(-np.pi,np.pi) # x轴范围
plt.xticks(np.linspace(-np.pi,np.pi,5,endpoint=True)) # x轴的刻度
plt.ylim(-1.0,1.0) # y轴范围
plt.yticks(np.linspace(-1,1,4,endpoint=True)) # y轴的刻度
plt.show()
help
help(plt.xlim)
Help on function xlim in module matplotlib.pyplot:
xlim(*args, **kwargs)
Get or set the *x* limits of the current axes.
::
xmin, xmax = xlim() # return the current xlim
xlim( (xmin, xmax) ) # set the xlim to xmin, xmax
xlim( xmin, xmax ) # set the xlim to xmin, xmax
If you do not specify args, you can pass the xmin and xmax as
kwargs, e.g.::
xlim(xmax=3) # adjust the max leaving min unchanged
xlim(xmin=1) # adjust the min leaving max unchanged
Setting limits turns autoscaling off for the x-axis.
The new axis limits are returned as a length 2 tuple.
help(plt.xticks)
Help on function xticks in module matplotlib.pyplot:
xticks(*args, **kwargs)
Get or set the *x*-limits of the current tick locations and labels.
::
# return locs, labels where locs is an array of tick locations and
# labels is an array of tick labels.
locs, labels = xticks()
# set the locations of the xticks
xticks( arange(6) )
# set the locations and labels of the xticks
xticks( arange(5), ('Tom', 'Dick', 'Harry', 'Sally', 'Sue') )
The keyword args, if any, are :class:`~matplotlib.text.Text`
properties. For example, to rotate long labels::
xticks( arange(12), calendar.month_name[1:13], rotation=17 )
备注
1. 感谢老师的教学与课件
2. 欢迎各位同学一起来交流学习心得^_^
3. 沙箱实验、认证、论坛和直播,其中包含了许多优质的内容,推荐了解与学习。
2. 欢迎各位同学一起来交流学习心得^_^
3. 沙箱实验、认证、论坛和直播,其中包含了许多优质的内容,推荐了解与学习。
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)