目录

前言

陆陆续续接触了些,关于Matplotlib的教材,总是感觉学不到本质的东西。今天就来讲一下 关于

plt.plot()函数的本质。

(一)plt.plot()函数的本质

1.说明

plt.plot()函数的本质就是根据点连接线。根据x(数组或者列表) 和 y(数组或者列表)组成点,然后连接成线。

2.源代码

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [1, 2, 20, 50]
# 创建一个画布
plt.figure()
# 创建一条线
plt.plot(x, y) # 展现画布
plt.show()

3.展示效果

(二)plt.plot()函数缺省x时

1.说明

缺省x的情况下,x的默认值是:range(len(y))

2.源代码

import matplotlib.pyplot as plt

# 缺省x参数时,默认的x是range(len(y))
y = [1, 2, 3, 4]
# 创建一个画布
plt.figure()
# 创建一条线
plt.plot(y)
# 展现画布
plt.show()

3.展示效果

(三)颜色控制符

要想使用丰富,炫酷的图标,我们可以使用更复杂的格式设置,主要颜色,线的样式,点的样式。

默认的情况下,只有一条线,是蓝色实线。多条线的情况下,生成不同颜色的实线。

字符 颜色
'b' blue
'g' green
'r' red
'c' cyan 青色
'm' magenta平红
'y' yellow
'k' black
'w' white

(四)线形控制符

1.说明

字符 类型
'-' 实线
'--' 虚线
'-.' 虚点线
':' 点线
' ' 空类型,不显示线

2.源代码

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y1 = [1, 2, 3, 4]
y2 = [1, 4, 9, 16]
y3 = [1, 8, 27, 64]
y4 = [1, 16, 81, 124]
# 创建一个画布
plt.figure()
# 在figure下线
plt.plot(x, y1, "-o") #实线
plt.plot(x, y2, "--o") #虚线
plt.plot(x, y3, "-.o") #虚点线
plt.plot(x, y4, ":o") # 点线
# 展现画布
plt.show()

3.输出效果

(五)点的类型控制符

1.普通点类型

(1)说明:

'.'
',' 像素点
'o' 原点

(2)源代码

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y1 = [1, 2, 3, 4]
y2 = [1, 4, 9, 16]
y3 = [1, 8, 27, 64]
y4 = [1, 16, 81, 124]
# 创建一个画布
plt.figure()
# 在figure下的线
plt.plot(x, y1, "-.") # 点
plt.plot(x, y2, "-,") # 像素点
plt.plot(x, y3, "-o") # 圆点 # 展现画布
plt.show()

(3)输出效果:

2.三角点

(1)说明:

'^' 上三角点
'v' 下三角点
'<' 左三角点
'>' 右三角点

(2)源代码:

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y1 = [1, 2, 3, 4]
y2 = [1, 4, 9, 16]
y3 = [1, 8, 27, 64]
y4 = [1, 16, 81, 124]
# 创建一个画布
plt.figure()
# 在figure下的线
plt.plot(x, y1, "-^")
plt.plot(x, y2, "-v")
plt.plot(x, y3, "-<")
plt.plot(x, y4, "->") # 展现画布
plt.show()

(3)输出效果:

3.三叉点

(1)说明:

'1' 下三叉点
'2' 上三叉点
'3' 左三叉点
'4' 右三叉点

(2)源代码:

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y1 = [1, 2, 3, 4]
y2 = [1, 4, 9, 16]
y3 = [1, 8, 27, 64]
y4 = [1, 16, 81, 124]
# 创建一个画布
plt.figure()
# 在figure下的线
plt.plot(x, y1, "-1")
plt.plot(x, y2, "-2")
plt.plot(x, y3, "-3")
plt.plot(x, y4, "-4") # 展现画布
plt.show()

(3)输出效果:

4.多边形点

(1)说明:

's' 正方点
'p' 五角点
'*' 星形点
'h' 六边形1
'H' 六边形2

(2)源代码:

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y1 = [1, 2, 3, 4]
y2 = [1, 4, 9, 16]
y3 = [1, 8, 27, 64]
y4 = [1, 16, 81, 124]
y5 = [1, 64, 100, 180]
# 创建一个画布
plt.figure()
# 在figure下的线
plt.plot(x, y1, "-s")
plt.plot(x, y2, "-p")
plt.plot(x, y3, "-*")
plt.plot(x, y4, "-h")
plt.plot(x, y5, "-H") # 展现画布
plt.show()

(3)输出效果:

5.其他形状点

(1)说明:

'+' 加号点
'x' 乘号点
'D' 实心菱形点
'd' 细菱形点
'_' 横线点
'|' 竖线点

(2)源代码:

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y1 = [1, 2, 3, 4]
y2 = [1, 4, 9, 16]
y3 = [1, 8, 27, 64]
y4 = [1, 16, 81, 124]
y5 = [1, 64, 100, 180]
# 创建一个画布
plt.figure()
# 在figure下的线
plt.plot(x, y1, "-+")
plt.plot(x, y2, "-x")
plt.plot(x, y3, "-D")
plt.plot(x, y4, "-d")
plt.plot(x, y5, "-_") # 展现画布
plt.show()

(3)输出效果:

注:三种控制符可以单独使用,也可以组合使用

(六)风格使用的另一种方法

1.说明

color="green" 指定颜色为绿色

linestyle="dashed" 指定线形为dashed类型

marker="o" 指定标记类型为o点

markerfacecolor="blue"指定标记的颜色为蓝色

markersize=20 指定标记的大小为20

2.原代码

import matplotlib.pyplot as plt
import numpy as np x = np.arange(10)
y1 = x * 1.5
y2 = x * 2.5
y3 = x * 3.5
y4 = x * 4.5
y5 = x * 5.5 plt.plot(x, y1, "-P")
plt.plot(x, y2, "-|")
plt.plot(x, y3, color="#000000")
plt.plot(x, y4, "-o", markersize=20)
plt.plot(x, y5, "-^", markerfacecolor="blue") plt.show()

3.输出效果

作者:Mark

日期:2019/01/30 周三

4.3Python数据处理篇之Matplotlib系列(三)---plt.plot()折线图的更多相关文章

  1. 4.5Python数据处理篇之Matplotlib系列(五)---plt.pie()饼状图

    目录 目录 前言 (一)简单的饼状图 (二)添加阴影和突出部分 (三)显示图例和数据标签: 目录 前言 饼状图需要导入的是: plt.pie(x, labels= ) (一)简单的饼状图 (1)说明: ...

  2. 4.4Python数据处理篇之Matplotlib系列(四)---plt.bar()与plt.barh条形图

    目录 目录 前言 (一)竖值条形图 (二)水平条形图 1.使用bar()绘制: 2.使用barh()绘制: (三)复杂的条形图 1.并列条形图: 2.叠加条形图: 3.添加图例于数据标签的条形图: 目 ...

  3. 4.2Python数据处理篇之Matplotlib系列(二)---plt.scatter()散点图

    目录 目录 前言 (一)散点图的基础知识 (二)相关性的举例 ==1.正相关== ==1.负相关== ==1.不相关== (三)实战项目以一股票的分析 目录 前言 散点图是用于观测数据的相关性的,有正 ...

  4. 4.6Python数据处理篇之Matplotlib系列(六)---plt.hist()与plt.hist2d()直方图

    目录 目录 前言 (一)直方图 (二)双直方图 目录 前言 今天我们学习的是直方图,导入的函数是: plt.hist(x=x, bins=10) 与plt.hist2D(x=x, y=y) (一)直方 ...

  5. 5.3Python数据处理篇之Sympy系列(三)---简化操作

    目录 5.3简化操作 目录 前言 (一)有理数与多项式的简化 1.最简化-simplify() 2.展开-expand() 3.提公因式-factor() 4.合并同类项-ceiling() 5.简化 ...

  6. 3.3Python数据处理篇之Numpy系列(三)---数组的索引与切片

    目录 (一)数组的索引与切片 1.说明: 2.实例: (二)多维数组的索引与切片 1.说明: 2.实例: 目录: 1.一维数组的索引与切片 2.多维数组的索引与切片 (一)数组的索引与切片 1.说明: ...

  7. 4.13Python数据处理篇之Matplotlib系列(十三)---轴的设置

    目录 目录 前言 (一)设置轴的范围 1.同时对于x,y轴设置 2.分别对与x,y轴的设置 (二)设置刻度的大小 1.普通的刻度设置 2.添加文本的刻度设置 3.主副刻度的设置 (三)设置轴的数据 1 ...

  8. 4.11Python数据处理篇之Matplotlib系列(十一)---图例,网格,背景的设置

    目录 目录 前言 (一)图例legend 1.默认不带参数的图例 2.添加参数的图例 3.将图例移动到框外 (二)网格grid 1.说明 2.源代码: 3.输出效果 (三)背景axses 1.设置全局 ...

  9. 4.9Python数据处理篇之Matplotlib系列(九)---子图分布

    目录 目录 前言 (一)subplot()方法 ==1.语法说明== ==2.源代码== ==3.输出效果== (二)subplot2grid方法 ==1.语法说明== ==2.源代码== ==3.展 ...

随机推荐

  1. json数据格式说明

    格式说明 json文件由对象(集合).数组.key/value元素组成,可以相互嵌套. 使用大括号包围的是对象,使用中括号包围的是数组,冒号分隔的是元素. 元素的key只能是字符串. 元素的value ...

  2. mybatis_ The content of element type association must match (constructor,id,result,ass ociation,collection,discriminator)

    一般遇到这种问题肯定要看一看association中元素编写顺序, <resultMap id="orderRslMap" type="orders"&g ...

  3. 使用virtualenv进行python环境隔离

    按照以下步骤安装 TensorFlow: 1.打开终端(一个 shell),你将在这个终端中执行随后的步骤 2.通过以下命令安装 pip 和 virtualenv sudo easy_install ...

  4. Android Studio 学习(二) UI

    TextView android:gravity="center"居中对齐 //文字对齐方式 top bottom left right center android:textSi ...

  5. CommandLineRunner和ApplicationRunner的区别

    CommandLineRunner和ApplicationRunner的区别 二者的功能和官方文档一模一样,都是在Spring容器初始化完毕之后执行起run方法 不同点在于,前者的run方法参数是St ...

  6. linux防火墙相关 iptables

    1. root用户查看防火墙状态(非root用户无权限查看) 查看防火墙状态: service iptables status 2.开启和关闭防火墙 //开启防火墙: service iptables ...

  7. xml方式封装数据方法

    1.xml方式封装数据方法 2.demo <?php xml方式封装数据方法 /** * [xmlEncode description] * @param [type] $code [descr ...

  8. ASPxGridView 选中主表一行数据,从表自动选中(勾选)对应的行

    一.图解 下图为效果图,点击 [A表]种的某一行,[B表]会有与之相对于一行会被自动选中并且勾选上: 二.Html 代码 <html xmlns="http://www.w3.org/ ...

  9. JS之innerHTML,innerText,outerHTML,textContent的用法与区别

    示例html代码: <div id="test"> <span style="color:red">test1</span> ...

  10. React 入门学习笔记整理目录

    React 入门学习笔记整理(一)--搭建环境 React 入门学习笔记整理(二)-- JSX简介与语法 React 入门学习笔记整理(三)-- 组件 React 入门学习笔记整理(四)-- 事件 R ...