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

需要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. Jenkins流水线(pipeline)实战之:从部署到体验

    关于Jenkins流水线(pipeline) Jenkins 流水线 (pipeline) 是一套插件,让Jenkins可以实现持续交付管道的落地和实施. 关于blueocean Blue Ocean ...

  2. JAVA多线程高并发面试题总结

    ReadMe : 括号里的内容为补充或解释说明. 多线程和高并发是毕业后求职大厂面试中必问的知识点,自己之前总是面试前才去找相关的知识点面试题来背背,隔段时间又忘了,没有沉淀下来,于是自己总结了下相关 ...

  3. 基于 VMware 的超融合, 解析 vSAN 与 SmartX ZBS 的优劣差异

    在企业级IT领域从业多年,最近越来越多地听到圈内人谈论起超融合技术的种种好处.的确,超融合技术已越来越走向成熟,带来的价值也逐渐凸显.它可靠性高,资源消耗低,尤其是运维部署非常便捷.在企业基础架构领域 ...

  4. Linux 笔记 - 前三章 CentOS 简介、安装和远程连接

    博客地址:http://www.moonxy.com 一.Unix 和 Linux 的区别 目前主流的 Unix 系统有三种,分别是 IBM-AIX.HP-UX.SUN-Solaris,它们分别运行在 ...

  5. Falsk中的Request、Response

    Flask 中的Response 1.HTTPResponse('helloword') "helloword" from flask import Flask # 实例化Flas ...

  6. 大白话讲解 Java程序的运行机制和JVM

    据我们所知,Java程序是跨平台的.那么Java是如何实现跨平台的呢?看完下面几句话就会恍然大悟! 1.为什么Java语言既是编译型语言又是解释型语言呢? 答:运行Java程序,首先需要经过编译,编译 ...

  7. [sonarqube的使用] sonarqube安装

    一 . SonarQube代码质量检查工具简介 Sonar (SonarQube)是一个开源平台,用于管理源代码的质量 Sonar 不只是一个质量数据报告工具,更是代码质量管理平台 支持Java, C ...

  8. dom4j.jar下载

    下载地址: 链接:https://pan.baidu.com/s/16GCgCpaF7dc33pMbK2sTLg 密码:z444

  9. JMeter 压测Server Agent无法监控资源问题,PerfMon Metrics Collector报Waiting for sample,Error loading results file - see file log, Can't accept UDP connections java.net.BindException: Address already in use 各种疑难杂症

    如何安装插件此博主已经说得很详细了. https://www.cnblogs.com/saryli/p/6596647.html 但是需注意几点: 1.修改默认端口,这样可以避免掉一个问题.Serve ...

  10. 性能测试的基础知识--QPS和TPS

    基本概念: QPS:Queries Per Second意思是“每秒查询率” ,是一台服务器每秒能够相应的查询次数,是对一个特定的查询服务器在规定时间内所处理流量多少的衡量标准. TPS:Transa ...