黄浦企业网站制作,网站加速器免费永久,网络营销案例介绍,超大尺寸哔哩哔哩网站目录 扫一扫关注公众号
效果图
粉丝给的图#xff1a;
复刻的图#xff1a;
其他样式效果#xff1a;
数据
绘图教程
绘制左边Y轴
绘制主、次网格和主、次刻度的极坐标区域。
添加刮风数据#xff0c;添加数据和颜色、图列大小映射关系。
颜色条绘制…目录 扫一扫关注公众号
效果图
粉丝给的图
复刻的图
其他样式效果
数据
绘图教程
绘制左边Y轴
绘制主、次网格和主、次刻度的极坐标区域。
添加刮风数据添加数据和颜色、图列大小映射关系。
颜色条绘制
添加图列绘制
绘图工具箱介绍
默认绘图
刻度颜色设置
刻度方向和长短设置其中刻度方向有in|out|both。
网格设置主、次网格的颜色、粗细、透明度设置。
背景颜色设置
图列设置
颜色条设置
WindRosePlot类函数
属性:
方法: 扫一扫关注公众号 效果图
粉丝给的图 复刻的图 其他样式效果 数据
数据包含风向、刮风频率、最大风速、平均风速四个数据。
windDirections [0.0, 22.5, 45.0, 67.5, 90.0, 112.5, 135.0, 157.5, 180.0, 202.5, 225.0, 247.5, 270.0, 292.5, 315.0, 337.5];
windFrequency [10.2, 4, 4, 3.0, 4.0, 3.0, 4.0, 4.0, 7.0, 6.0, 3, 2, 2, 1.0, 3, 5];
maxWindSpeed [15, 12, 10, 5, 5, 5,10, 12, 13, 15, 12,5, 5, 10, 12, 15];
avgWindSpeed [2.8, 2.0, 1.5, 1.2, 1.4, 1.3, 1.45, 2.00, 2.80, 2.80, 1.50, 1.00, 1.0, 1.0, 1.8, 2.0];
data[windDirections,windFrequency,maxWindSpeed,avgWindSpeed];
数据长成这样的 绘图教程
绘制左边Y轴
% 设置基础参数
maxRadius ceil(max(windFrequency));
minRadius round(maxRadius / 10);
dfTunique(diff(windDirections));
allTheta 0:0.01:360;
% 创建并配置坐标轴
figfigure(Color,[1,1,1]);
ax gca;
hold on; box off; grid off; axis equal;
ax.YLim [-maxRadius, maxRadius];
ax.YMinorTick on;
ax.XColor none;
ax.XDir normal;
ax.TickDir out;
ax.LineWidth 1.5;
majorTicksY ax.YTick;
minorTicksY (majorTicksY(1:end-1) majorTicksY(2:end)) / 2;
diffTicks unique(diff(majorTicksY));
maxRadiusmax(ax.YTick)diffTicks/2;
ax.YLim [-maxRadius, maxRadius];%重新设定
ax.YAxis.MinorTickValues [minorTicksY(1)-diffTicks, minorTicksY, minorTicksY(end)diffTicks];
ax.YTickLabel arrayfun((y) sprintf(%d, abs(y)), majorTicksY, UniformOutput, false);
ax.YLabel.String风向频率(%); 绘制主、次网格和主、次刻度的极坐标区域。
% 绘制主要的极坐标网格线
majorRadius majorTicksY(majorTicksY minRadius);
for i 1:length(majorRadius)[xMajor, yMajor] pol2cart(deg2rad(allTheta), majorRadius(i));plot(xMajor, yMajor, -, Color, [0 0 0], LineWidth, 0.5);
end
majorTheta windDirections;
fullRadius linspace(minRadius, maxRadius, 1000);
for i 1:length(majorTheta)[xMajorT, yMajorT] pol2cart(deg2rad(majorTheta(i)), fullRadius);plot(xMajorT, yMajorT, -, Color, [0.8 0.8 0.8], LineWidth, 1.2);
end
% 绘制次要的极坐标网格线
minorRadius minorTicksY(minorTicksY minRadius);
for i 1:length(minorRadius)[xMinor, yMinor] pol2cart(deg2rad(allTheta), minorRadius(i));plot(xMinor, yMinor, :, Color, [0.55 0.55 0.55], LineWidth, 0.8);
end
minorThetawindDirectionsdfT/2;
% minorTheta 11.25:22.5:360;
for i 1:length(minorTheta)[xMinorT, yMinorT] pol2cart(deg2rad(minorTheta(i)), fullRadius);plot(xMinorT, yMinorT, -., Color, [0.55 0.55 0.55]);
end
% 绘制最外层的极坐标线
[xOuter, yOuter] pol2cart(deg2rad(allTheta), maxRadius);
plot(xOuter, yOuter, -, Color, k, LineWidth, 2);
% 主刻度线
mainTickTheta windDirectionsdfT;
% mainTickTheta 0:22.5:360;
tickRadius [maxRadius*0.96, maxRadius];
for i 1:length(mainTickTheta)[xMainTick, yMainTick] pol2cart(deg2rad(mainTickTheta(i)), tickRadius);plot(xMainTick, yMainTick, -, Color, [0, 0, 0], LineWidth, 1.5);
end
% 次刻度线
minorTickThetawindDirectionsdfT/2;
% minorTickTheta 11.25:22.5:360;
tickRadiusMinor [maxRadius*0.98, maxRadius];
for i 1:length(minorTickTheta)[xMinorTick, yMinorTick] pol2cart(deg2rad(minorTickTheta(i)), tickRadiusMinor);plot(xMinorTick, yMinorTick, -, Color, [0 0 0], LineWidth, 1.5);
end
% 添加主刻度外的标签
labelDist maxRadius *(1 0.094); % 设定标签距离为最大半径(1 0.094)可以根据需要进行调整
for i 1:length(majorTheta)adjustedAngle majorTheta(i); % 从正北方开始并且顺时针增加 % 从正北方开始并且顺时针增加angle mod(adjustedAngle, 360); % 确保角度在0-360之间[xLabel, yLabel] pol2cart(deg2rad(90-adjustedAngle), labelDist);labelText sprintf(%.1f°, angle);text(xLabel, yLabel, labelText, HorizontalAlignment, center, VerticalAlignment, middle);
end 添加刮风数据添加数据和颜色、图列大小映射关系。
adjustedWindDirections 360 - windDirections;
[xWind, yWind] pol2cart(deg2rad(adjustedWindDirections 90), windFrequency);
colorGradient [0.0078, 0.0941, 0.7333; 0.9725, 0.0039, 0.5216];
colorMapMajor makeColorMap(colorGradient, length(windDirections));
% 根据风速大小对颜色进行排序
[~, idx] sort(maxWindSpeed, Ascend);
sortedColorMap colorMapMajor(idx, :);
% 对于相同的风速值使用第一个出现的颜色值为其赋色
uniqueSpeeds unique(maxWindSpeed, stable);
for i 1:length(uniqueSpeeds)currentSpeed uniqueSpeeds(i);indices find(maxWindSpeed currentSpeed);if length(indices) 1sortedColorMap(indices, :) repmat(sortedColorMap(indices(1), :), length(indices), 1);end
end
maxWind max(maxWindSpeed);
desiredMaxSizemax(avgWindSpeed);
desiredMinSizemin(avgWindSpeed);
for i 1:length(windDirections)color getColorForSpeed(maxWindSpeed(i), maxWind , colorMapMajor);s mapToMarkerSize(avgWindSpeed(i), desiredMaxSize, desiredMinSize);plot(xWind(i), yWind(i), o, LineWidth, 1.2, MarkerSize,s, ...MarkerEdgeColor, k, MarkerFaceColor, color);
end 颜色条绘制
colorMapMinor makeColorMap(colorGradient, 10);
colormap(colorMapMinor);
cBar colorbar;
cBar.Position [.9 .1 .04 .36];
cBar.LineWidth 1.2;
cBar.TickLength 0.025;
cBar.Ticks linspace(floor(min(maxWindSpeed)),ceil(max(maxWindSpeed)),11);
% cBar.Ticks linspace(minWindSpeed, maxWindSpeed, 11);
tickLabels arrayfun((x) sprintf(%.1f, x), cBar.Ticks, UniformOutput, false);
cBar.TickLabels tickLabels;
cBar.TickDirection both;
colorBarTitle title(cBar, 最大风速(m/s));
caxis([floor(min(maxWindSpeed)),ceil(max(maxWindSpeed))]);
AxSizeaxes(fig,Position,[.86 0.55 .1 .36],Color,[1,1,1]);
title(AxSize,平均风速(m/s))
AxSize.XColornone;
AxSize.YColornone;
meanRLabellinspace(ceil(0.3),ceil(2.6),5); 添加图列绘制
% 定义半径和距离
legRlinspace(ceil(min(avgWindSpeed)),ceil(max(avgWindSpeed)),5);
d ceil(ceil(max(avgWindSpeed))/2);
% 计算每个圆的中心位置
legY zeros(1, length(legR));
totalHeight sum(2.*legR) d*(length(legR)-1);
legY(1) totalHeight/2 - legR(1);
for i 2:length(legR)legY(i) legY(i-1) - 2*legR(i-1) - d;
end
% 绘制圆形
hold on;
for i 1:length(legR)rectangle(Position,[-legR(i), legY(i)-legR(i), 2*legR(i), 2*legR(i)], Curvature, [1, 1],LineWidth,1);text(max(legR) 0.6, legY(i), sprintf(%.1f, legR(i)));
end
axis equal;
xlim([-max(legR) max(legR)]);
ylim([legY(end)-legR(end) legY(1)legR(1)]);
hold off; 绘图工具箱介绍
默认绘图
figure(name,默认绘图)
wWindRosePlot(data);
w.plot(); 刻度颜色设置
figure(name,设置刻度颜色)
wWindRosePlot(data);
w.AxisColor[0,0,1];
w.AxisLineWidth2;
w.plot(); 刻度方向和长短设置其中刻度方向有in|out|both。
figure(name,设置刻度方向、长短)
wWindRosePlot(data);
w.AxisMainTickDirboth;
w.AxisMinorTickDirout;
w.AxisColor[1,0,0];
w.AxisLineWidth2;
w.AxisTickLength0.08;
w.plot(); 网格设置主、次网格的颜色、粗细、透明度设置。
figure(name,主、次网格样式、颜色、粗细、透明度)
wWindRosePlot(data);
w.RGridon;
w.RGridLineStyle-.;
w.RGridColor[1,0,0];
w.RGridAlpha0.5;
w.RGridLineWidth1.5;w.ThetaGridon;
w.ThetaGridLineStyle--;
w.ThetaGridColor[0,1,0];
w.ThetaGridAlpha0.5;
w.ThetaGridLineWidth2;w.MinorRGridon;
w.MinorRGridLineStyle-;
w.MinorRGridColor[1,1,0];w.MinorThetaGridon;
w.MinorThetaGridLineStyle:;
w.MinorThetaGridColor[0,0,1];
w.plot(); 背景颜色设置
figure(name,背景颜色)
wWindRosePlot(data);
w.ColorMapshsv;
w.AxisBackgroundColor[1,1,1]*0.10;
w.AxisFaceAlpha0.1;
w.plot(); 图列设置
figure(name,图列设置:title设置、背景色、边缘色、边缘粗细、字体属性)
wWindRosePlot(data);
w.LegendTitle图列设置Title;
w.LegendBackgroundColor[1,.9,.8]*.98;
w.LegendEdgeColorm;
w.LegendLineWidth4;
w.LegendFontNameTimes new Roman;
w.LegendFontSize16;
w.LegendFontAnglenormal;
w.LegendFontWeightbold;%加粗
w.plot(); 颜色条设置
figure(name,颜色条设置)
wWindRosePlot(data);
% load(colorsData/acton100.mat)
% load(colorsData/bwr.mat)
% load(colorsData/vikO100.mat)
% w.ColorMapscolorsList;
% w.ColorMapshsv;
% w.ColorMapsbone;
% w.ColorMapsjet;
% w.ColorMapswinter;
w.ColorMapsspring;
w.ColorMapsTitle颜色条 Title测试;
w.ColorMapsFontSize14;
w.ColorMapsFontAngleitalic;
w.plot(); WindRosePlot类函数
收藏学会
classdef WindRosePlot% ------------------------------------------------% Author: 好玩的 MATLAB.% E-mail: 2377389590qq.com% WeChat: idmatlab% Date: Oct 30, 2023.% Version: Matlab R2022b.% % #Respect the fruits of labor. Please note the tweet link and official account name when reprinting. Commercial use is strictly prohibited.% Example:% windDirections [0.0, 22.5, 45.0, 67.5, 90.0, 112.5, 135.0, 157.5, 180.0, 202.5, 225.0, 247.5, 270.0, 292.5, 315.0, 337.5];% windFrequency [10.2, 4, 4, 3.0, 4.0, 3.0, 4.0, 4.0, 7.0, 6.0, 3, 2, 2, 1.0, 3, 5];% maxWindSpeed [15, 12, 10, 5, 5, 5,10, 12, 13, 15, 12,5, 5, 10, 12, 15];% avgWindSpeed [2.8, 2.0, 1.5, 1.2, 1.4, 1.3, 1.45, 2.00, 2.80, 2.80, 1.50, 1.00, 1.0, 1.0, 1.8, 2.0];% % dataT table(windDirections, windFrequency, maxWindSpeed, avgWindSpeed, VariableNames, {风向, 频率, 最大风速, 平均风速});% data[windDirections,windFrequency,maxWindSpeed,avgWindSpeed];% wWindRosePlot(data);% w.plot();%-------------------------------------------------propertiesfig%WindDirections; %风向WindFrequency; %刮风频率MaxWindSpeed; %最大风速AvgWindSpeed; %平均风速%RGridon; %显示主 r 轴网格线ThetaGridon; %显示主 Theta 轴网格线MinorRGridon; %显示次 r 轴网格线MinorThetaGridon;%显示次 Theta 轴网格线%YLabel风向频率(%);% R主网格样式RGridLineStyle-;RGridColor[0,0,0];RGridAlpha1;RGridLineWidth0.5;% Theta 主网格样式ThetaGridLineStyle-;ThetaGridColor[0.8 0.8 0.8];ThetaGridAlpha1;ThetaGridLineWidth1.2;% R次网格样式MinorRGridLineStyle:;MinorRGridColor[0.55 0.55 0.55];MinorRGridAlpha1;MinorRGridLineWidth0.8;% Theta 次网格样式MinorThetaGridLineStyle-.MinorThetaGridColor[0.55 0.55 0.55];MinorThetaGridAlpha1;MinorThetaGridLineWidth1.2;% 刻度样式AxisColor[0,0,0];AxisLineWidth1.5;AxisMainTickDirin;AxisMinorTickDirin;AxisTickLength0.04;AxisTickFontSize12;AxisTickFontWeightnormal%normalboldAxisTickFontNameTimes new Roman;AxisFaceAlpha0.5;AxisBackgroundColor[1,1,1];% 颜色条ColorMaps[0.0078, 0.0941, 0.7333; 0.9725, 0.0039, 0.5216];ColorMapsTitle最大风速(m/s);ColorMapsFontNameTimes new Roman;ColorMapsFontSize12;ColorMapsFontAnglenormal;%normal | italic。ColorMapsFontWeightnormal; %normalbold%legend 图列LegendTitle平均风速(m/s);LegendBackgroundColor[1,1,1]*.95;LegendEdgeColornone;LegendLineWidth1;LegendFontNameTimes new Roman;LegendFontAngleitalic;%normal | italic。LegendFontSize12;LegendFontWeightnormal;LegendRotation0;endmethodsfunction obj WindRosePlot(data)obj.figgcf;obj.fig.Color[1,1,1];obj.WindDirections data(:,1);obj.WindFrequency data(:,2);obj.MaxWindSpeed data(:,3);obj.AvgWindSpeed data(:,4);%-------------------------obj.RGridon; obj.RGridLineStyle-; obj.RGridColor[0,0,0]; obj.RGridAlpha1; obj.RGridLineWidth0.5;obj.ThetaGridon; obj.ThetaGridLineStyle-; obj.ThetaGridColor[0.8 0.8 0.8]; obj.ThetaGridAlpha1; obj.ThetaGridLineWidth1.2;obj.MinorRGridon; obj.MinorRGridLineStyle:; obj.MinorRGridColor[0.55 0.55 0.55]; obj.MinorRGridAlpha1; obj.MinorRGridLineWidth0.8;obj.MinorThetaGridon;obj.MinorThetaGridLineStyle-.;obj.MinorThetaGridColor[0.55 0.55 0.55];obj.MinorThetaGridAlpha1;obj.MinorThetaGridLineWidth1.2;obj.ColorMaps [0.0078, 0.0941, 0.7333; 0.9725, 0.0039, 0.5216];endfunction plot(obj)maxRadius ceil(max(obj.WindFrequency));minRadius round(maxRadius / 10);dfTunique(diff(obj.WindDirections));allTheta 0:0.01:360;ax gca;hold on; box off; grid off; axis equal;ax.YLim [-maxRadius, maxRadius];ax.YMinorTick on;ax.XColor none;ax.XDir normal;ax.TickDir out;ax.LineWidth obj.AxisLineWidth;ax.YColorobj.AxisColor;majorTicksY ax.YTick;minorTicksY (majorTicksY(1:end-1) majorTicksY(2:end)) / 2;diffTicks unique(diff(majorTicksY));maxRadiusmax(ax.YTick)diffTicks/2;ax.YLim [-maxRadius, maxRadius];%重新设定ax.YAxis.MinorTickValues [minorTicksY(1)-diffTicks, minorTicksY, minorTicksY(end)diffTicks];ax.YTickLabel arrayfun((y) sprintf(%d, abs(y)), majorTicksY, UniformOutput, false);ax.YLabel.Stringobj.YLabel;% 绘制主要R Theta的极坐标网格线% # RGridmajorRadius majorTicksY(majorTicksY minRadius);if strcmpi(obj.RGrid,on)for i 1:length(majorRadius)[xMajor, yMajor] pol2cart(deg2rad(allTheta), majorRadius(i));plot(xMajor, yMajor,LineStyle,obj.RGridLineStyle,Color, [obj.RGridColor obj.RGridAlpha], LineWidth,obj.RGridLineWidth);endelseif strcmpi(obj.RGrid,off)end% # ThetaGridmajorTheta obj.WindDirections;fullRadius linspace(minRadius, maxRadius, 1000);if strcmpi(obj.ThetaGrid,on)for i 1:length(majorTheta)[xMajorT, yMajorT] pol2cart(deg2rad(majorTheta(i)), fullRadius);plot(xMajorT, yMajorT, LineStyle,obj.ThetaGridLineStyle, Color, [obj.ThetaGridColor obj.ThetaGridAlpha], LineWidth, obj.ThetaGridLineWidth);endelseif strcmpi(obj.ThetaGrid,off)end% 绘制次要R Theta的极坐标网格线% # MinorRGridif strcmpi(obj.MinorRGrid,on)minorRadius minorTicksY(minorTicksY minRadius);for i 1:length(minorRadius)[xMinor, yMinor] pol2cart(deg2rad(allTheta), minorRadius(i));plot(xMinor, yMinor, LineStyle,obj.MinorRGridLineStyle,Color, [obj.MinorRGridColor obj.MinorRGridAlpha], LineWidth,obj.MinorRGridLineWidth);endelseif strcmpi(obj.MinorRGrid,off)end% # MinorThetaGridminorThetaobj.WindDirectionsdfT/2;if strcmpi(obj.MinorThetaGrid,on)for i 1:length(minorTheta)[xMinorT, yMinorT] pol2cart(deg2rad(minorTheta(i)), fullRadius);plot(xMinorT, yMinorT, LineStyle,obj.MinorThetaGridLineStyle, Color, [obj.MinorThetaGridColor obj.MinorThetaGridAlpha], LineWidth, obj.MinorThetaGridLineWidth);endelseif strcmpi(obj.MinorThetaGrid,off)end% 绘制刻度% 绘制最外层的极坐标线[xOuter, yOuter] pol2cart(deg2rad(allTheta), max(ax.YTick)diffTicks/2);plot(xOuter, yOuter, -, Color,obj.AxisColor, LineWidth, obj.AxisLineWidth);fill(xOuter, yOuter,obj.AxisBackgroundColor,EdgeColor,none,FaceAlpha,obj.AxisFaceAlpha)% #主刻度if obj.AxisTickLength 1 || obj.AxisTickLength 0error(TickLength must be less than 1 and greater than 0.);endif strcmpi(obj.AxisMainTickDir,in)tickRadius [maxRadius*(1-obj.AxisTickLength), maxRadius];elseif strcmpi(obj.AxisMainTickDir,out)tickRadius [ maxRadius,maxRadius*(1obj.AxisTickLength)];elseif strcmpi(obj.AxisMainTickDir,both)tickRadius [maxRadius*(1-obj.AxisTickLength) maxRadius*(1obj.AxisTickLength)];elseerror(Invalid value for mainTickDir. It should be in, out, or both.);endmainTickTheta obj.WindDirectionsdfT;for i 1:length(mainTickTheta)[xMainTick, yMainTick] pol2cart(deg2rad(mainTickTheta(i)), tickRadius);plot(xMainTick, yMainTick, -, Color, obj.AxisColor, LineWidth, obj.AxisLineWidth);enddisp(char([20844 20247 21495 58 22909 29609 30340 77 97 116 108 97 98]))% #次刻度if strcmpi(obj.AxisMinorTickDir,in)tickRadiusMinor [maxRadius*(1-obj.AxisTickLength/2), maxRadius];elseif strcmpi(obj.AxisMinorTickDir,out)tickRadiusMinor [ maxRadius maxRadius*(1obj.AxisTickLength/2)];elseif strcmpi(obj.AxisMinorTickDir,both)tickRadiusMinor [maxRadius*(1-obj.AxisTickLength/2), maxRadius*(1obj.AxisTickLength/2)];elseerror(Invalid value for mainTickDir. It should be in, out, or both.);endminorTickThetaobj.WindDirectionsdfT/2;for i 1:length(minorTickTheta)[xMinorTick, yMinorTick] pol2cart(deg2rad(minorTickTheta(i)), tickRadiusMinor);plot(xMinorTick, yMinorTick, -, Color, obj.AxisColor, LineWidth, obj.AxisLineWidth*0.8);end% 添加主刻度外的标签labelDist maxRadius *(1 0.094); % 设定标签距离为最大半径(1 0.094)可以根据需要进行调整for i 1:length(majorTheta)adjustedAngle majorTheta(i); % 从正北方开始并且顺时针增加 % 从正北方开始并且顺时针增加angle mod(adjustedAngle, 360); % 确保角度在0-360之间[xLabel, yLabel] pol2cart(deg2rad(90-adjustedAngle), labelDist);labelText sprintf(%.1f°, angle);text(xLabel, yLabel, labelText, HorizontalAlignment, center, ...VerticalAlignment, middle, ...FontSize,obj.AxisTickFontSize,FontWeight,obj.AxisTickFontWeight,FontName,obj.AxisTickFontName, ...Color,obj.AxisColor);end%添加数据adjustedWindDirections 360 - obj.WindDirections;[xWind, yWind] pol2cart(deg2rad(adjustedWindDirections 90), obj.WindFrequency);colorMapMajor obj.makeColorMap(obj.ColorMaps, length(obj.WindDirections));% 根据风速大小对颜色进行排序[~, idx] sort(obj.MaxWindSpeed, Ascend);sortedColorMap colorMapMajor(idx, :);%对于相同的风速值使用第一个出现的颜色值为其赋色uniqueSpeeds unique(obj.MaxWindSpeed, stable);for i 1:length(uniqueSpeeds)currentSpeed uniqueSpeeds(i);indices find(obj.MaxWindSpeed currentSpeed);if length(indices) 1sortedColorMap(indices, :) repmat(sortedColorMap(indices(1), :), length(indices), 1);endendmaxWind max(obj.MaxWindSpeed);desiredMaxSizemax(obj.AvgWindSpeed);desiredMinSizemin(obj.AvgWindSpeed);for i 1:length(obj.WindDirections)color obj.getColorForSpeed(obj.MaxWindSpeed(i), maxWind , colorMapMajor);s obj.mapToMarkerSize(obj.AvgWindSpeed(i), desiredMaxSize, desiredMinSize);plot(xWind(i), yWind(i), o, LineWidth, 1.2, MarkerSize,s,...MarkerEdgeColor, k, MarkerFaceColor, color);end% 添加 colorbarcolorMapMinor obj.makeColorMap(obj.ColorMaps, 10);colormap(colorMapMinor);cBar colorbar;cBar.Position [.9 .1 .04 .36];cBar.LineWidth 1.2;cBar.TickLength 0.025;cBar.Ticks linspace(floor(min(obj.MaxWindSpeed)),ceil(max(obj.MaxWindSpeed)),11);tickLabels arrayfun((x) sprintf(%.1f, x), cBar.Ticks, UniformOutput, false);cBar.TickLabels tickLabels;cBar.TickDirection both;caxis([floor(min(obj.MaxWindSpeed)),ceil(max(obj.MaxWindSpeed))]);title(cBar, obj.ColorMapsTitle);cBar.FontName obj.ColorMapsFontName;cBar.FontSizeobj.ColorMapsFontSize;cBar.FontAngle obj.ColorMapsFontAngle;cBar.FontWeightobj.ColorMapsFontWeight; %normalbold% 添加 LegendlegAxaxes(obj.fig,Position,[.86 0.55 .1 .36],Color,[1,1,1],Box,on);title(legAx,obj.LegendTitle)legAx.Colorobj.LegendBackgroundColor;legAx.XColorobj.LegendEdgeColor;legAx.YColorobj.LegendEdgeColor;legAx.XTick[];legAx.YTick[];legAx.TickLength[0 0];legAx.LineWidthobj.LegendLineWidth;% 定义半径和距离legRlinspace(ceil(min(obj.AvgWindSpeed)),ceil(max(obj.AvgWindSpeed)),5);d ceil(ceil(max(obj.AvgWindSpeed))/2);legY zeros(1, length(legR));totalHeight sum(2.*legR) d*(length(legR)-1);legY(1) totalHeight/2 - legR(1);for i 2:length(legR)legY(i) legY(i-1) - 2*legR(i-1) - d;end% 绘制圆形hold on;for i 1:length(legR)rectangle(Position,[-legR(i), legY(i)-legR(i), 2*legR(i), 2*legR(i)], Curvature, [1, 1],LineWidth,1.5,FaceColor, white);text(max(legR) 0.9, legY(i), sprintf(%.1f, legR(i)), ...FontName,obj.LegendFontName,FontSize,obj. LegendFontSize,FontAngle,obj.LegendFontAngle, ...FontWeight,obj.LegendFontWeight,Rotation,obj.LegendRotation);endaxis equal;xlim([-max(legR)*1.2 max(legR)*1.2]);ylim([(legY(end)-legR(end))*1.1 (legY(1)legR(1))*1.1]);hold off;endendmethods(Accessprivate)function color getColorForSpeed(obj,speed, maxSpeed, colorMap)idx round((speed / maxSpeed) * size(colorMap, 1));idx min(max(idx, 1), size(colorMap, 1)); % 保证idx在正确的范围内color colorMap(idx, :);endfunction s mapToMarkerSize(obj,speed, maxSize, minSize)normalized (speed - minSize)/(maxSize -minSize);s minSize normalized * (maxSize - minSize);ss*10;endfunction cMapmakeColorMap(obj,colorlist,num)color.Num num;color.listcolorlist;for col1:size(color.list,2)x1:size(color.list,1);xilinspace(1,size(color.list,1),color.Num);color.map(:,col)interp1(x,color.list(:,col),xi);endcMapcolor.map;endend
end属性: fig存储图形的句柄。 WindDirections风向数据。 WindFrequency刮风频率。 MaxWindSpeed最大风速数据。 AvgWindSpeed平均风速数据。 RGridThetaGridMinorRGridMinorThetaGrid这些属性用于控制是否显示对应的网格线。 YLabelY轴标签。 还有许多其他的属性例如RGridLineStyleRGridColor等用于控制图形的样式和外观。
方法: 构造函数WindRosePlot当创建WindRosePlot类的对象时此构造函数将被调用。构造函数接收风玫瑰数据作为输入并初始化类的属性。此外还设置了默认的图形样式。 plot方法这个方法用于绘制风玫瑰图。它首先设置坐标轴和极坐标的属性。接下来它会绘制主要和次要的R和Theta网格线。然后它绘制刻度。