MATLAB实例:散点密度图

MATLAB绘制用颜色表示数据密度的散点图

1. demo.m

% 用颜色表示数据密度的散点图

data_load=dlmread('E:\scanplot\gauss.txt');

X=data_load(:,1:2);

scatplot(X(:,1),X(:,2),'circles', sqrt((range(X(:, 1))/30)^2 + (range(X(:,2))/30)^2), 100, 5, 1, 8);

% colormap jet

print(gcf,'-dpng','散点密度图.png');

2. scatplot.m

function out = scatplot(x,y,method,radius,N,n,po,ms)

% Scatter plot with color indicating data density

% https://www.mathworks.com/matlabcentral/fileexchange/8577-scatplot

% USAGE:

% out = scatplot(x,y,method,radius,N,n,po,ms)

% out = scatplot(x,y,dd)

%

% DESCRIPTION:

% Draws a scatter plot with a colorscale

% representing the data density computed

% using three methods

%

% INPUT VARIABLES:

% x,y - are the data points

% method - is the method used to calculate data densities:

% 'circles' - uses circles with a determined area

% centered at each data point

% 'squares' - uses squares with a determined area

% centered at each data point

% 'voronoi' - uses voronoi cells to determin data densities

% default method is 'voronoi'

% radius - is the radius used for the circles or squares

% used to calculate the data densities if

% (Note: only used in methods 'circles' and 'squares'

% default radius is sqrt((range(x)/30)^2 + (range(y)/30)^2)

% N - is the size of the square mesh (N x N) used to

% filter and calculate contours

% default is 100

% n - is the number of coeficients used in the 2-D

% running mean filter

% default is 5

% (Note: if n is length(2), n(2) is tjhe number of

% of times the filter is applied)

% po - plot options:

% 0 - No plot

% 1 - plots only colored data points (filtered)

% 2 - plots colored data points and contours (filtered)

% 3 - plots only colored data points (unfiltered)

% 4 - plots colored data points and contours (unfiltered)

% default is 1

% ms - uses this marker size for filled circles

% default is 4

%

% OUTPUT VARIABLE:

% out - structure array that contains the following fields:

% dd - unfiltered data densities at (x,y)

% ddf - filtered data densities at (x,y)

% radius - area used in 'circles' and 'squares'

% methods to calculate densities

% xi - x coordenates for zi matrix

% yi - y coordenates for zi matrix

% zi - unfiltered data densities at (xi,yi)

% zif - filtered data densities at (xi,yi)

% [c,h] = contour matrix C as described in

% CONTOURC and a handle H to a contourgroup object

% hs = scatter points handles

%

%Copy-Left, Alejandro Sanchez-Barba, 2005

if nargin==0

scatplotdemo

return

end

if nargin<3 | isempty(method)

method = 'vo';

end

if isnumeric(method)

gsp(x,y,method,2)

return

else

method = method(1:2);

end

if nargin<4 | isempty(n)

n = 5; %number of filter coefficients

end

if nargin<5 | isempty(radius)

radius = sqrt((range(x)/30)^2 + (range(y)/30)^2);

end

if nargin<6 | isempty(po)

po = 1; %plot option

end

if nargin<7 | isempty(ms)

ms = 7; %markersize

end

if nargin<8 | isempty(N)

N = 100; %length of grid

end

%Correct data if necessary

x = x(:);

y = y(:);

%Asuming x and y match

idat = isfinite(x);

x = x(idat);

y = y(idat);

holdstate = ishold;

if holdstate==0

cla

end

hold on

%--------- Caclulate data density ---------

dd = datadensity(x,y,method,radius);

%------------- Gridding -------------------

xi = repmat(linspace(min(x),max(x),N),N,1);

yi = repmat(linspace(min(y),max(y),N)',1,N);

zi = griddata(x,y,dd,xi,yi);

%----- Bidimensional running mean filter -----

zi(isnan(zi)) = 0;

coef = ones(n(1),1)/n(1);

zif = conv2(coef,coef,zi,'same');

if length(n)>1

for k=1:n(2)

zif = conv2(coef,coef,zif,'same');

end

end

%-------- New Filtered data densities --------

ddf = griddata(xi,yi,zif,x,y);

%----------- Plotting --------------------

switch po

case {1,2}

if po==2

[c,h] = contour(xi,yi,zif);

out.c = c;

out.h = h;

end %if

hs = gsp(x,y,ddf,ms);

out.hs = hs;

colorbar

case {3,4}

if po>3

[c,h] = contour(xi,yi,zi);

out.c = c;

end %if

hs = gsp(x,y,dd,ms);

out.hs = hs;

colorbar

end %switch

%------Relocate variables and place NaN's ----------

dd(idat) = dd;

dd(~idat) = NaN;

ddf(idat) = ddf;

ddf(~idat) = NaN;

%--------- Collect variables ----------------

out.dd = dd;

out.ddf = ddf;

out.radius = radius;

out.xi = xi;

out.yi = yi;

out.zi = zi;

out.zif = zif;

if ~holdstate

hold off

end

return

%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

function scatplotdemo

po = 2;

method = 'squares';

radius = [];

N = [];

n = [];

ms = 5;

x = randn(1000,1);

y = randn(1000,1);

out = scatplot(x,y,method,radius,N,n,po,ms)

return

%~~~~~~~~~~ Data Density ~~~~~~~~~~~~~~

function dd = datadensity(x,y,method,r)

%Computes the data density (points/area) of scattered points

%Striped Down version

%

% USAGE:

% dd = datadensity(x,y,method,radius)

%

% INPUT:

% (x,y) - coordinates of points

% method - either 'squares','circles', or 'voronoi'

% default = 'voronoi'

% radius - Equal to the circle radius or half the square width

Ld = length(x);

dd = zeros(Ld,1);

switch method %Calculate Data Density

case 'sq' %---- Using squares ----

for k=1:Ld

dd(k) = sum( x>(x(k)-r) & x(y(k)-r) & y

end %for

area = (2*r)^2;

dd = dd/area;

case 'ci'

for k=1:Ld

dd(k) = sum( sqrt((x-x(k)).^2 + (y-y(k)).^2) < r );

end

area = pi*r^2;

dd = dd/area;

case 'vo' %----- Using voronoi cells ------

[v,c] = voronoin([x,y]);

for k=1:length(c)

%If at least one of the indices is 1,

%then it is an open region, its area

%is infinity and the data density is 0

if all(c{k}>1)

a = polyarea(v(c{k},1),v(c{k},2));

dd(k) = 1/a;

end %if

end %for

end %switch

return

%~~~~~~~~~~ Graf Scatter Plot ~~~~~~~~~~~

function varargout = gsp(x,y,c,ms)

%Graphs scattered poits

map = colormap;

ind = fix((c-min(c))/(max(c)-min(c))*(size(map,1)-1))+1;

h = [];

%much more efficient than matlab's scatter plot

for k=1:size(map,1)

if any(ind==k)

h(end+1) = line('Xdata',x(ind==k),'Ydata',y(ind==k), ...

'LineStyle','none','Color',map(k,:), ...

'Marker','.','MarkerSize',ms);

end

end

if nargout==1

varargout{1} = h;

end

return

3. 结果

MATLAB实例:绘制折线图

MATLAB实例:绘制折线图 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 条形图的绘制见:MATLAB实例:绘制条形图 用MATLAB将几组不同的数 ...

MATLAB实例:构造网络连接图&lpar;Network Connection&rpar;及计算图的代数连通度&lpar;Algebraic Connectivity&rpar;

MATLAB实例:构造网络连接图(Network Connection)及计算图的代数连通度(Algebraic Connectivity) 作者:凯鲁嘎吉 - 博客园 http://www.cnbl ...

Matlab plotyy画双纵坐标图实例

Matlab plotyy画双纵坐标图实例 x = 0:0.01:20;y1 = 200*exp(-0.05*x).*sin(x);y2 = 0.8*exp(-0.5*x).*sin(10*x);[A ...

MATLAB实例:求相关系数、绘制热图并找到强相关对

MATLAB实例:求相关系数.绘制热图并找到强相关对 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 用MATLAB编程,求给定数据不同维度之间的相关系 ...

MATLAB实例:聚类网络连接图

MATLAB实例:聚类网络连接图 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 本文给出一个简单实例,先生成2维高斯数据,得到数据之后,用模糊C均值( ...

MATLAB实例:二元高斯分布图

MATLAB实例:二元高斯分布图 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 1. MATLAB程序 %% demo Multivariate No ...

Python图表数据可视化Seaborn:1&period; 风格&vert; 分布数据可视化-直方图&vert; 密度图&vert; 散点图

conda  install seaborn  是安装到jupyter那个环境的 1. 整体风格设置 对图表整体颜色.比例等进行风格设置,包括颜色色板等调用系统风格进行数据可视化 set() / se ...

MATLAB实例:绘制条形图

MATLAB实例:绘制条形图 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 用MATLAB绘制条形图,自定义条形图的颜色.图例位置.横坐标名称.显示条 ...

MATLAB实例:将批量的图片保存为&period;mat文件

MATLAB实例:将批量的图片保存为.mat文件 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 一.彩色图片 图片数据:horse.rar 1. MA ...

随机推荐

体验报告:微信小程序在安卓机和苹果机上的区别

很多人可能会问:微信小程序和在微信里面浏览一个网页有什么区别? 首先,小程序的运行是全屏的,界面跟进入了一个APP很像,更为沉浸跟在微信里面访问h5不一样:其次,它的浏览体验更为稳定. 不过,这还不够 ...

POJ1014 解题报告&lpar;DFS&rpar;

题目在此:http://poj.org/problem?id=1014 要看清题意呢,题中要求输入的是价值分别为1,2,3,4,5,6的大理石的个数,而不是6块价值为输入数字的大理石!选这个题主要想练 ...

51nod 1412 AVL树的种类&lpar;dp&rpar;

题目链接:51nod 1412 AVL树的种类 开始做的时候把深度开得过小了结果一直WA,是我天真了.. #include #include ...

Regex&period;Replace的基本用法

Regex构造函数Regex(string pattern)Regex(string pattern,RegexOptions options)参数说明pattern:要匹配的正则表达式模式optio ...

使用Redis的理由

Redis是一个远程内存数据库,它不仅性能强劲,而且还具有复制特性以及为解决问题而生的独一无二的数据模型.Redis提供了5种不同类型的数据结构,各式各样的问题都可以很自然地映射到这些数据结构上:Re ...

Could not load type System&period;ServiceModel&period;Activation&period;HttpModule解决办法

等注册完成后网站就可以打开了. win2008下提示未能从程序集“System.ServiceModel, Version=3.0.0.0问题解决 在Windows Server 2008中的IIS服 ...

DailyTick 开发实录 —— UI 设计

上次的文章中描述了 DailyTick 的设计理念.经过两周左右的设计和开发,现在 DailyTick 的主要 UI 已经完成了原型的设计和初步的实现.既然是原型,当然看起来就有点粗糙. 主 UI 主 ...

C&num; 读取系统日志

.NET框架类库提供了EventLog类和EventLogEntry类与系统日志进行交互二者属于System.Diagnostics命名空间 EventLog 类的属性主要有 Entris返回一个Ev ...

docker dead but pid file exists

CentOS 6安装docker 报docker dead but pid file exists 执行 yum install epel-release yum install docker-io ...

SpringBoot系列&colon; 集成MyBatis

本文主要修改自下面博客:http://www.ityouknow.com/springboot/2016/11/06/spring-boo-mybatis.htmlhttp://tengj.top/2 ...

matlab绘制散点密度,MATLAB实例:散点密度图相关推荐

  1. matlab ploty,matlab绘制函数 如何利用matlab的ploty

    最近有网友提出"matlab绘制函数 如何利用matlab的ploty"等问题,小小知识站提取了各大知名网站有关"matlab绘制函数 如何利用matlab的ploty& ...

  2. matlab yticklable,Matlab绘制XTickLabel有效字符串(Matlab Plot XTickLabel valid strings)

    Matlab绘制XTickLabel有效字符串(Matlab Plot XTickLabel valid strings) 我有一个情节: x = [0 1 2 3]; y = [0 0 1 1]; ...

  3. matlab 绘制符号函数,DAY8 MATLAB学习笔记—simulink入门、MATLAB符号函数的图形绘制...

    如何打开simulink: 启动simulink: 先打开MATLAB软件界面 第一步打开simulink 第二步在command windows输入 simulink然后enter,等待 有很多模块 ...

  4. matlab绘制三维球体,使用Matlab绘制三维圆柱体和球体

    使用Cylinder功能函数绘制圆柱体侧面 在matlab中自带了绘制圆柱体的功能函数cylinder,其用法如下: 例1,绘制一个圆柱体的三维图像,要求圆柱体底面圆心在坐标原点,底面半径为3,高度为 ...

  5. matlab绘制星下点轨迹,卫星星下点轨迹Matlab仿真.docx

    使用Matlab绘制卫星星下点轨迹1.地球静止轨道卫星,倾角分别为0,30,90度.clc; clear;t = 0:1:6;we = 360/24;u = we*t;i = 30;fai = asi ...

  6. matlab绘制磁场图,基于Matlab的电磁场图示化教学

    第 26 卷第 3 期 孝感学院学报 VOL. 26 NO. 3 2006 年 5 月 JOURNAL OF XIAOGAN UNIVERSITY MA Y. 2006 基于 Matlab 的电磁场图 ...

  7. matlab绘制y3=e (-x),MATLAB图形绘制-二维配套实验

    实验五 MATLAB 绘图-二维 1.在同一坐标系下绘制下面三个函数在t ∈[0,4π]的图象. ) sin(41.0321t e y t y t y t -===π 注意此处的sin (t )前面需 ...

  8. 用MATLAB绘制国债NSS模型,Matlab在数字信号处理中的运用.ppt

    <Matlab在数字信号处理中的运用.ppt>由会员分享,可在线阅读,更多相关<Matlab在数字信号处理中的运用.ppt(68页珍藏版)>请在装配图网上搜索. 1.第七讲 M ...

  9. matlab绘制一组椭圆,在MATLAB中绘制椭圆和椭圆体

    Ellipse文章 Wikipedia有一个简单的JavaScript代码绘制椭圆. 它使用参数形式: x(theta) = a0 + ax*sin(theta) + bx*cos(theta) y( ...

  10. 如何用MATLAB绘制真值表,编写真值表 - MATLAB Simulink - MathWorks 中国

    编写真值表 在创建新真值表后,您就可以对它进行编写以根据您的设定执行.要编写真值表,您需要添加条件.决策和动作.有关创建真值表的详细信息,请参阅使用真值表对组合逻辑建模. 真值表仅在 Simulink ...

最新文章

  1. break 与 continue
  2. 从今天开始用上了液晶显示器,总算对得起自己的眼睛了。感谢!
  3. x86服务器当虚拟化的存储,X86服务器虚拟化实施方案.doc
  4. 代码review工具:Review Board
  5. mysql null值和空格_MySQL中NULL与空字符串空格问题
  6. Redis-3.2主从复制与集群搭建 推荐
  7. 2021高考个人成绩排名查询,2021新高考八省联考实力排名:怎么查联考成绩在全省排名?...
  8. 怎么增加一个工位?ApiPost工位有什么用?
  9. 统计php代码执行情况,PHP代码执行函数总结
  10. 【bzoj4321】queue2 dp
  11. Centos7 安装python3.7.0
  12. POJ2115 C Looooops 扩展欧几里德
  13. linux ntfs 转换 无损,无损数据下NTFS转换FAT32分区
  14. Vista 自动激活工具(最新 最权威 所有版本 可升级)
  15. dataFrame(DF)将数据插入ES时报错 org.elasticsearch.hadoop.EsHadoopIllegalArgumentException: Cannot detect E
  16. 安卓手机格式化怎么弄_安卓手机怎么格式化 Android手机内存卡格式化方法
  17. Mysql优化之6年工作经验总结
  18. 数据库组成和存储引擎
  19. VIC运行笔记2019.05.01
  20. 今年世界杯预测(阿根廷队冠军)

热门文章

  1. linux ftp无法打开文件,Linux下vsftp匿名用户无法上传文件
  2. (转载)3. 飞控与惯性导航系统
  3. 转:gp88写频教程
  4. 2018/03/28更新 日记
  5. Twaver-HTML5基础学习(26)背景
  6. 【Linux】nasm/yasm not found
  7. 地信遥感行业可以考的证
  8. c语言模拟uart协议的收发
  9. sap服务器的文件管理,SAPPLM 文档管理介绍
  10. QTcpSocket的读写操作