文章目录
什么是 matplotlib
为什么要学习matplotlib
- 能够将数据进可视化,更直观的呈现
- 是数据更加客观,更具说服力
什么是matplotlib
matplotlib:最流行的Python底层绘图库,主要做数据可视化图表,名字取材于MATLAB,模仿MATLAB构建
matplotlib基本要点



Matplotlib 常用设置(折线图)

设置图片大小

调整 x 轴或者 y 轴上的刻度

设置中文显示

常用的统计图

散点图

import random
from matplotlib import pyplot as plt
from matplotlib.font_manager import FontProperties
"""
绘制10月和三月温度变化的散点图
"""
# 字体设置
myfont = FontProperties(fname="/usr/share/fonts/wqy-microhei/wqy-microhei.ttc", size=14)
titlefont = FontProperties(fname="/usr/share/fonts/wqy-microhei/wqy-microhei.ttc", size=25)
# x轴和Y轴数据
march_y = [random.randint(10, 20) for i in range(31)]
october_y = [random.randint(20, 30) for j in range(31)]
x = range(1, 32) # 1, 2, 3, ...31
# 设置图形大小
plt.figure(figsize=(10, 5), dpi=100)
# 绘制散点图
plt.subplot(2, 1, 1)
plt.scatter(x, march_y, )
# 调整刻度
_x3_labels = ["3月{}日".format(_) for _ in x]
# rotation: 旋转
plt.xticks(x[::3], labels=_x3_labels[::3], fontproperties=myfont, rotation=45)
# x, y和标题的说明
plt.xlabel("月份", fontproperties

Matplotlib是Python中最流行的底层绘图库,用于数据可视化。本文介绍了matplotlib的基础知识,包括为何学习它,如何设置图片大小、调整轴刻度及显示中文。还详细讲解了散点图、条形图(单个和多个)以及直方图(普通和科学分组)的绘制方法,帮助读者更好地将数据转化为直观的图表。

3437

被折叠的 条评论
为什么被折叠?



