金点网络-全网资源,一网打尽
  • 网站首页
    • 金点部落
    • 小游戏
    • OpenAPI
    • 设计资产导航
    • 升级会员
  • 技能学习
    • 体育运动
    • 办公教程
    • 口才演讲
    • 小吃技术
    • 建站教程
    • 摄影教程
    • 棋牌教程
    • 网赚教程
      • 爆粉引流
      • 自媒体
      • 贴吧引流
  • 网站源码
    • 商城/淘客/交易
    • 小说/漫画/阅读
    • 影视/音乐/视频
    • 微信/微商/微擎
    • 理财/金融/货币
    • 模板/主题/插件
  • 游戏源码
    • 精品网单
    • 端游源码
    • 手游源码
    • 页游源码
  • 素材资料
    • 电子文档
    • 综合资料
    • 考研资料
    • 设计素材
    • 音频讲座
      • 人文艺术
      • 名师讲座
      • 说书小说
  • 软件工具
    • Windows软件
    • MacOS软件
    • Android软件
  • 寄售资源
    • 游戏源码
    • 网站源码
    • 软件源码
  • 公益服
登录/注册
  • 专享大神特权
立即开通开通会员抄底价

Python数据分析(中英对照)·Introduction to Matplotlib and Pyplot-Matplotlib 和 Pyplot 介绍

作者 : jamin 本文共7083个字,预计阅读时间需要18分钟 发布时间: 2020-10-18 共1716人阅读

2.3.1: Introduction to Matplotlib and Pyplot-Matplotlib 和 Pyplot 介绍

Matplotlib is a Python plotting library that produces publication-quality figures.
Matplotlib是一个Python绘图库,用于生成出版物质量的图形。
It can be used both in Python scripts and when using Python’s interactive mode.
它既可以在Python脚本中使用,也可以在使用Python的交互模式时使用。
Matplotlib is a very large library, and getting to know it well takes time.
Matplotlib是一个非常大的库,了解它需要时间。
But often we don’t need the full matplotlib library in our programs,and this is where Pyplot comes in handy.
但是我们的程序中通常不需要完整的matplotlib库,这就是Pyplot的用武之地。
Pyplot is a collection of functions that make matplotlib work like Matlab,which you may be familiar with.
Pyplot是一组函数,使matplotlib像Matlab一样工作,您可能熟悉这些函数。
Pyplot is especially useful for interactive work,for example, when you’d like to explore a dataset or visually examine your simulation results.
Pyplot对于交互式工作尤其有用,例如,当您希望浏览数据集或直观地检查模拟结果时。
We’ll be using Pyplot in all our data visualizations.
我们将在所有数据可视化中使用Pyplot。
Pyplot provides what is sometimes called a state machine interface to matplotlib library.
Pyplot为matplotlib库提供了有时称为状态机的接口。
You can loosely think of it as a process where you create figures one at a time,and all commands affect the current figure and the current plot.
您可以粗略地将其视为一个一次创建一个地物的过程,所有命令都会影响当前地物和当前绘图。
We will mostly use NumPy arrays for storing the data that we’d like to plot, but we’ll occasionally use other types of data objects such as built-in lists.
我们将主要使用NumPy数组来存储要绘制的数据,但偶尔也会使用其他类型的数据对象,如内置列表。
As you may have realized, saying matplotlib.pyplot is kind of a mouthful, and it’s a lot to type too.
正如您可能已经意识到的那样,说matplotlib.pyplot有点口齿不清,而且打字也很费劲。
That’s why virtually everyone who uses the library imports it as plt, which is a lot shorter.
这就是为什么几乎所有使用该库的人都将其作为plt导入,而plt要短得多。
So to import the library, we will type the following– import matplotlib.pyplot as plt.
因此,要导入库,我们将键入以下内容–import matplotlib.pyplot as plt。
Now we are ready to start our plotting.
现在我们准备开始我们的阴谋。
A basis but very useful command is the plt plot function, which can be used to plot lines and markers.
plt plot函数是一个基本但非常有用的命令,可用于绘制线和标记。
The simplest version of plot has just one argument,and it specifies the y-axis values that are to be plotted.
plot的最简单版本只有一个参数,它指定要打印的y轴值。
In this case, when you provide just one argument, the plot function,each y-axis value will be plotted against its corresponding index value on the x-axis.
在这种情况下,当您只提供一个参数(plot函数)时,每个y轴值都将根据其对应的索引值在x轴上进行打印。
Because Python indexing starts at 0, the first element of your array or list ppears at location x equal to 0.
因为Python索引从0开始,所以数组或列表的第一个元素出现在位置x等于0。
The second element appears at location x equal to 1, and so on.
第二个元素出现在等于1的位置x,依此类推。
Let’s now practice using the plot function in the IPython Shell.
现在让我们练习在IPython Shell中使用plot函数。
Let’s start by making a simple plot.
让我们先画一个简单的图。
So we’ll say plt.plot.
所以我们说plt.plot。
I’m going to create a list consisting of the numbers 0, 1, 4, 9, and 16.
我将创建一个由数字0、1、4、9和16组成的列表。
You can see here that Python returns a matplotlib object.
您可以在这里看到Python返回matplotlib对象。
If for some reason you’d like to suppress the printing of that object,in the IPython Shell you can add a semi-colon at the end of the line and that will do the job.
如果出于某种原因希望禁止打印该对象,则可以在IPython Shell中的行末尾添加分号,这样就可以完成此任务。
If we rerun this with the semi-colon at the end,you’ll see that the plot still appears, but we don’t get that matplotlib object printed out.
如果我们在最后使用分号重新运行此操作,您将看到绘图仍然显示,但我们无法打印matplotlib对象。
Because we are working in IPython, the plots will appear inside the Python Shell.
因为我们在IPython中工作,所以绘图将显示在pythonshell中。
Well, let’s see what happens if, instead of using IPython Shell,we used the standard Python Shell.
好吧,让我们看看如果我们使用标准的Python Shell而不是IPython Shell会发生什么。
Let’s first launch the Python Shell.
让我们首先启动pythonshell。
I’m going to go to View Panes and Console.
我要去查看窗格和控制台。
I’ll resize my window a little bit.
我会稍微调整一下我的窗口。
Because we have a new session here, I need to do my import first.
因为这里有一个新会话,所以我需要先导入。
So I’ve just imported my plt.
所以我刚导入了我的plt。
The next step is to create the plot 0, 1, 4, 9, and 16.
下一步是创建绘图0、1、4、9和16。
You’ll notice that it seems like nothing has happened.
你会注意到好像什么都没发生。
In fact, the plot has been created, but because we are not working in a Python Shell, not IPython Shell,we need to issue the command Show for plt to show the plot.
事实上,已经创建了绘图,但是因为我们不是在pythonshell中工作,不是在ipythonshell中工作,所以我们需要为plt发出Show命令来显示绘图。
So let’s try that– plt.show.
让我们试试看,plt.show。
We can also give the plot function two arguments, in which case the first argument specifies the x-coordinates of the points,
我们也可以给plot函数两个参数,在这种情况下,第一个参数指定点的x坐标,
and the second argument the y-coordinates of the points.
第二个参数是点的y坐标。
I’m going to create a vector x using np.linspace.
我将使用np.linspace创建一个向量x。
I want that vector to start at 0 and at 10,and I would like to have 20 points in my vector– in my one-dimensional array.
我希望向量从0到10开始,我希望向量中有20个点,在一维数组中。
I’m going to define my y-vector from the x.
我要用x来定义y向量。
I’m going to be taking every element of x and raising them to power 2.
我将取x的每一个元素,并将它们提升到2次方。
Now I have two vectors defined– x and y.
现在我定义了两个向量——x和y。
I can now call the plot function where my first argument is x and my second argument is y.
现在我可以调用plot函数,其中第一个参数是x,第二个参数是y。
In this case, what we have is the familiar shape of a parabola.
在这种情况下,我们得到的是熟悉的抛物线形状。
We can also provide a third argument to the plot function, which is a format string that specifies color, marker, and line type.
我们还可以为plot函数提供第三个参数,这是一个指定颜色、标记和线型的格式字符串。
Letters and symbols of the format string are the same as in Matlab,but even if you’re not familiar with those,
格式字符串的字母和符号与Matlab中的相同,但即使您不熟悉这些,
you’ll easily learn them with a little practice.
只要稍加练习,你就能轻松地学会它们。
This is also a good place to introduce what are called keyword arguments.
这也是介绍所谓的关键字参数的好地方。
The idea is completely generic and applies to all Python functions,but with the plt library, it’s almost impossible not to use them.
这个想法是完全通用的,适用于所有Python函数,但是对于plt库,几乎不可能不使用它们。
In short, a keyword argument is an argument which is supplied to the function by explicitly naming each parameter and specifying its value.
简而言之,关键字参数是通过显式命名每个参数并指定其值提供给函数的参数。
Two keyword arguments that I use all the time are linewidth and markersize.
我一直使用的两个关键字参数是linewidth和markersize。
Let’s put these different ideas together in an example.
让我们把这些不同的想法放在一个例子中。
I’m first going to create my vector x.
我首先要创建向量x。
It’s a linear vector starting from 0, going to 10, and consists of 20 points.
它是一个从0开始到10的线性向量,由20个点组成。
I’m going to define y1, which is going to be my x raised to the power of 2.
我将定义y1,它将是我的x,提升到2的幂。
Then I’m going to define a second vector.
然后我将定义第二个向量。
Let’s call that y2, and this is x raised to the power of 1.5.
我们称之为y2,这是x的幂,1.5。
At this point, I have three vectors– x, y1, and y2.
在这一点上,我有三个向量——x,y1和y2。
I can now call the plot function.
我现在可以调用plot函数了。
My first argument is x, my second argument is y1,and then my third argument specifies the appearance of the plot.
我的第一个参数是x,第二个参数是y1,然后第三个参数指定绘图的外观。
In this case, I’m requesting plt to use blue, to use circles,and to use a solid line.
在本例中,我要求plt使用蓝色、圆形和实线。
We can try plotting this out, and we see the outcome.
我们可以试着画出来,我们看到了结果。
We can now add our keyword arguments to this function call.
现在,我们可以将关键字参数添加到此函数调用中。
I can specify linewidth.
我可以指定线宽。
I’m going to set it to 2 in this case.
在这种情况下,我将把它设置为2。
I’m going to also specify markersize, which I’m going to set to 4.
我还将指定markersize,将其设置为4。
And in this case, you’ll see that the linewidth has changed,and the size of the markers has also changed.
在本例中,您将看到线宽已更改,标记的大小也已更改。
If I would prefer larger markers, I could set markersize 12 and, again, the effect is apparent.
如果我更喜欢较大的标记,我可以将markersize设置为12,同样,效果是明显的。
I can do the same thing for y2.
我可以为y2做同样的事情。
I’m going to use this line and build from it.
我将使用这条线并从中构建。
I’m going to be plotting x, and I’m going to be plotting y2 but in this case, I would like to use green squares,so I change b to g, meaning from blue to green. And I change circles to squares,so I change the o to an s. And I will still stick with my solid lines.
我要画x,我要画y2,但在这个例子中,我想用绿色的方块,所以我把b改成g,意思是从蓝色变成绿色。我把圆变成了正方形,所以我把o变成了s。我仍然会坚持我的实线。
In this case, we run the line and we see the green plot.
在本例中,我们运行该行,并看到绿色的绘图。

Python 数据分析
本站所提供的部分资源来自于网络,版权争议与本站无关,版权归原创者所有!仅限用于学习和研究目的,不得将上述内容资源用于商业或者非法用途,否则,一切后果请用户自负。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容资源。如果上述内容资对您的版权或者利益造成损害,请提供相应的资质证明,我们将于3个工作日内予以删除。本站不保证所提供下载的资源的准确性、安全性和完整性,源码仅供下载学习之用!如用于商业或者非法用途,与本站无关,一切后果请用户自负!本站也不承担用户因使用这些下载资源对自己和他人造成任何形式的损失或伤害。如有侵权、不妥之处,请联系站长以便删除!
金点网络-全网资源,一网打尽 » Python数据分析(中英对照)·Introduction to Matplotlib and Pyplot-Matplotlib 和 Pyplot 介绍

常见问题FAQ

免费下载或者VIP会员专享资源能否直接商用?
本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
是否提供免费更新服务?
持续更新,永久免费
是否经过安全检测?
安全无毒,放心食用
jamin

jamin 大神

下一篇
网络协议-组播介绍

相关推荐

Python数据分析(中英对照)·Numbers and Basic Calculations 数字和基本计算

Python数据分析(中英对照)·Numbers and Basic Calculations 数字和基本计算

Python数据分析(中英对照)·Scope Rules范围规则

Python数据分析(中英对照)·Scope Rules范围规则

Python数据分析(中英对照)·Examples Involving Randomness 涉及随机性的例子

Python数据分析(中英对照)·Examples Involving Randomness 涉及随机性的例子

Python数据分析(中英对照)·Sets 集合

Python数据分析(中英对照)·Sets 集合

Python数据分析(中英对照)·Simulating Randomness 模拟随机性

Python数据分析(中英对照)·Simulating Randomness 模拟随机性

标签云
Android Atom ExecutorService ForkJoin GM GM后台 GM授权后台 H5 Java Javascript Linux手工服务端 pipbestcom Python ReentrantLock synchronized ThreadLocal volatile Win一键即玩服务端 一键端 传奇 写作 创业 单机 后台 商业端 外网 安卓 安卓苹果双端 工具 手工端 手游 搭建教程 教程 数据分析 文案 游戏源码 端游 经典 网单 职场 自媒体 视频教程 详细搭建教程 运营后台 页游

近期文章

  • 回合手游【逍遥西游之繁华西游】最新整理单机一键既玩镜像服务端_Linux手工端_GM后台_教程
  • 最新整理精品回合制手游【天书奇谈3D混沌完整版】VM一键单机版_linux手工外网端_隐盟视频教程_授权GM后台_双端
  • 典藏修真页游【诸仙列传OL】最新整理Win系服务端_GM工具_详细外网搭建教程
  • MT3换皮MH【浮生若梦尊享挂机修复版】最新整理单机一键即玩镜像端_Linux手工服务端_安卓苹果双端_GM后台_详细搭建教程
  • 大话回合手游【最新引擎之缥缈西游渡劫版】最新整理Linux手工服务端_安卓苹果双端_管理后台_CDK后台_详细搭建教程_视频教程

分类

  • | wordpress插件 |
  • | wordpress模板 |
  • | 其它模板 |
  • | 帝国模板 |
  • | 织梦插件 |
  • | 织梦模板 |
  • A5源码
  • Android软件
  • APP引流
  • E语言
  • H5
  • LUA
  • QQ营销
  • SEO推广
  • Windows软件
  • 体育运动
  • 信息数据
  • 创业专题
  • 办公教程
  • 口才演讲
  • 名师讲座
  • 商城/淘客/交易
  • 小吃技术
  • 小说/漫画/阅读
  • 建站教程
  • 引流脚本
  • 影视/音乐/视频
  • 影视资源
  • 微信/微商/微擎
  • 微信小程序
  • 微信营销
  • 微擎模块
  • 手游源码
  • 技能学习
  • 抖音课程
  • 摄影教程
  • 棋牌教程
  • 模板/主题/插件
  • 游戏源码
  • 爆粉引流
  • 理财/金融/货币
  • 生活老师
  • 电商客
  • 电子文档
  • 电脑教程
  • 社群营销
  • 站长工具
  • 精品网单
  • 系统工具
  • 素材资料
  • 综合资料
  • 编程经验
  • 网站源码
  • 网络安全
  • 网赚教程
  • 网赚源码
  • 考研资料
  • 脚本/AI/智能
  • 自媒体
  • 英语学习
  • 营销软件
  • 设计素材
  • 说书小说
  • 贴吧引流
  • 软件工具
  • 软文营销
  • 逆向软件
  • 音频讲座
  • 页游源码

提供最优质的资源集合

立即加入 友好社区
金点网络-全网资源,一网打尽

新一代全网资源综合门户网(www.pipbest.com-金点网络)专注服务于互联网,提供各类最新最全的免费源码下载(PHP、ASP、JSP、.NET),更提供免费工具,免费源码下载,软件下载,素材下载,赚钱教程下载,交流论坛等网站运营相关的一切内容,为网友搜罗最有价值的网站源码下载与技术教程等服务!

服务目录
  • 金点OpenAPI
  • 金点云
  • 金点支付
友情链接
  • 数媒派
  • 国家电网
快速搜索

本站由Nice强力驱动

声明: 本站部分内容属于原创转载请注明出处 如有侵权行为请严格参照本站【版权声明】与我们联系,我们将在48小时内容进行处理!

本站部分内容属于原创转载请注明出处 如有侵权行为请严格参照本站【版权声明】与我们联系,我们将在48小时内容进行处理!
© 2016-2023 PipBest.Com - 金点网络 & 金点部落. All rights reserved 京ICP备2022005359号-1
  • 关注有礼
  • 签到
  • 客服
    官方QQ群 常见问题 FAQ

    在线客服

    点我联系

    直接说出您的需求!
    切记!带上资源连接与问题!

    工作时间: 9:30-21:30

  • 暗黑
    模式
  • 全屏
  • 投稿
    赚钱
  • 首页

  • 签到

  • 切换

  • 客服

金点网络-全网资源,一网打尽
  • 登录
  • 注册
or
or
忘记密码?
金点网络-全网资源,一网打尽
  • 网站首页 ►
    • 金点部落
    • 小游戏
    • OpenAPI
    • 设计资产导航
    • 升级会员
  • 技能学习 ►
    • 体育运动
    • 办公教程
    • 口才演讲
    • 小吃技术
    • 建站教程
    • 摄影教程
    • 棋牌教程
    • 网赚教程 ►
      • 爆粉引流
      • 自媒体
      • 贴吧引流
  • 网站源码 ►
    • 商城/淘客/交易
    • 小说/漫画/阅读
    • 影视/音乐/视频
    • 微信/微商/微擎
    • 理财/金融/货币
    • 模板/主题/插件
  • 游戏源码 ►
    • 精品网单
    • 端游源码
    • 手游源码
    • 页游源码
  • 素材资料 ►
    • 电子文档
    • 综合资料
    • 考研资料
    • 设计素材
    • 音频讲座 ►
      • 人文艺术
      • 名师讲座
      • 说书小说
  • 软件工具 ►
    • Windows软件
    • MacOS软件
    • Android软件
  • 寄售资源
    ►
    • 游戏源码
    • 网站源码
    • 软件源码
  • 公益服
×
u3** 刚刚下载了 爆款吸金文案训练

    全网资源·一网打尽

  • 金点出品,必属精品!
  • 发布原创内容,获取高额提成!
  • 我们与你共创美好数字生态!
  • 无特殊说明密码默认:pipbest.com