数据分析(一)Matplotlib

本文介绍了Python数据可视化库Matplotlib,包括Matplotlib的基本概念、为何使用它,以及常用设置如折线图、坐标轴、子图、图例、散点图、条形图和直方图的绘制。此外,还详细讲解了线条样式和颜色的选择,帮助读者掌握数据图表的创建技巧。
摘要由CSDN通过智能技术生成

一.Matplotlib简介

1.什么是matplotlib?

matplotlib:最流行的Python底层绘图库,主要做数据可视化图表。

2.为什么要学matplotlib?

  • 能将数据进行可视化,更直观的呈现
  • 使数据更加客观、更具说服力

3.matplotlib基本要点

在这里插入图片描述

二.Matplotlib 常用设置

1.基本折线图绘制

import random
from matplotlib import pyplot as plt

x = range(2, 26, 2)
y = [random.randint(10, 30) for i in range(12)]

# 设置图形的大小
plt.figure(figsize=(20, 8), dpi=100)
# 传递x和y的值
plt.plot(x, y)
# x轴和y轴显示的范围
plt.xticks(x[:])
plt.yticks(range(min(y), max(y)+1))

plt.show()

在这里插入图片描述

2.设置坐标轴含义

import random
from matplotlib import pyplot as plt, font_manager
import matplotlib

myfont = font_manager.FontProperties(fname='/usr/share/fonts/cjkuni-uming/uming.ttc', size=12)
titlefont = font_manager.FontProperties(fname='/usr/share/fonts/cjkuni-uming/uming.ttc', size=32, weight=True)

y = [random.randint(20, 35) for i in range(120)]
x = range(0, 120)
plt.figure(figsize=(10, 5), dpi=100)
plt.plot(x, y)

plt.xlabel('时间', fontproperties=myfont)
plt.ylabel('温度(摄氏度)', fontproperties=myfont)
plt.title('10点到12点每分钟的时间变化情况', fontproperties=myfont)
plt.show()

在这里插入图片描述

3.绘制线性函数

from matplotlib i
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值