一、matplotlib.pyplot绘图相关对象
1、容器类:图(figure)、坐标系(axes)、坐标轴(axis)、刻度(tick)
2、基础类:线(line)、点(marker)、文本(text)、图例(legend)、网格(grid)、标题(title)
二、绘图的类型
1、线形图:plot()
2、直方图:hist()
3、条形图:bar()
4、饼图:pie()
5、散点图:scatter()
6、3D图:from mpl_toolkits.mplt3d import Axes3d
7、动态交互图:pyecharts
一、首先要检测环境
源码:
pip show matplotlib
输出:
Name: matplotlib
Version: 3.5.2
Summary: Python plotting package
Home-page: https://matplotlib.org
Author: John D. Hunter, Michael Droettboom
Author-email: matplotlib-users@python.org
License: PSF
Location: c:\users\administrator\anaconda3\lib\site-packages
Requires: cycler, fonttools, kiwisolver, numpy, packaging, pillow, pyparsing, python-dateutil
Required-by: seaborn
Note: you may need to restart the kernel to use updated packages.
二、导入第三方库
-
import matplotlib.pyplot as plt #导入第三方数据可视化库matplotlib中的pyplot绘图模块
-
import numpy as np #导入科学计算库,别名为np
三、不同绘图类型
1、线型图(plot)
源码:
绘制平行四边形
源码:
输出:
同一绘图区域绘制多图
源码:
多区域绘图
源码:
综合示例
源码:
直方图(hist)
源码:
条形图 (bar)
源码:
输出:
饼图(pie)
源码:
输出:
散点图(scatter)
源码:
输出:
3D图
源码 :
输出: