zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    蒟蒻的sb对拍方法
    LuoguP5176 公约数 题解
    天守阁的地板 题解
    Crash的数字表格 / JZPTAB 题解
    于神之怒加强版 简要题解
    最小公倍数之和 题解
    莫比乌斯反演的计算
    YY的GCD 题解
    acwing 309装饰围栏 大致思路 (预览)
    错排问题(预览)
  • 原文地址:https://www.cnblogs.com/wangxiaobei2019/p/11578246.html
Copyright © 2011-2022 走看看