根据需要,修改了一些参数:1. 字体全部统一为新罗马;2. 颜色改为彩色。

function varargout = wind_rose(D,F,varargin)
%WIND_ROSE   Wind rose of direction and intensity
%
%   Syntax:
%      [HANDLES,DATA] = WIND_ROSE(D,I,VARARGIN)
%
%   Inputs:
%      D   Directions
%      I   Intensities
%      VARARGIN:
%       -dtype, type of input directions D, standard or meteo,
%            if meteo, the conversion dnew=mod(-90-D,360) is done;
%            if not meteo, standard is used (default)
%       -n, number of D subdivisons
%       -di, intensities subdivisons, default is automatic
%       -ci, percentage circles to draw, default is automatic
%       -labtitle, main title
%       -lablegend, legend title
%       -cmap, colormap [jet]
%       -colors, to use instead of colormap, for each di
%       -quad, Quadrant to show percentages [1]
%       -ri, empty internal radius, relative to size of higher
%            percentage [1/30]
%       -legtype, legend type: 1, continuous, 2, separated boxes [2]
%       -bcolor, full rectangle border color ['none']
%       -lcolor, line colors for axes and circles ['k']
%       -percbg, percentage labels bg ['w']
%       -ax, to place wind rose on pervious axes, the input for ax
%            must be [theax x y width], where theax is the previous
%            axes, x and y are the location and width is the wind
%            rose width relative to theax width (default=1/5)
%       -parent, by default a new axes is created unless parent is
%                given, ex, parent may be a subplot
%       -iflip, flip the intensities as they go outward radially, ie,
%                highest values are placed nearest the origin [{0} 1]
%       -inorm, normalize intensities, means all angles will have 100%
%       -incout, if 0, data outside di limits will not be used [0 {1}]
%
%   Output:
%      HANDLES   Handles of all lines, fills, texts
%      DATA   Wind rose occurences per direction and intensity
%
%   Examle:
%      d=0:10:350;
%      D=[];
%      V=[];
%      for i=1:length(d)
%        n=d(i)/10;
%        D=[D ones(1,n)*d(i)];
%        V=[V 1:n];
%      end
%
%      figure
%      wind_rose(D,V)
%
%      figure
%      wind_rose(D,V,'iflip',1)
%
%      figure
%      wind_rose(D,V,'ci',[1 2 7],'dtype','meteo')
%
%      % place it on a previous axes:
%      ax=axes;
%      plot(lon,lat)
%      wind_rose(D,V,'ax',[ax x y 1/3])
%
%   MMA 26-11-2007, mma@odyle.net
%
%   IEO, Instituto Espaol de Oceanografa
%   La Corua, Espaa%   10-12-2007 - Added varargin ci and n (nAngles removed as input)
%   17-12-2007 - Added varargin ax, colors
%   22-02-2008 - Added varargin dtype
%   08-05-2008 - Bug fix (bar at dir=0 could be incorrect in some cases)
%   14-05-2008 - Added varargin iflip
%   16-06-2008 - Added varargin parent
%   10-06-2009 - Added varargin incout
%   27-04-2010 - Added output DATA
%   17-06-2010 - Bug fix (E(i,end)=length(find(b>=Ag(end-1))),
%                previously was ...b>Ag...). So the percentages where
%                wrong only when using intensities equal to the lower
%                value of the highest intensity subdivision, basically
%                an academic case.handles=[];% varargin options:
dtype='standard';
nAngles=36;
ri=1/30;
quad=1;
legType=2;
percBg='w';
titStr='';
legStr='';
% cmap=jet;
cmap=jet;
colors=[];
Ag=[]; % intensity subdivs.
ci=[]; % percentage circles
lineColors='k';
borderColor='none';
onAxes=false;
iflip=0;
inorm=0;
parent=0;
IncHiLow=1; % include values higher and lower that the limits of Ag.vin=varargin;
for i=1:length(vin)if isequal(vin{i},'dtype')dtype=vin{i+1};elseif isequal(vin{i},'n')nAngles=vin{i+1};elseif isequal(vin{i},'ri')ri=vin{i+1};elseif isequal(vin{i},'quad')quad=vin{i+1};elseif isequal(vin{i},'legtype')legType=vin{i+1};elseif isequal(vin{i},'percbg')percBg=vin{i+1};elseif isequal(vin{i},'labtitle')titStr=vin{i+1};elseif isequal(vin{i},'lablegend')legStr=vin{i+1};elseif isequal(vin{i},'cmap')cmap=vin{i+1};elseif isequal(vin{i},'colors')colors=vin{i+1};elseif isequal(vin{i},'di')Ag=vin{i+1};elseif isequal(vin{i},'ci')ci=vin{i+1};elseif isequal(vin{i},'lcolor')lineColors=vin{i+1};elseif isequal(vin{i},'bcolor')borderColor=vin{i+1};elseif isequal(vin{i},'ax')ax=vin{i+1};tryonAxes=ax(1);onAxesX=ax(2);onAxesY=ax(3);onAxesR=ax(4);catchdisp(':: cannot place wind rose on axes, bad argument for ax')returnendelseif isequal(vin{i},'iflip')iflip=vin{i+1};elseif isequal(vin{i},'inorm')inorm=vin{i+1};elseif isequal(vin{i},'parent')parent=vin{i+1};elseif isequal(vin{i},'incout')IncHiLow=vin{i+1};end
end% other options:
% size of the full rectangle:
rs=1.2;
rl=1.7;% directions conversion:
if isequal(dtype,'meteo')% D=mod(-90-D,360);D=mod(90-D,360);
end% angles subdivisons:
D=mod(D,360);
Ay=linspace(0,360,nAngles+1)-0.5*360/nAngles;% calc instensity subdivisions:
if isempty(Ag)% gen Ag:f=figure('visible','off');plot(F); axis tight;yl=get(gca,'ytick');close(f)dyl=diff(yl); dyl=dyl(1);if min(F)<yl(1),   yl=[yl(1)-dyl yl];   endif max(F)>yl(end), yl=[yl yl(end)+dyl]; endAg=yl;
endfor i=1:length(Ay)-1if i==1I=find( (D>=Ay(i) & D<Ay(i+1)) | D>=Ay(end));elseI=find(D>=Ay(i) & D<Ay(i+1));endb=F(I);for j=1:length(Ag)-1if j==length(Ag)-1J=find(b>=Ag(j) & b<=Ag(j+1)); % include data with last AggelseJ=find(b>=Ag(j) & b<Ag(j+1));endE(i,j)=length(J);endif IncHiLowE(i,1)=length(find(b<Ag(2)));E(i,end)=length(find(b>=Ag(end-1)));end
end
b=sum(E,2)/length(D)*100;% normalize data:
if inormn=sum(E,2);for i=1:length(n)E(i,:)=E(i,:)/n(i);endb=100*ones(size(b));
end% check if has values higher or lower than the Ag limits
hasH=length(find(F>Ag(end)));
hasL=length(find(F<Ag(1)));% calc number of percentage circles to draw:
if isempty(ci)if inormci=[25 50 75];g=120;ncircles=3;elsedcircles=[1 2 5 10 15 20 25 30 50];ncircles=3;d=abs(1./(dcircles/max(b))-ncircles);i=find(d==min(d));d=dcircles(i(1));if d*ncircles<max(b)ncircles=ncircles+1;endci=[1:ncircles]*d;g=ncircles*d;end
elsencircles=length(ci);g=max(max(ci),max(b));
end% plot axes, percentage circles and percent. data:
if parentwrAx=parent;set(wrAx,'units','normalized');
elsewrAx=axes('units','normalized');
end
ri=g*ri;
handles(end+1)=fill([-rs*g rl*g rl*g -rs*g],[-rs*g -rs*g rs*g rs*g],'w',...'EdgeColor',borderColor);
if onAxesset(handles(end),'facecolor','none')
end
hold on
handles(end+1)=plot([-g-ri -ri nan ri g+ri nan 0 0 nan 0 0],...[0 0 nan 0 0 nan -g-ri -ri nan ri g+ri],':','color',lineColors);
t0=[0:360]*pi/180;
labs=[];
Ang=[1/4 3/4 5/4 7/4]*pi;
Valign={'top' 'top' 'bottom' 'bottom'};
Halign={'right' 'left' 'left' 'right'};
for i=1:ncirclesx=(ci(i)+ri)*cos(t0);y=(ci(i)+ri)*sin(t0);circles(i)=plot(x,y,':','color',lineColors);handles(end+1)=circles(i);labs(i)=text((ci(i)+ri)*cos(Ang(quad)),(ci(i)+ri)*sin(Ang(quad)),[num2str(ci(i)),'%'],...'VerticalAlignment',Valign{quad},'HorizontalAlignment',Halign{quad},...'BackgroundColor',percBg,'FontSize',8,'Fontname', 'Times New Roman');
end
handles=[handles labs];% calc colors:
if isempty(colors)cor={};for j=1:length(Ag)-1cor{j}=caxcolor(Ag(j),[Ag(1) Ag(end-1)],cmap);end
elsecor=colors;
end% fill data:
n=sum(E,2);
if iflip, E=fliplr(E); end
for i=1:length(Ay)-1if n(i)t=linspace(Ay(i),Ay(i+1),20)*pi/180;r1=ri;for j=1:length(Ag)-1r2=E(i,j)/n(i) *b(i) +r1;x=[r1*cos(t(1)) r2*cos(t) r1*cos(fliplr(t))];y=[r1*sin(t(1)) r2*sin(t) r1*sin(fliplr(t))];if iflip, jcor=length(Ag)-1-j+1;else, jcor=j;endif E(i,j)>0, handles(end+1)=fill(x,y,cor{jcor}); endr1=r2;endend
end
axis equal
axis off% uistack has problems in some matlab versions, so:
%uistack(labs,'top')
%uistack(circles,'top')
ch=get(wrAx,'children');
if inorm% only bring circles up in inorm case.for i=1:length(circles)ch(ch==circles(i))=[]; ch=[circles(i); ch];end
end
for i=1:length(labs)ch(ch==labs(i))=[]; ch=[labs(i); ch];
end
set(wrAx,'children',ch);% N S E W labels:      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bg='none';
args={'BackgroundColor',bg,'FontSize',8,'Fontname', 'Times New Roman'};%%%%%%%%%%原来是8,现在是16%%%%%%%%%%%%%
h(1)=text(-g-ri, 0,'WEST', 'VerticalAlignment','top','HorizontalAlignment','left', args{:});
h(2)=text( g+ri, 0,'EAST', 'VerticalAlignment','top','HorizontalAlignment','right',args{:});
h(3)=text( 0,-g-ri,'SOUTH','VerticalAlignment','bottom','HorizontalAlignment','left', args{:});
h(4)=text( 0, g+ri,'NORTH','VerticalAlignment','top','HorizontalAlignment','left', args{:});
handles=[handles h];% scale legend:
L=(g*rl-g-ri)/7;
h=(g+ri)/10;
dy=h/3;x0=g+ri+(g*rl-g-ri)/7;
x1=x0+L;
y0=-g-ri;if legType==1 % contimuous.图例for j=1:length(Ag)-1lab=num2str(Ag(j));if j==1 & hasL & IncHiLowlab='';endy1=y0+h;handles(end+1)=fill([x0 x1 x1 x0],[y0 y0 y1 y1],cor{j});handles(end+1)=text(x1+L/4,y0,lab,'VerticalAlignment','middle','fontsize',8,'Fontname', 'Times New Roman');y0=y1;endif ~ (hasH & IncHiLow)handles(end+1)=text(x1+L/4,y0,num2str(Ag(end)),'VerticalAlignment','middle','fontsize',8,'Fontname', 'Times New Roman');end
elseif legType==2 % separated boxes.for j=1:length(Ag)-1lab=[num2str(Ag(j)) ' - ' num2str(Ag(j+1))];if j==1 & hasL & IncHiLowlab=['<',num2str(Ag(2))];endif j==length(Ag)-1 & hasH & IncHiLowlab=['>=',num2str(Ag(j))];endy1=y0+h;handles(end+1)=fill([x0 x1 x1 x0],[y0+dy y0+dy y1 y1],cor{j});handles(end+1)=text(x1+L/4,(y0+dy+y1)/2,lab,'VerticalAlignment','middle','fontsize',8,'Fontname', 'Times New Roman');y0=y1;endend% title and legend label:   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x=mean([-g*rs,g*rl]);
y=mean([g+ri,g*rs]);
handles(end+1)=text(x,y,titStr,'HorizontalAlignment','center');x=x0;
y=y1+dy;
handles(end+1)=text(x,y,legStr,'HorizontalAlignment','left','VerticalAlignment','bottom','FontName','Times New Roman');if onAxesplace_wr(onAxes,wrAx,onAxesX,onAxesY,onAxesR);
endif nargout>=1varargout{1}=handles;
end
if nargout>=2varargout{2}=E;
endfunction place_wr(ax,ax2,x,y,width)
if nargin < 5width=1/5;
end
uax=get(ax,'units');
pax=get(ax,'position');
set(ax,'units',uax)
axXlim=get(ax,'xlim');
axYlim=get(ax,'ylim');x_ax2=pax(1)+pax(3)*(x-axXlim(1))/diff(axXlim);
y_ax2=pax(2)+pax(4)*(y-axYlim(1))/diff(axYlim);pax2=get(ax2,'position');
width=pax(3)*width;
height=pax2(4)*width/pax2(3);
pax2=[x_ax2 y_ax2 width height];if 1% place at centre of the wr, not the bottom left corner:ax2Xlim=get(ax2,'xlim');ax2Ylim=get(ax2,'ylim');dx=(0-ax2Xlim(1))/diff(ax2Xlim)*pax2(3);dy=(0-ax2Ylim(1))/diff(ax2Ylim)*pax2(4);x_ax2=x_ax2-dx;y_ax2=y_ax2-dy;pax2=[x_ax2 y_ax2 width height];
end
set(ax2,'position',pax2)function cor = caxcolor(val,cax,cmap)
%CAXCOLOR   Caxis color for value
%   Find the color for a given value in a colormap.
%
%   Syntax:
%     COLOR = CAXCOLOR(VALUE,CAXIS,COLORMAP)
%
%   Inputs:
%      VALUE
%      CAXIS   Default is current caxis
%      COLORMAP   Default is current colormap
%
%   Output:
%      COLOR   RGB color vector
%
%   Example:
%      figure
%      pcolor(peaks)
%      color=caxcolor(0);
%      set(gcf,'color',color)
%
%   MMA 28-5-2007, martinho@fis.ua.pt% Department of Physics
% University of Aveiro, Portugalif nargin < 3cmap = get(gcf,'colormap');
end
if nargin < 2cax = caxis;
endn=size(cmap,1);
i= (val-cax(1))/diff(cax) * (n-1) +1;
a=i-floor(i);
i=floor(i);i=min(i,n);
i=max(i,1);if i==ncor=cmap(n,:);
elseif i==1cor=cmap(1,:);
elsecor=cmap(i,:)*(1-a) + cmap(i+1,:)*a;
end

MATLAB 风玫瑰图 wind_rose.m相关推荐

  1. Matlab进阶绘图第5期—风玫瑰图(WindRose)

    风玫瑰图(Wind rose diagram)是一种特殊的极坐标堆叠图/统计直方图,其能够直观地表示某个地区一段时期内风向.风速的发生频率. 风玫瑰图在建筑规划.环保.风力发电.消防.石油站设计.海洋 ...

  2. 【花式】基于matlab花风玫瑰图【含Matlab源码 088期】

    一.简介 风玫瑰图分为:风向玫瑰图和风速玫瑰图两种. 1.2 风玫瑰图一般都反映着两个重要信息:风向.风率. 风玫瑰图上所表示的风向即风的来向,是指从外面吹向地区中心的方向 如图:①表示北风,②表示西 ...

  3. 【五一创作】Matlab 绘制风速、风向统计玫瑰花图【优化】

    在之前,有个博客专门讲matlab 绘制风速.风向统计玫瑰花图:这里面存在不少细节问题,目前对该部分代码做了优化.以前的博客链接见下: Matlab 绘制风速.风向统计玫瑰花图 最近接了一个任务,需要 ...

  4. Python如何调用matlab函数?

    仅需一步就能搭建好两者的通道! 在matlab的命令行下键入: cd (fullfile(matlabroot,'extern','engines','python')) system('python ...

  5. 利用NVIDIA-NGC中的MATLAB容器加速语义分割

    利用NVIDIA-NGC中的MATLAB容器加速语义分割 Speeding Up Semantic Segmentation Using MATLAB Container from NVIDIA NG ...

  6. 用matlab怎么画视电阻率拟断面图,在MATLAB平台上实现可控源音频大地电磁反演数据三维可视化显示...

    第29卷 增刊 物探化探计算技术 2007年10月 收稿日期6文章编号:1001-1749(2007)增刊(1)-0068-04 在MAT LAB 平台上实现可控源音频大地 电磁反演数据三维可视化显示 ...

  7. 直接法 matlab,解线性方程组直接方法matlab用法.doc

    解线性方程组直接方法matlab用法 在这章中我们要学习线性方程组的直接法,特别是适合用数学软件在计算机上求解的方法. 2.1 方程组的逆矩阵解法及其MATLAB程序 2.1.3 线性方程组有解的判定 ...

  8. matlab编程实现基于密度的聚类(DBSCAN)

    1. DBSCAN聚类的基本原理 详细原理可以参考链接: https://www.cnblogs.com/pinard/p/6208966.html 这是找到的相对很详细的介绍了,此链接基本仍是周志华 ...

  9. matlab编程实现k_means聚类(k均值聚类)

    1. 聚类的定义 以下内容摘抄自周志华<机器学习> 根据训练数据是否拥有标记信息,机器学习任务可以大致分为两大类:"监督学习"(supervised learning) ...

  10. matlab生成多组多维高斯分布数据

    matlab生成多组多维高斯分布数据 之所以写这么一个函数,是因为在练习用matlab实现聚类分析,用matlab生成的高斯分布数据可以作为很好的数据.当然,直接load进鸢尾花数据集也可以拿来练手, ...

最新文章

  1. 要强大的“黑匣子”,还是“可解释”的机器学习?| 清华AI Time激辩
  2. [转]MacBook Pro上装三系统 OS X、Ubuntu、Win 7
  3. Important table for launchpad Designer and configuration
  4. 01背包初始化的细节问题与循环下限的改进
  5. 发布软件之前,怎样告诉用户怎么用
  6. python安装requests模块失败_No module named quot;Cryptoquot;,如何安装Python三方模块Crypto...
  7. 将字符串1/4转换成0.25 eval()
  8. vsftpd 本地用户登录和上传设置
  9. Object Detection︱RCNN、faster-RCNN框架的浅读与延伸内容笔记
  10. python初学者学用anaconda学_致Python初学者:Anaconda入门使用指南
  11. 数学主题分类 - 中文(上)
  12. 【转】资深眼镜人告诉你一些所不为人知的眼镜知识和内幕
  13. web网站http转成https
  14. win10辅助准星教程
  15. saltstack return mysql_10-saltstack 数据返回到MySQL
  16. Unity 异常记录日志功能
  17. 量化选股策略模型大全
  18. 大数据的理解,大数据是什么,大数据能干什么?
  19. 深度学习中常见的打标签工具和数据集集合(转)
  20. Python免费下载哔哩哔哩视频,只需一行代码!

热门文章

  1. 访问网上邻居-修改账号密码
  2. 从哥尼斯堡“七桥问题”到盖洛普“优势识别器”
  3. 此计算机里有旧的MF驱动程序,[讲解]手动删除旧的打印机驱动程序
  4. uni-app 实现自定义音效播放
  5. vscode安装旧版本插件_vscode 常用插件安装
  6. 机器学习之路六:文本特征提取
  7. c++ 调用批处理 bat 清理浏览器缓存。
  8. matlab中数组的创建
  9. 融合零样本学习和小样本学习的弱监督学习方法综述
  10. 《软件测试》学习目标与计划