改变线的颜色和线宽

参考文章:

线有很多属性你可以设置:线宽,线型,抗锯齿等等;具体请参考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() 为例进行说明:

获取或设置当前图像 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()

生成的图像:

最新文章

  1. 《数据结构》 java的一维数组的内存结构与其特性
  2. Mono for android真难用
  3. [daily][device][bluetooth] 蓝牙怎么办!(archlinux下驱动蓝牙鼠标,以及三星手机)
  4. Centos 7 修改SSH端口号
  5. unity jiaoben
  6. apache2.4 +django1.9+python3+ubuntu15.10
  7. java内部类实现多继承
  8. SVN如何commit(提交)项目代码
  9. MPLS的模拟学习过程
  10. 一道有趣的JS问题
  11. SQL Server进阶(十)事务和并发处理
  12. 关于linux下ntp时间同步服务的安装与配置
  13. 数学小知识点整理(TBC)
  14. jrebel热部署
  15. 带你走进二进制-一次APT攻击分析
  16. android dev概念快速入门
  17. Mac下配置环境变量重启后不生效解决(.bash_profile vs .bashrc)(bash/zsh下不加载.bashrc问题解决)
  18. [算法整理]树上求LCA算法合集
  19. Code Igniter数据库操作函数大全
  20. admin.ModelAdmin 后台管理关联对象,某个字段怎么显示值

热门文章

  1. flask实现api
  2. (2.13)Mysql之SQL基础——触发器
  3. 解决MySQL报错:1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'informat
  4. 【生产问题】write log 引起系统卡死,业务全部阻塞
  5. C++模拟Http/Https访问web站点
  6. 自动化测试中级篇——LazyAndroid UI自动化测试框架使用指南
  7. The same month as the adidas NMD Singapore is releasing
  8. lua实现单例模式
  9. vgg_face人脸识别
  10. ng-深度学习-课程笔记-9: 机器学习策略1(Week1)