• Python_散点图绘制


    为了可视化一些数据分布,需要以散点图的形式呈现

    引入绘图工具

    1 import matplotlib.pyplot as plt
    2 from matplotlib.font_manager import FontProperties

    单一数据的散点图

     1 def DrawScatter(VolumeListY, pic_name):
     2 #    绘制两组数据的散点图
     3    plt.figure(figsize=(15, 5), dpi=300)
     4    ax = plt.subplot(111)
     5    # 导入中文字体,及字体大小
     6    zhfont = FontProperties(fname='C:/Windows/Fonts/simsun.ttc', size=20)
     7   ax.scatter(range(1, len(VolumeListY) + 1), VolumeListY, marker='o', s=1, facecolors='none', edgecolors='b')
     8    plt.xlabel(u'x坐标', fontproperties=zhfont)
     9    plt.ylabel(u'y坐标', fontproperties=zhfont)
    10    plt.title(u'中文标题', fontproperties=zhfont)
    11    # 设定 坐标轴的取值范围
    12    # plt.axis([1000, 2500, 50, 60])
    13    # 以当前时间命名图片
    14    # 保存图片到当前文件夹
    15    imgname = '.\'+ pic_name + '.png'
    16    plt.savefig(imgname, bbox_inches = 'tight')
    17    # 显示图像
    18    plt.show()

    两种数据绘制散点图

     1 def DrawScatter(BeltListY, VolumeListY, pic_name):
     2 #    绘制两组数据的散点图
     3    plt.figure(figsize=(15, 5), dpi=300)
     4    ax = plt.subplot(111)
     5    # 导入中文字体,及字体大小
     6    zhfont = FontProperties(fname='C:/Windows/Fonts/simsun.ttc', size=20)
     7    p1 = ax.scatter(range(1, len(VolumeListY) + 1), VolumeListY, marker='o', s=1, facecolors='none', edgecolors='b')
     8    p2 = ax.scatter(range(1, len(BeltListY) + 1), BeltListY, marker='o', s=1, facecolors='none', edgecolors='b')
     9    plt.xlabel(u'x坐标', fontproperties=zhfont)
    10    plt.ylabel(u'y坐标', fontproperties=zhfont)
    11    plt.title(u'中文标题', fontproperties=zhfont)
    12    #定义两种数据标签
    13    ax.legend((p1, p2), (u'数据1',u'数据2'), loc='upper right', prop=zhfont)
    14    # 设定 坐标轴的取值范围
    15    # plt.axis([1000, 2500, 50, 60])
    16    # 保存图片到当前文件夹
    17     imgname = '.\'+ pic_name + '.png'
    18    plt.savefig(imgname, bbox_inches = 'tight')
    19    # 显示图像
    20    plt.show()
  • 相关阅读:
    13.Query for Null or Missing Fields-官方文档摘录
    海南IT互联网招聘数据简单分析
    Mongo Spark Connector中的分区器(一)
    一、Golang中的反射基本使用
    Golang中的sync.Pool对象
    Golang中的内置函数
    golang单元测试简述
    Spark Streaming数据限流简述
    Golang中类面向对象特性
    在Docker中跑Hadoop与镜像制作
  • 原文地址:https://www.cnblogs.com/wangxiaobei2019/p/11578246.html
Copyright © 2020-2023  润新知