python画散点图程序-Python散点图与折线图绘制过程解析
这篇文章主要介绍了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(' ')[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(' ')[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画散点图程序-Python散点图与折线图绘制过程解析相关推荐
- Python读取excel/csv表格并通过折线图可视化显示
Python读取excel/csv表格并通过折线图可视化显示 写作背景 参数 使用figure()函数重新申请一个figure对象 注意,每次调用figure的时候都会重新申请一个figure对象 第 ...
- 用python画大白_[Python][可视化]matplotlib基础入门
Python包matplotlib画图入门,以折线图为例. 在使用之前,导入matplotlib包,设置中文字体 import matplotlib.pyplot as plt %matplotlib ...
- python画立体图形-Python绘制六种可视化图表详解,三维图最炫酷!你觉得呢?
可视化图表,有相当多种,但常见的也就下面几种,其他比较复杂一点,大都也是基于如下几种进行组合,变换出来的.对于初学者来说,很容易被这官网上众多的图表类型给吓着了,由于种类太多,几种图表的绘制方法很有可 ...
- java根据散点图模拟出直线_借助Excel中XY散点图来模拟实现纵向折线图的方法
Excel中的折线图通常是在水平方向上展示数据图线,如果希望在纵向上也能展现折线图,可以借助XY散点图来模拟实现.本文就图文介绍了借助Excel中XY散点图来模拟实现纵向折线图的方法. 具体方法可参考 ...
- python使用matplotlib2D绘图库的折线图绘制小案例(方便matplotlib的学习理解)——随机数做幸运值,绘制一周的幸运趋势
python使用matplotlib2D绘图库的折线图绘制小案例(方便matplotlib的学习理解)--随机数做幸运值,绘制一周的幸运趋势 QQ:3020889729 小蔡 小案例内容简介 实例 第 ...
- 利用python决策树分析iris数据及树状图绘制
利用python决策树分析iris数据及树状图绘制 数据说明 数据划分 模型训练及评估 模型训练代码 模型大致评估 树状图绘制 Graphviz安装配置及入门 代码汇总 基地部门公众号 数据说明 数据 ...
- qchart折现图_Qt Charts 动态实时折线图绘制
在Qt Charts发布之前, Qt比较著名两个画图插件是 qwt和Qcustom, 其中Qcustom较轻量,只需要在project 中包含qcustomplot.h 和 qcustomplot.c ...
- 两条纵坐标折线图绘制
python 两条纵坐标折线图绘制 欢迎使用Markdown编辑器 新的改变 功能快捷键 合理的创建标题,有助于目录的生成 如何改变文本的样式 插入链接与图片 如何插入一段漂亮的代码片 生成一个适合你 ...
- Qt Charts 动态实时折线图绘制
在Qt Charts发布之前, Qt比较著名两个画图插件是 qwt和Qcustom, 其中Qcustom较轻量,只需要在project 中包含qcustomplot.h 和 qcustomplot.c ...
最新文章
- 腾讯告诉你小孩子的钱也有多好赚,一月花费25万不是梦!
- 网页素材大宝库:高质量的免费 PSD 素材【系列四】
- jfinal配置rails的数据表
- SAP Cloud Platform API management Policy Editor的高级用法
- smart field demo1 - how does system know currency needs to be rendered
- Adobe两款软件存在缺陷 黑客可控制用户PC
- 零配置 之 Spring注解实现Bean定义
- java utf8转iso8859-1_在Java中将UTF-8转换为ISO-8859-1
- RESTful API 设计指南 (转)
- 看FusionInsight Spark如何支持JDBCServer的多实例特性
- DT时代释放金融数据价值,驱动金融商业裂变
- SAP License:客户特别总帐统驭科目某天余额取数逻辑
- 交换机短路_交换机日常怎么运行维护?一文告诉你
- C++ const与static
- 微信8.0来了,iOS更新及Android内测版来啦(内含内测版下载连接)
- pymol怎么做底物口袋表面_高质量PyMOL作图教程
- 十年阿里巴巴资深架构师整理分享的SpringSecurity实战文档
- NPDCCH发送周期解析
- Socket通信接口对接
- 80端口被占用的解决办法
热门文章
- wifi linux 驱动分析,Linux 下wifi 驱动开发(二)—— WiFi模块浅析
- Java多线程闲聊(四):阻塞队列与线程池原理
- (转载)各Linux发行版本 网络配置文件
- Android分级部门选择界面(一)
- Morris Traversal方法遍历二叉树(非递归,不用栈,O(1)空间)——无非是在传统遍历过程中修改叶子结点加入后继结点信息(传统是stack记录),然后再删除恢复...
- 启用Gzip压缩(IIS)提高客户端网站访问速度
- c++模板库的一些基本使用
- 打开eclipse出现an error has occurred.see the loh file
- java 线程池原理分析
- Spring事务支持:利用继承简化配置