【Matplotlib】线设置,坐标显示范围
2016-12-01 13:56
639 查看
【Matplotlib】线设置,坐标显示范围
改变线的颜色和线宽参考文章:
controlling line properties
Line API
线有很多属性你可以设置:线宽,线型,抗锯齿等等;具体请参考matplotlib.lines.Line2D
有以下几种方式可以设置线的属性
使用关键字参数
plt.plot(x, y, linewidth=2.0)
使用 Line2D 对象的设置方法。 plot 返回一个 Line2D 对象的列表; line1, line2 = plot(x1, y1, x2, y2)。 下面的代码中我们假定图中仅有一条线以使返回的列表的长度为1。我们使用
line,进行元组展开,来获得列表的首个元素。
line, = plt.plot(x, y, '-') line.set_antialiased(False) # 关闭抗锯齿
使用 setp() 命令。下面给出的例子使用Matlab样式命令来设置对列表中的线对象设置多种属性。
setp可以作用于对象列表或仅仅一个对象。你可以使用Python关键字的形式或Matlab样式。
lines = plt.plot(x1, y1, x2, y2) # use keyword args plt.setp(lines, color='r', linewidth=2.0) # or MATLAB style string value pairs plt.setp(lines, 'color', 'r', 'linewidth', 2.0)
设置坐标轴范围
参考文档:
xlim() 命令
ylim() 命令
下面以 xlim() 为例进行说明:
获取或设置当前图像 x 轴的范围:
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
或者可以下面这样:
xlim(xmax=3) # adjust the max leaving min unchanged xlim(xmin=1) # adjust the min leaving max unchanged
设置 x-axis limits 会使得 autoscaling 自动关闭,即两者不能同时设置。
以上说明综合举例如下:
import numpy as np import matplotlib.pyplot as plt plt.figure(figsize=(8, 5), dpi=80) plt.subplot(111) X = np.linspace(-np.pi, np.pi, 256, endpoint=True) S = np.sin(X) C = np.cos(X) plt.plot(X, C, color="blue", linewidth=2.5, linestyle="-") plt.plot(X, S, color="red", linewidth=2.5, linestyle="-") plt.xlim(X.min() * 1.1, X.max() * 1.1) plt.ylim(C.min() * 1.1, C.max() * 1.1) plt.show()
生成的图像:
相关文章推荐
- 【Matplotlib】线设置,坐标显示范围
- matplotlib 设置坐标轴显示内容
- matplotlib-设置绘图横纵坐标的取值范围
- 使用matplotlib的示例:调整字体-设置刻度、坐标、colormap和colorbar等
- python matplotlib 中文显示参数设置
- matplotlib--设置坐标轴
- 如何设置让基于matplotlib的绘图库正常的显示no-ascii字符(中文字符)
- matplotlib模块数据可视化-设置次坐标轴
- matplotlib模块数据可视化-设置坐标轴
- python matplotlib 中文显示参数设置
- matplotlib的基本用法(六)——设置坐标轴label
- python matplotlib绘图设置坐标轴刻度、文本
- 设置matplotlib 横坐标为毫秒
- 【原】在Matplotlib绘图过程中设置X轴的刻度和显示文本
- matplotlib时间坐标设置
- python matplotlib 中文显示参数设置
- matplotlib设置中文显示
- Matplotlib 绘图双纵坐标轴设置及控制设置时间格式
- 设置matplotlib中文显示