【数据分析】数据分析之matplotlib绘制折线图 No.1

一、matplotlib安装

pip install matplotlib

二、matplotlib

1、什么是matplotlib

  最流行的python底层绘图库,主要做数据可视化图表,名字取自matlab,模仿matlab构建。

(1)将数据进行可视化,更直观的呈现

(2)使数据更加客观、更具说服力

2、matplotlib基本要点

Axis坐标轴,x轴,y轴,坐标(x,y)。

3、使用

 

 

# 1

font = {'family': '微软雅黑',
       
'weight': 'bold',
       
'size': 12}
matplotlib.rc(
'font', **font)

# 2

from matplotlib import pyplot as plt
import random
import matplotlib


def plt_data():
    x = [i for i in range(2, 26, 2)]
    y_1 = [random.uniform(10, 40) for i in range(0, 12)]
    y_2 = [random.uniform(10, 40) for i in range(0, 12)]

    # 图片大小
    plt.figure(figsize=(8, 6), dpi=80)
    # plt.xticks(x)
    # 设置字体
    # 第一种
    font = {'family': '微软雅黑',
            'weight': 'bold',
            'size': 12}
    matplotlib.rc('font', **font)

    # # 第二种
    # matplotlib.font_manager.FontProperties(fname="C:\\Windows\\Fonts\\")

    _x = ["hello, {}".format(i) for i in range(2, 26, 2)]

    # 刻度
    plt.xticks(x, _x, rotation=45)
    plt.yticks([i for i in range(10, 41)][::3])

    # 添加描述信息
    plt.xlabel("datetime")
    plt.ylabel("temperature")


    # 绘制折线图多条
    plt.plot(x, y_1, label="2019")
    plt.plot(x, y_2, label="2020")

    # 显示网格
    plt.grid(alpha=0.2)

    # 添加图例
    plt.legend()

    # 展示图片
    plt.show()

    return None


if __name__ == "__main__":

    plt_data()

执行结果展示

三、常用统计图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

C-Jonn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值