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

需要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. Git客户端下载

    链接:http://pan.baidu.com/s/1eRXsITO 密码:4i6e

  2. CTC安装错误之:binding.cpp:6:29: fatal error: torch/extension.h: No such file or directory

    错误原因:该问题主要由于CTC的版本导致. 解决方法: 在终端打开warp-ctc文件夹: cd warp-ctc 然后:git checkout ac045b6072b9bc3454fb9f9f17 ...

  3. MOOC 数据库系统笔记(二):数据库系统的基本结构及其演变发展

    数据库系统的结构抽象与演变 数据库的标准结构 DBMS管理数据的三个层次 1.External Level = User Level 某一用户能够看到与处理的数据,全局数据中的某一部分 2.Conce ...

  4. C#基础知识总结(二)--泛型

    什么是泛型 我们在编写程序时,经常遇到两个模块的功能非常相似,只是一个是处理int数据,另一个是处理string数据,或者其他自定义的数据类型,但我们没有办法,只能分别写多个方法处理每个数据类型,因为 ...

  5. [Spark] 03 - Programming

    写在前面 ETL Pipeline 学习资源 Ref: 使用 AWS Glue 和 Amazon Athena 实现无服务器的自主型机器学习 Ref: AWS Glue 常见问题 Extract is ...

  6. Mysql学习笔记整理之数据库优化

    数据库性能瓶颈的原因 数据库连接数 数据量大 硬件资源限制 数据性能优化方案 sql优化       2.缓存        3.建好索引    4.读写分离        5. 分库分表 慢日志查  ...

  7. 2018年蓝桥杯java b组第六题

    标题:递增三元组 给定三个整数数组A = [A1, A2, ... AN], B = [B1, B2, ... BN], C = [C1, C2, ... CN],请你统计有多少个三元组(i, j, ...

  8. Linux-----centos6.2---安装Linux的流程

      1.安装命令 # yum install mysql-server mysql 2.查看是否安装正确 # chkconfig --list mysqld 3.启动 (1).启动服务: # serv ...

  9. Flume和Kafka完成实时数据的采集

    Flume和Kafka完成实时数据的采集 写在前面 Flume和Kafka在生产环境中,一般都是结合起来使用的.可以使用它们两者结合起来收集实时产生日志信息,这一点是很重要的.如果,你不了解flume ...

  10. 03-body标签中的部分标签

    一.字体标签 标题标签h1-h6 h1定义最大的标题,h6定义最小的标题,一般一个页面中h1只能出现一次,尽量标题不要超过三级.h标签具有align属性,属性值分别是:left.center.righ ...