Python_散点图与折线图绘制
在数据分析的过程中,经常需要将数据可视化,目前常使用的:散点图 折线图
需要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_散点图与折线图绘制的更多相关文章
- Qt数据可视化(散点图、折线图、柱状图、盒须图、饼状图、雷达图)开发实例
目录 散点图 折线图 柱状图 水平柱状图 水平堆叠图 水平百分比柱状图 盒须图 饼状图 雷达图 Qt散点图.折线图.柱状图.盒须图.饼状图.雷达图开发实例. 在开发过程中我们会使用多各种各样的图 ...
- python 绘图---2D、3D散点图、折线图、曲面图
python中绘制2D曲线图需要使用到Matplotlib,Matplotlib 是一个 Python 的 2D绘图库,它以各种硬拷贝格式和跨平台的交互式环境生成出版质量级别的图形,通过 Matplo ...
- qt外部数据传入实现动态的折线图绘制
在嵌入式开发中,实现数据收集与显示很常见,对于希望数据稳定的应用来说, 折现图的表现形式很符合条件. 本实现是通过qt的signal-slot来 ...
- [Python Study Notes]折线图绘制
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- JAVA Swing使用JFreeChart实现折线图绘制
效果如下: 实现步骤: 1.导入JAR包 jfreechart官网下载的zip文件中包含这两个jar包 2.代码编写 import org.jfree.chart.ChartFactory; impo ...
- matplotlib常见绘图基础代码小结:折线图、散点图、条形图、直方图、饼图
一.折线图 二.散点图 三.条形图 四.直方图 五.饼图 一.折线图折线图用于显示随时间或有序类别的变化趋势 from matplotlib import pyplot as plt x = rang ...
- Matplotlib数据可视化(4):折线图与散点图
In [1]: from matplotlib import pyplot as plt import numpy as np import matplotlib as mpl mpl.rcParam ...
- OpenGL——折线图柱状图饼图绘制
折线图绘制代码: #include<iostream> //旧版本 固定管线 #include<Windows.h> #include <GL/glut.h> // ...
- R in action读书笔记(15)第十一章 中级绘图 之二 折线图 相关图 马赛克图
第十一章 中级绘图 本节用到的函数有: plot legend corrgram mosaic 11.2折线图 如果将散点图上的点从左往右连接起来,那么就会得到一个折线图. 创建散点图和折线图: &g ...
随机推荐
- js数组增删元素
操作数组的方法 push() 结尾添加 数组.push(元素) 参数 描述 newelement1 必需.要添加到数组的第一个元素. newelement2 可选.要添加到数组的第二个元素. newe ...
- EventBus 消息的线程切换模型与实现原理
一. 序 EventBus 是一个基于观察者模式的事件订阅/发布框架,利用 EventBus 可以在不同模块之间,实现低耦合的消息通信. EventBus 因为其使用简单且稳定,被广泛应用在一些生产项 ...
- 如何在spingboot项目中自定义自己的配置
在实际开发中,为了方便我们常常会考虑把配置文件的某一类配置映射到配置类上,方便spring容器加载,实现方法如下: 1. 书写配置文件信息:书写某一类特定字段开头的配置信息,例如在yml配置文件中可以 ...
- Java第三次作业第五题
5. [问题描述]Fibonacci序列处理 从文件in.txt中读取第一个数作为Fibonacci数列的开始数n,读取第二个数,作为需要写入的数的个数m. 将从n开始的m个Fibonacci数列写入 ...
- Day4 文件管理-常用命令
文件管理 --> 创建 移动 删除 复制 1.cp复制: #####-v:详细显示命令执行的操作 #####-r: 递归处理目录与子目录 #####-p: 保留源文件或目录的属性 #####1. ...
- 07 (OC)* XIB原理和Xib、storyBoard、代码的优缺点
1:可读性 2:可视化界面.立马看到 3:开发速度. 4:复用性 5:维护性差 本质 编译时对xml文件做了如下操作1,读取xml文件,生成所有界面对象,生成所有object(即自定义的control ...
- Java连载33-对象的创建和使用、内存分析
一.创建一个学生类 每个学生都有学号信息,但是每一个学生的学号都是不同的,所以要访问这个学号必须先创建对象,通过对象去访问学号信息,学号信息不能直接通过“类”去访问,所以这种成员变量又被称为“实例变量 ...
- java httpclient跳过https证书验证
httpclien调用skipHttpsUtil得wrapClient方法跳过https证书验证 SkipHttpsUtil skipHttpsUtil=new SkipHttpsUtil(); ...
- Mysql学习笔记整理之引擎
mysql的引擎: myisam引擎 Mysql 5.5之前默认的存储引擎 数据.索引分别存储 (数据物理磁盘---索引物理磁盘) .MYD 存储数据 表级索 ...
- 第六届蓝桥杯java b组第五题
九数组分数 1,2,3…9 这九个数字组成一个分数,其值恰好为1/3,如何组法? 下面的程序实现了该功能,请填写划线部分缺失的代码. public class A { public static vo ...