matlab 环形单层柱状图
matlab 环形单层柱状图
matlab 环形单层柱状图
图片
图片
【图片来源粉丝】
我给他的思路是:直接使用风玫瑰图可以画出。
rose_bar
本次我的更新和这个有些不同!是环形柱状图,可调节细节多;
只需要函数:可实现各个方面:
欢迎持续投稿,宣传自己的工作(不限代码论文等方面)!
rose_bar
使用简单:
输入数据和参数
[ph,fs] =rose_bar(datax,datay,r,R,bw1,xtickvalue);
% note: datax is x;
% datay is y;
% r is inner circle
% R is circle
% bw1 is width of bar,from 2 to inf; 2 is full; increase then thin bar; %
% ph can control line of circle;;
% fs can control line and face color of bar
先看些结果:在解释如何做出:
默认图,所有颜色一致:
图片
可使用代码调节某一个柱状图的颜色:
例如第十四(14)个为蓝色:
set(fs(14),‘FaceColor’,‘b’,‘EdgeColor’,‘b’)
图片
可调节每一个颜色都不同:
图片
可控制中心⚪的大小
⚪为零:
图片
⚪为大:
图片
可以加单位:一个或多个或全部
图片
可以什么都不要
图片在这里插入图片描述
可以更改xtick
图片
总而言之,挺强的!
主程序:
.rtcContent { padding: 30px; } .lineNode {font-size: 12pt; font-family: "Times New Roman", Menlo, Monaco, Consolas, "Courier New", monospace; font-style: normal; font-weight: normal; }
clear;clc;close all;
% 构造数据
year = 1:14;
windspeed = 1:14;
yeartick = 2001:2014;
% yeartick = 1:14;
%
close all;
figure
set(gcf,'position',[50 50 850 850 ],'color','w')
% 使用函数
datax = year;
datay = windspeed;
r = 1;
R = 2;
bw1 = 2;
xtickvalue = yeartick;
[ph,fs] =rose_bar(datax,datay,r,R,bw1,xtickvalue);
% set(fs(14),'FaceColor','b','EdgeColor','b')
% 颜色包
load('GMT_drywet.mat')
cmap =GMT_drywet(1:floor(59/length(windspeed)):end,:);
cmap = load('colormore_21.txt');
cmap = cmap(1:20:end,:);
for i = 1:length(fs)
set(fs(i),'FaceColor',cmap(i,:),'EdgeColor',cmap(i,:));
end
% note: datax is x;
% datay is y;
% r is inner circle
% R is circle
% bw1 is width of bar,from 2 to inf; 2 is full; increase then thin bar; %
% ph can control line of circle;;
% fs can control line and face color of bar
title('环形柱状图','FontSize',12,'FontWeight','bold','FontName','time News roman','color',[0.54588199 0.40039200 0.17607801]);
export_fig('环形柱状图.jpg')
函数:
.rtcContent { padding: 30px; } .lineNode {font-size: 12pt; font-family: "Times New Roman", Menlo, Monaco, Consolas, "Courier New", monospace; font-style: normal; font-weight: normal; }
function [ph,fs] = rose_bar(datax,datay,r,R,bw1,xtickvalue)
% note: datax is x;
% datay is y;
% r is inner circle
% R is circle
% bw1 is width of bar
% 数据传入
year = datax;
windspeed = datay;
R = R;
bw1 = bw1;% bw1 最小值 min value is 2; max is not limit;
r = r;
t = 0:0.01:2*pi;
windspeed = windspeed+r;
% 基底
% h(1)=plot(r*sin(t),r*cos(t),'color','k');
if R>=r
xlim([-(max(windspeed)+R) max(windspeed)+R])
ylim([-(max(windspeed)+R) max(windspeed)+R])
else
xlim([-(max(windspeed)+r) max(windspeed)+r])
ylim([-(max(windspeed)+r) max(windspeed)+r])
end
axis equal
axis off
hold on
t1 = 0:2*pi/(length(year)):2*pi;
% scatter(r*sin(t1),r*cos(t1))
bw = 2*pi/(length(year)-1)/bw1;
for i = 1:length(t1)-1
t2 = t1(i)-bw:0.01:t1(i)+bw;
% plot(r*sin(t2),r*cos(t2))
% hold on
% plot(windspeed(i)*sin(t2),windspeed(i)*cos(t2))
% hold on
X = [r*sin(t2) flip((windspeed(i))*sin(t2)) ];
Y = [r*cos(t2) flip((windspeed(i))*cos(t2)) ];
fs(i)= fill(X,Y,'r');
clear X Y
hold on
X= mean((windspeed(i))*sin(t2));
Y = mean((windspeed(i))*cos(t2));
text(X,Y,num2str(xtickvalue(i)),'FontSize',12,'FontWeight','bold','FontName','time News roman','Rotation',90,'color','b')
clear X Y
end
hold on
T = 0:0.01:pi/8;% 控制标签的摆放位置
for ii = 1:R:max(windspeed)+R
if (r+ii-1)<=(max(windspeed)+R)
ph(ii)=plot((r+(ii-1))*sin(t),(r+(ii-1))*cos(t),'LineStyle','--','Color','k');
X = mean((r+(ii-1))*sin(T));
Y = mean((r+(ii-1))*cos(T));
text(X,Y,num2str(ii-1),'FontSize',12,'FontWeight','bold','FontName','time News roman','color',[0.54588199 0.40039200 0.17607801]);
hold on
if ii == (r+ii-1)%max(1:R:max(windspeed)+R)
text(X,Y,[num2str(ii-1),' m/s'],'FontSize',12,'FontWeight','bold','FontName','time News roman','color',[0.54588199 0.40039200 0.17607801]);
else
text(X,Y,[num2str(ii-1)],'FontSize',12,'FontWeight','bold','FontName','time News roman','color',[0.54588199 0.40039200 0.17607801]);
end
end
end
赞赏直接公益捐赠!
图片
点分享
图片
点收藏
图片
点在看
图片
点点赞