matplotlib 画散点图


from matplotlib import pyplot as plt
import numpy as num
import pandas as pd
import random
# import tkinter as tk
from matplotlib import font_manager

my_font = font_manager.FontProperties(fname="C:\\Windows\\Fonts\\msyhl.ttc")

def mat_test():
    # 以下是你程序所使用的其他模块
    # 。。。。。。。。。。
    x_1 = range(2, 14)
    x_2 = range(22, 34)
    y_1 = [3, 5, 1, 1, 2, 5, 1, 2, 4, 3, 3, 1]
    y_2 = [1, 1, 2, 2, 6, 7, 9, 6, 7, 7, 5, 1]

    # 设置图片大小
    fig = plt.figure(figsize=(20, 8), dpi=80)
    # ->  figure 图形图标的意思 这里就是我们画的图 通过实例化figure 并且传入参数  我们可以在后台使用实例
    # ->  在图片模糊时可以传入dpi参数  让图片更加清晰
    # 绘图
    plt.scatter(x_1, y_1, label='3月份')
    plt.scatter(x_2, y_2, label='10月份')
    # 设置x 轴刻度
    _x = list(x_1) + list(x_2)
    _xtick_labels = ['3月{}日'.format(i) for i in x_1]
    _xtick_labels += ['10月{}日'.format(i) for i in x_2]
    plt.xticks(_x, _xtick_labels, fontproperties=my_font, rotation=45)
    # 设置图形信息
    plt.xlabel('时间', fontproperties=my_font)
    plt.ylabel('温度', fontproperties=my_font)
    plt.title('标题', fontproperties=my_font)
    plt.legend(prop=my_font)
    plt.savefig('./show.png')
    # 展示图形  此处由于tkinter原因无法展示
    # plt.show()


if __name__ == '__main__':
    mat_test()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值