Python Matplotlib库安装与基本作图示例
作者:memoryqiu 时间:2021-09-01 04:22:51
本文实例讲述了Python Matplotlib库安装与基本作图。分享给大家供大家参考,具体如下:
不论是数据挖掘还是数据建模,都免不了数据可视化的问题。对于Python来说,Matplotlib是著名的绘图库,它主要用于二维绘图,简单的三维绘图。
安装Matplotlib
通过pip安装Matplotlib步骤:
在cmd窗口下,进入到pip安装目录,在命令提示符中依次输入
python -m pip install -U pip setuptools
python -m pip install matplotlib
Matplotlib作图的基本代码
>>> import numpy as np
>>> import matplotlib.pyplot as plt #导入matplotlib
>>> x=np.linspace(0,10,1000) #作图的自变量x
>>> y=np.sin(x)+1 #自变量y
>>> z=np.cos(x**2)+1 #自变量z
>>> plt.figure(figsize=(8,4)) #设置图像大小
>>> plt.plot(x,y,label='$\sin x+1$',color='red',linewidth=2) #设置标签,线条颜色、大小
>>> plt.plot(x,z,'b--',label='$\cos x^2+1$') #设置线条类型,标签
>>> plt.xlabel('times(s)') #x轴名称
>>> plt.ylabel('volt') #y轴名称
>>> plt.title('a simple example') #标题
>>> plt.ylim(0,2.2) #显示的y轴范围
>>> plt.legend() #显示图例
>>> plt.show()
这里使用Python3.6环境cmd窗口运行效果如下:
绘制的图形如下:
希望本文所述对大家Python程序设计有所帮助。
来源:https://blog.csdn.net/sinat_25873421/article/details/80562114
标签:Python,Matplotlib库
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java使用正则表达式验证用户名和密码的方法
2023-06-13 18:05:56
解决python DataFrame 打印结果不换行问题
2023-11-20 23:12:25
![](https://img.aspxhome.com/file/2023/4/84084_0s.jpg)
iis、apache与nginx禁止目录执行asp、php脚本的实现方法
2023-10-14 11:30:26
![](https://img.aspxhome.com/file/2023/7/64587_0s.gif)
跟老齐学Python之总结参数的传递
2021-12-16 18:17:24
pd.read_csv读取文件路径出现的问题解决
2022-03-16 06:12:53
![](https://img.aspxhome.com/file/2023/9/86499_0s.png)
Python实现合成多张图片到PDF格式
2023-02-26 04:57:25
![](https://img.aspxhome.com/file/2023/2/77912_0s.jpg)
实现asp长文章自动分页插件
2011-02-26 13:51:00
如何限制上传文件的大小?
2010-06-09 18:47:00
Python实现将Excel转换成xml的方法示例
2023-01-19 23:02:53
一篇文章带你了解python标准库--random模块
2023-09-18 10:45:34
![](https://img.aspxhome.com/file/2023/6/83836_0s.png)
如何使Python中的print()语句运行结果不换行
2023-08-03 18:22:54
W3C优质网页小贴士(二)
2008-04-07 12:14:00
Python+Tkinter制作猜灯谜小游戏
2021-09-24 19:43:17
![](https://img.aspxhome.com/file/2023/7/66887_0s.gif)
使用Python监控文件内容变化代码实例
2021-06-05 22:45:19
Python内置数据类型中的集合详解
2022-07-13 04:06:38
![](https://img.aspxhome.com/file/2023/3/95413_0s.png)
基于python的BP神经网络及异或实现过程解析
2021-10-29 00:02:01
![](https://img.aspxhome.com/file/2023/8/72778_0s.jpg)
用 Python 脚本实现电脑唤醒后自动拍照并截屏发邮件通知
2023-08-30 14:15:44
![](https://img.aspxhome.com/file/2023/5/62555_0s.png)
趣用文化元素
2009-09-03 11:53:00
![](https://img.aspxhome.com/file/UploadPic/20099/3/0909-using_culture_elements-01-12s.jpg)
页面表达常用方式
2010-05-27 12:42:00
![](https://img.aspxhome.com/file/UploadPic/20105/27/01-93s.jpg)
Python字典简介以及用法详解
2023-12-05 04:23:52
![](https://img.aspxhome.com/file/2023/9/88039_0s.png)