Matplotlib 中最重要的一个模块应该就是 matplotlib.pyplot
了,里边包括了几乎所有普通用户需要调用的功能。
另外 numpy
作为一个多维数组/矩阵的模块,也经常和 Matplotlib 一起被使用
matplotlib 官方建议在引用这两个库的时候,使用如下语法:
import matplotlib.pyplot as plt
import numpy as np
plt.plot(x1, y1, '样式1', x2, y2, '样式2', x3, y3, '样式3', ...)
用于绘制折线图。
其中 xn、yn 为第 n 条曲线的 x、y 的值(n = 1, 2, 3, …)
样式n 为每个曲线的样式,本篇暂不做介绍。
返回值是一个数组,其中每个元素都是绘制的曲线。
plt.loglog(*args, **kwargs)
用于绘制折线图,与 plot 的区别在于 x 轴和 y 轴都是指数型的。
重要参数:
basex, basey: x、y 轴的底,需要大于 1
plt.semilogx(*args, **kwargs)
和 plt.semilogy(*args, **kwargs)
用于绘制折线图,两个函数的 x 轴、y 轴分别是指数型的。
支持 plot 函数的所有参数,分别有一个重要参数:
plt.step(x, y, *args, data=None, **kwargs)
类似 plot 函数,但是曲线是阶梯状的。
重要参数:
where: pre、post 或 mid,即数据点处于阶梯的右侧、左侧还是正中
plt.plot_date(z, y, tz, xdate, ydate)
与 plot 类似,可以把总坐标/横坐标当做 matplotlib.dates 类型数据来处理
plt.errorbar(x, y, yerr=None, xerr=None, lolims=False, uplims=False, xlolims=False, xuplims=False, **kwargs)
用于绘制带有 误差线的折线图。
重要参数:
plt.bar(x, height, width=0.8, bottom=0, *args, **kwargs)
柱状图,重要参数:
height 一次为一个一维的数组。
如果柱状图希望叠加(如下图),可以多次调用 bar 函数。
plt.barh(*args, **kwargs)
与 plt.bar()
函数类似,不过是水平方向的。
重要参数:
plt.fill_between(x, y1, y2=0, where=None, interpolate=False, step=None, hold=None, data=None, **kwargs)
y1 和 y2 之间进行填充。
重要参数:
plt.fill_betweenx(y, x1, x2=0, where=None, step=None, interpolate=False, hold=None, data=None, **kwargs)
与 plt.fill_betwwen()
函数类似,但是是进行水平方向,即 x1 和 x2 之间填充。
重要参数:
stackplot(x, *args, **kwargs)
绘制多层图,或称堆叠式图区。
重要参数:
plt.fill(*args, **kwargs)
填充一个个的多边形,调用方式如下:
ax.fill(x, y[, 样式描述字符串]) # x 和 y 分别是某一个多边形的横、纵坐标数组
ax.fill(x1, y2[, 样式描述字符串], x2, y2[, 样式描述字符串], x3, y3[, 样式描述字符串])
# 每对 xn、yn描述了一个多边形
plt.scatter(x, y, s=None, c=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None, *, data=None, **kwargs)
二维的散点图,重要参数:
stem([x,] y, linefmt=None, markerfmt=None)
散点的杆图
重要参数:
plt.eventplot(positions, orientation='horizontal', lineoffsets=1, linelengths=1, linewidths=None, colors=None, linestyles='solid', hold=None, data=None, **kwargs)
类似蛋白质电泳图,每个数据点将被绘制成一根数据线。
重要参数:
plt.broken_barh(xranges, yrange, hold=None, data=None, **kwargs)
效果上和泳道图有类似之处。
重要参数:
plt.pie(x, explode=None, labels=None, colors=None, autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1, startangle=None, radius=None, counterclock=True, wedgeprops=None, textprops=None, center=(0, 0), frame=False, rotatelabels=False, hold=None, data=None)
绘制饼图。
重要参数:
系列文章:
matplotlib 使用简明教程(一)-基础概念:
https://blog.csdn.net/fenghuizhidao/article/details/79352882
matplotlib 使用简明教程(二)-常用图表
https://blog.csdn.net/fenghuizhidao/article/details/83090043
matplotlib 使用简明教程(三)-一些专业图表简介
https://blog.csdn.net/fenghuizhidao/article/details/83090165
matplotlib 使用简明教程(四)-辅助性元件
https://blog.csdn.net/fenghuizhidao/article/details/83090249
matplotlib 使用简明教程(五)-画布、图表、元素基础操作
https://blog.csdn.net/fenghuizhidao/article/details/83090320
matplotlib 使用简明教程(六)-图像、动画相关
https://blog.csdn.net/fenghuizhidao/article/details/83090512
matplotlib 使用简明教程(七)-样式定义
https://blog.csdn.net/fenghuizhidao/article/details/83090553