matplotlib 曲线图 和 折线图 plt.plot()实例


Posted in Python onApril 17, 2020

我就废话不多说了,大家还是直接看代码吧!

绘制曲线:

import time
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 1000)
y = np.sin(x)
plt.figure(figsize=(6,4))
plt.plot(x,y,color="red",linewidth=1 )
plt.xlabel("x") #xlabel、ylabel:分别设置X、Y轴的标题文字。
plt.ylabel("sin(x)")
plt.title("正弦曲线图") # title:设置子图的标题。
plt.ylim(-1.1,1.1)# xlim、ylim:分别设置X、Y轴的显示范围。
plt.savefig('quxiantu.png',dpi=120,bbox_inches='tight')
# plt.show()
# plt.close()

matplotlib 曲线图 和 折线图 plt.plot()实例

import matplotlib.pyplot as plt
squares=[1,4,9,6,25]
plt.plot(squares)
plt.savefig('zhexiantu.png',dpi=120,bbox_inches='tight') #dpi 代表像素
#绘制折线图

matplotlib 曲线图 和 折线图 plt.plot()实例

补充知识:matplotlib 画箭头的两种方式

如下所示:

def drawArrow(A, B):
 fig = plt.figure(figsize=(5, 5))
 print("xasxcsasdc")
 ax = fig.add_subplot(121)
 # fc: filling color
 # ec: edge color


 """第一种方式"""
 ax.arrow(A[0], A[1], B[0]-A[0], B[1]-A[1],
    width=0.01,
    length_includes_head=True, # 增加的长度包含箭头部分
    head_width=0.25,
    head_length=1,
    fc='r',
    ec='b')
 ax.set_xlim(0, 5)
 ax.set_ylim(0, 5)
 ax.grid()
 ax.set_aspect('equal')

 """第二种方式"""
 # 这种方式是在图上做标注时产生的
 # Example:
 ax = fig.add_subplot(122)
 ax.annotate("",
    xy=(B[0], B[1]),
    xytext=(A[0], A[1]),
    # xycoords="figure points",
    arrowprops=dict(arrowstyle="->", color="r"))
 ax.set_xlim(0, 5)
 ax.set_ylim(0, 5)
 ax.grid()
 ax.set_aspect('equal') #x轴y轴等比例

 #x轴y轴等比例
 plt.show()

matplotlib 曲线图 和 折线图 plt.plot()实例

第一种

Axes.arrow(x,y,# 坐标x, y
dx,dy, # 箭头两端横纵坐标距离差
* * kwargs) # 箭头架构和属性设置

Constructor arguments
width 箭头尾巴的线宽
length_includes_head: bool (default: False) # 增加的长度包含箭头部分
head_width: float or None (default: 3*width) # 箭头部分的宽度
head_length: float or None (default: 1.5 * head_width) # 箭头部分的长度
shape: [‘full', ‘left', ‘right'] (default: ‘full') # 箭头是否全部显示 full 完整显示 left左半部 right 右半部
overhang: float (default: 0) # 不知道怎么形容 会改变箭头部分的形状

alpha:透明度
color 箭头的颜色
fc : 箭头尾部的
ec:箭头边界的颜色
fill:箭头部分是否填充颜色
antialiased :False时会让箭头部分带上锯齿
hatch:箭头部分的填充形状

{'/', ‘', ‘|', ‘-', ‘+', ‘x', ‘o', ‘O', ‘.', ‘*'}

第二种

Axes.annotate(s, 标注的信息
xy, 标注点的坐标
*args,
**kwargs)[source]

参数:

s : str 标注的信息
xy : (float, float) 标注点的坐标(箭头的头端点)
xytext : (float, float), 标注的位置(箭头的尾巴)
arrowprops : dict, optional

标注指向的线条的形状:

‘-' 、 ‘->' 、 ‘-[' 、 ‘|-|' 、 ‘-|>' 、 ‘<-' 、 ‘<->' 、 ‘<|-' 、 ‘<|-|>'、 ‘fancy' 、 ‘simple' 、 ‘wedge' 、

以上这篇matplotlib 曲线图 和 折线图 plt.plot()实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python使用rsa加密算法模块模拟新浪微博登录
Jan 22 Python
Python中输出ASCII大文字、艺术字、字符字小技巧
Apr 28 Python
一步步教你用Python实现2048小游戏
Jan 19 Python
深入理解Python3中的http.client模块
Mar 29 Python
Python+OpenCV目标跟踪实现基本的运动检测
Jul 10 Python
python中协程实现TCP连接的实例分析
Oct 14 Python
Python重新加载模块的实现方法
Oct 16 Python
如何基于Python实现自动扫雷
Jan 06 Python
Python实现FLV视频拼接功能
Jan 21 Python
Tensorflow: 从checkpoint文件中读取tensor方式
Feb 10 Python
简单了解python关键字global nonlocal区别
Sep 21 Python
Python连续赋值需要注意的一些问题
Jun 03 Python
Python实现自动打开电脑应用的示例代码
Apr 17 #Python
Python matplotlib绘制图形实例(包括点,曲线,注释和箭头)
Apr 17 #Python
Python读取excel文件中带公式的值的实现
Apr 17 #Python
在Matplotlib图中插入LaTex公式实例
Apr 17 #Python
python中for in的用法详解
Apr 17 #Python
解决Jupyter无法导入已安装的 module问题
Apr 17 #Python
使用 Python 读取电子表格中的数据实例详解
Apr 17 #Python
You might like
CI框架数据库查询缓存优化的方法
2016/11/21 PHP
php中引用符号(&amp;)的使用详细介绍
2016/12/06 PHP
php 多继承的几种常见实现方法示例
2019/11/18 PHP
textarea不能通过maxlength属性来限制字数的解决方法
2014/09/01 Javascript
招聘网站基于jQuery实现自动刷新简历
2015/05/10 Javascript
JS+DIV实现鼠标划过切换层效果的方法
2015/05/25 Javascript
Linux下为Node.js程序配置MySQL或Oracle数据库的方法
2016/03/19 Javascript
js replace()去除代码中空格的实例
2017/02/14 Javascript
完美解决mui框架off-canvas侧滑超出部分隐藏无法滚动的问题
2018/01/25 Javascript
javascript中undefined的本质解析
2019/07/31 Javascript
小程序实现列表展开收起效果
2020/07/29 Javascript
解决vue字符串换行问题(绝对管用)
2020/08/06 Javascript
[01:02]DOTA2辉夜杯决赛日 CDEC.Y对阵VG赛前花絮
2015/12/27 DOTA
[01:14:55]EG vs Spirit Supermajor 败者组 BO3 第三场 6.4
2018/06/05 DOTA
[01:25:33]完美世界DOTA2联赛PWL S3 INK ICE vs Magma 第二场 12.20
2020/12/23 DOTA
Python查看多台服务器进程的脚本分享
2014/06/11 Python
Python类的专用方法实例分析
2015/01/09 Python
Python中用于计算对数的log()方法
2015/05/15 Python
Python实现全角半角字符互转的方法
2016/11/28 Python
python英语单词测试小程序代码实例
2019/09/09 Python
基于Python实现剪切板实时监控方法解析
2019/09/11 Python
Django使用Celery加redis执行异步任务的实例内容
2020/02/20 Python
解决pyPdf和pyPdf2在合并pdf时出现异常的问题
2020/04/03 Python
python实现三壶谜题的示例详解
2020/11/02 Python
Django数据库迁移常见使用方法
2020/11/12 Python
Python urlopen()参数代码示例解析
2020/12/10 Python
css3的动画特效之动画序列(animation)
2017/12/22 HTML / CSS
HTML5 canvas实现移动端上传头像拖拽裁剪效果
2016/03/14 HTML / CSS
MyFrenchPharma中文网:最大的法国药妆平台
2016/10/07 全球购物
英国电子产品购物网站:TobyDeals
2018/07/30 全球购物
将时尚融入珠宝:Adornmonde
2019/10/17 全球购物
应聘教师自荐信
2013/10/12 职场文书
青年志愿者活动总结
2014/04/26 职场文书
初中信息技术教学计划
2015/01/22 职场文书
端午节寄语2015
2015/03/23 职场文书
因个人原因离职的辞职信范文
2015/05/12 职场文书