在数据分析的过程中,经常需要将数据可视化,目前常使用的:散点图  折线图

需要import的外部包  一个是绘图 一个是字体导入

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

在数据处理前需要获取数据,从TXT  XML csv excel 等文本中获取需要的数据,保存到list

 def GetFeatureList(full_path_file):
file_name = full_path_file.split('\\')[-1][0:4]
# print(file_name)
# print(full_name)
K0_list = []
Area_list = []
all_lines = []
f = open(full_path_file,'r')
all_lines = f.readlines()
lines_num = len(all_lines)
# 数据清洗
if lines_num > 5000:
for i in range(3,lines_num-1):
temp_k0 = int(all_lines[i].split('\t')[1])
if temp_k0 == 0:
K0_list.append(ComputK0(all_lines[i]))
else:
K0_list.append(temp_k0)
Area_list.append(float(all_lines[i].split('\t')[15]))
# K0_Scatter(K0_list,Area_list,file_name)
else:
print('{} 该样本量少于5000'.format(file_name))
return K0_list, Area_list,file_name

绘制两组数据的散点图,同时绘制两个散点图,上下分布在同一个图片中

 def K0_Scatter(K0_list, area_list, pic_name):
plt.figure(figsize=(25, 10), dpi=300)
# 导入中文字体,及字体大小
zhfont = FontProperties(fname='C:/Windows/Fonts/simsun.ttc', size=16)
ax = plt.subplot(211)
# print(K0_list)
ax.scatter(range(len(K0_list)), K0_list, c='r', marker='o')
plt.title(u'散点图', fontproperties=zhfont)
plt.xlabel('Sampling point', fontproperties=zhfont)
plt.ylabel('K0_value', fontproperties=zhfont)
ax = plt.subplot(212)
ax.scatter(range(len(area_list)), area_list, c='b', marker='o')
plt.xlabel('Sampling point', fontproperties=zhfont)
plt.ylabel(u'大小', fontproperties=zhfont)
plt.title(u'散点图', fontproperties=zhfont)
# imgname = 'E:\\' + pic_name + '.png'
# plt.savefig(imgname, bbox_inches = 'tight')
plt.show()

散点图显示

绘制一个折线图 每个数据增加标签

 def K0_Plot(X_label, Y_label, pic_name):
plt.figure(figsize=(25, 10), dpi=300)
# 导入中文字体,及字体大小
zhfont = FontProperties(fname='C:/Windows/Fonts/simsun.ttc', size=16)
ax = plt.subplot(111)
# print(K0_list)
ax.plot(X_label, Y_label, c='r', marker='o')
plt.title(pic_name, fontproperties=zhfont)
plt.xlabel('coal_name', fontproperties=zhfont)
plt.ylabel(pic_name, fontproperties=zhfont)
# ax.xaxis.grid(True, which='major')
ax.yaxis.grid(True, which='major')
for a, b in zip(X_label, Y_label):
str_label = a + str(b) + '%'
plt.text(a, b, str_label, ha='center', va='bottom', fontsize=10)
imgname = 'E:\\' + pic_name + '.png'
plt.savefig(imgname, bbox_inches = 'tight')
# plt.show()

绘制多条折线图

 def K0_MultPlot(dis_name, dis_lsit, pic_name):
plt.figure(figsize=(80, 10), dpi=300)
# 导入中文字体,及字体大小
zhfont = FontProperties(fname='C:/Windows/Fonts/simsun.ttc', size=16)
ax = plt.subplot(111)
X_label = range(len(dis_lsit[1]))
p1 = ax.plot(X_label, dis_lsit[1], c='r', marker='o',label='Euclidean Distance')
p2 = ax.plot(X_label, dis_lsit[2], c='b', marker='o',label='Manhattan Distance')
p3 = ax.plot(X_label, dis_lsit[4], c='y', marker='o',label='Chebyshev Distance')
p4 = ax.plot(X_label, dis_lsit[5], c='g', marker='o',label='weighted Minkowski Distance')
plt.legend()
plt.title(pic_name, fontproperties=zhfont)
plt.xlabel('coal_name', fontproperties=zhfont)
plt.ylabel(pic_name, fontproperties=zhfont)
# ax.xaxis.grid(True, which='major')
ax.yaxis.grid(True, which='major')
for a, b,c in zip(X_label, dis_lsit[5],dis_name):
str_label = c + '_'+ str(b)
plt.text(a, b, str_label, ha='center', va='bottom', fontsize=5)
imgname = 'E:\\' + pic_name + '.png'
plt.savefig(imgname,bbox_inches = 'tight')
# plt.show()

图形显示还有许多小技巧,使得可视化效果更好,比如坐标轴刻度的定制,网格化等,后续进行整理

Python_散点图与折线图绘制的更多相关文章

  1. Qt数据可视化(散点图、折线图、柱状图、盒须图、饼状图、雷达图)开发实例

    ​  目录 散点图 折线图 柱状图 水平柱状图 水平堆叠图 水平百分比柱状图 盒须图 饼状图 雷达图 Qt散点图.折线图.柱状图.盒须图.饼状图.雷达图开发实例. 在开发过程中我们会使用多各种各样的图 ...

  2. python 绘图---2D、3D散点图、折线图、曲面图

    python中绘制2D曲线图需要使用到Matplotlib,Matplotlib 是一个 Python 的 2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形,通过 Matplo ...

  3. qt外部数据传入实现动态的折线图绘制

    在嵌入式开发中,实现数据收集与显示很常见,对于希望数据稳定的应用来说,               折现图的表现形式很符合条件.               本实现是通过qt的signal-slot来 ...

  4. [Python Study Notes]折线图绘制

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...

  5. JAVA Swing使用JFreeChart实现折线图绘制

    效果如下: 实现步骤: 1.导入JAR包 jfreechart官网下载的zip文件中包含这两个jar包 2.代码编写 import org.jfree.chart.ChartFactory; impo ...

  6. matplotlib常见绘图基础代码小结:折线图、散点图、条形图、直方图、饼图

    一.折线图 二.散点图 三.条形图 四.直方图 五.饼图 一.折线图折线图用于显示随时间或有序类别的变化趋势 from matplotlib import pyplot as plt x = rang ...

  7. Matplotlib数据可视化(4):折线图与散点图

    In [1]: from matplotlib import pyplot as plt import numpy as np import matplotlib as mpl mpl.rcParam ...

  8. OpenGL——折线图柱状图饼图绘制

    折线图绘制代码: #include<iostream> //旧版本 固定管线 #include<Windows.h> #include <GL/glut.h> // ...

  9. R in action读书笔记(15)第十一章 中级绘图 之二 折线图 相关图 马赛克图

    第十一章 中级绘图 本节用到的函数有: plot legend corrgram mosaic 11.2折线图 如果将散点图上的点从左往右连接起来,那么就会得到一个折线图. 创建散点图和折线图: &g ...

随机推荐

  1. Django之模型层(2)

    Django之模型层(2) 一.创建模型 实例:我们来假定下面这些概念,字段和关系. 作者模型:一个作者由姓名和年龄. 作者详细模型:把作者的详情放到详情表,包含生日,手机号,家庭住址等信息.作者详情 ...

  2. centos7 下安装mysql5.7 数据库并使用nevicat连接数据库

    安装mysql5.7的教程: https://www.cnblogs.com/yybrhr/p/9810375.html 遇到的问题: 无法连接,到阿里云服务器安全组设置3306端口

  3. 微信支付中分账功能 填坑指南V1

    公司是做电商的,近期开发了一款小程序,准备线上线下同步销售玩具.这里就涉及到微信支付的功能,网上有很多教程,官方也有文档和Demo,因此微信支付还是比较容易实现的. 由于我们公司是和其他公司合作运营的 ...

  4. 简说Python发展及其就业前景

    简说python 发展历史 Python是著名的"龟叔"Guido van Rossum在1989年圣诞节期间,为了打发无聊的圣诞节而编写的一个编程语言. python从ABC语言 ...

  5. Jenkins把GitHub项目做成Docker镜像

    本文是<Jenkins流水线(pipeline)实战>系列的第三篇,前面已对Jenkins流水线有了基本认识,也试过从GitHub下载pipeline脚本并执行,今天的实战是编写一段pip ...

  6. ssh免密码登陆(集群多台机器之间免密码登陆)

    1. 首先在配置hosts文件(每台机器都要) 进入root权限 vi /etc/hosts 添加每台机器的ip + 主机名,例如: 172.18.23.201 hadoop1 172.18.23.1 ...

  7. Linux初识之Centos7中terminal光标位置偏移问题的解决

    新安装的centos7打开terminal发现光标位置向右偏移,使用起来影响感官,经查询后找到类似情况并顺利解决问题,特记录解决过程以作参考. 1.未解决时光标向右偏移显示: 2.打开设置(Setti ...

  8. Centos6安装MySQL5.7(yum方式)

    1. 下载并安装用来配置mysql的yum源的rpm包 # 下载 wget http://repo.mysql.com/mysql57-community-release-el6-10.noarch. ...

  9. 整理总结 python 中时间日期类数据处理与类型转换(含 pandas)

    我自学 python 编程并付诸实战,迄今三个月. pandas可能是我最高频使用的库,基于它的易学.实用,我也非常建议朋友们去尝试它.--尤其当你本身不是程序员,但多少跟表格或数据打点交道时,pan ...

  10. Spotlight性能监控工具的配置及使用

    这是我离线整理资料里的内容,大概是2012年时候开始使用此性能监控工具的,直到至今,接触到几个性能监控工具里,还是美国quest公司生产的Spotlight此产品相对比较牛! 我也不知道现在发展到能支 ...