python matplotlib画数据分布图_Python 数据分析(二):Matplotlib 绘图

python matplotlib画数据分布图_Python 数据分析(二):Matplotlib 绘图

1. 简介

Matplotlib 是 Python 提供的一个绘图库,通过该库我们可以很容易的绘制出折线图、直方图、散点图、饼图等丰富的统计图,安装使用 pip install matplotlib 命令即可,Matplotlib 经常会与 NumPy 一起使用。

在进行数据分析时,可视化工作是一个十分重要的环节,数据可视化可以让我们更加直观、清晰的了解数据,Matplotlib 就是一种可视化实现方式。

2. 绘图

下面我们来学习一下如何使用 Matplotlib 绘制常用统计图。

2.1 折线图

折线图可以显示随某一指标变化的连续数据。

2.1.1 单线

首先,我们来看一下如何使用 Matplotlib 绘制一个简单的折线图,具体实现如下:

from matplotlib import pyplot as pltx = range(1, 7)y = [13, 15, 14, 16, 15, 17]plt.title('折线图')plt.xlabel('x 轴')plt.ylabel('y 轴')plt.plot(x, y)plt.show()

看一下效果:

python matplotlib画数据分布图_Python 数据分析(二):Matplotlib 绘图

我们在使用中文时可能会现乱码的问题,可以通过如下方式解决:

① 下载 SimHei.ttf,下载地址为: https://download.csdn.net/download/ityard/12248458,放到 site-packages\matplotlib\mpl-data\fonts\ttf 目录下

② 到 site-packages\matplotlib\mpl-data 目录下找到 matplotlibrc 文件,并修改如下两项即可

font.sans-serif     : SimHei, DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serifaxes.unicode_minus  : False

我们还可以改变折线的样式、颜色等,通过示例来看一下。

from matplotlib import pyplot as pltx = range(1,

Original: https://blog.csdn.net/weixin_39634237/article/details/113630813
Author: weixin_39634237
Title: python matplotlib画数据分布图_Python 数据分析(二):Matplotlib 绘图

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/767787/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球