MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

这篇具有很好参考价值的文章主要介绍了MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

有粉丝问我这个图咋画:

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

我一看,这不就泰勒图嘛,就fileexchange上搜了一下泰勒图绘制代码,但是有的代码比较新的版本运行要改很多地方,有的代码需要包含一些压缩包没并没有的别人写的函数,于是我干脆自己写了个工具,想着如果大家用其他泰勒图绘制代码来不及修改的话,有多一次尝试机会吧。

复刻效果:

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

其他使用效果:

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

本文将分为大约四个部分:

  • 1 讲解泰勒图原理
  • 2 我写的工具函数基础使用教程
  • 3 属性修饰教程
  • 4 绘图复刻
  • 5 工具函数完整代码

1 泰勒图原理

泰勒图是Karl E. Taylor于2001年首先提出,主要用来比较几个气象模式模拟的能力,因此该表示方法在气象领域使用最多,但是在其他自然科学领域也有一定的应用。

这个图巧妙地利用了相关系数(COR)、均方根误差(RMSE/RMSD)和标准差(STD)三个评价指标之间的关系,巧妙地将三个变量的数据安排在了二维图上。

讲解一下公式和关系哈,为了避免误会后文中各个评价指标均用首字母代写( C , R , S C,R,S C,R,S),参考"标尺"使用小写字母 r r r,当前观察对象使用小写字母 f f f

标准差

S r = ∑ n = 1 N ( r n − r ˉ ) 2 N S f = ∑ n = 1 N ( f n − f ˉ ) 2 N \begin{aligned} &S_r = \sqrt{\frac{\sum_{n = 1}^{N}(r_n-\bar{r})^2}{N}}\\ &S_f = \sqrt{\frac{\sum_{n = 1}^{N}(f_n-\bar{f})^2}{N}} \end{aligned} Sr=Nn=1N(rnrˉ)2 Sf=Nn=1N(fnfˉ)2

均方根误差

R = ∑ n = 1 N ( ( f n − f ˉ ) − ( r n − r ˉ ) ) 2 N R = \sqrt{\frac{\sum_{n = 1}^{N}((f_n-\bar{f})-(r_n-\bar{r}))^2}{N}} R=Nn=1N((fnfˉ)(rnrˉ))2

相关系数

C = ∑ n = 1 N ( f n − f ˉ ) ( r n − r ˉ ) N S r S f C = \frac{\sum_{n = 1}^{N}(f_n-\bar{f})(r_n-\bar{r})}{NS_rS_f} C=NSrSfn=1N(fnfˉ)(rnrˉ)

余弦关系

就是很简单的差的平方展开式 ( a − b ) 2 = a 2 + b 2 − 2 a b (a-b)^2=a^2+b^2-2ab (ab)2=a2+b22ab,很容易能看出来:

R 2 = S r 2 + S f 2 − 2 S r S f C R^2=S_r^2+S_f^2-2S_rS_fC R2=Sr2+Sf22SrSfC

那我们如果把 C C C 看成 cos ⁡ ( θ ) \cos(\theta) cos(θ) 这不就余弦公式嘛,因此可以将其安排在一个图中:

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

就可以同时看出两组数据的各种统计量的相近程度。


2 我写的工具函数使用教程

2.1 数据预处理

数据首先要与标准数据对比计算标准差、中心均方根误差、相关系数,使用SStats函数,该函数会放在文末。

clc; clear
Data = load('testData.mat');
Data = Data.Data(:,1:end-1);

% Calculate STD RMSD and COR(计算标准差、中心均方根误差、相关系数)
STATS = zeros(4,size(Data,2));
for i = 1:size(Data,2)
    STATS(:,i) = SStats(Data(:,1),Data(:,i));
end
STATS(1,:) = [];

2.2 创建泰勒图坐标区域

% Create taylor axes(生成泰勒图坐标区域)
TD = STaylorDiag(STATS);

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

2.3 绘制散点

使用SPlot函数绘制,大概像下面这样(TD.SPlot),改形状就改Marker属性即可:

% Color list(颜色列表)
colorList = [0.3569    0.0784    0.0784
    0.6784    0.4471    0.1725
    0.1020    0.3882    0.5176
    0.1725    0.4196    0.4392
    0.2824    0.2275    0.2902];
MarkerType={'o','diamond','pentagram','^','v'};
% Plot(绘制散点图)
for i = 1:size(Data,2)
    TD.SPlot(STATS(1,i),STATS(2,i),STATS(3,i),'Marker',MarkerType{i},'MarkerSize',15,...
        'Color',colorList(i,:),'MarkerFaceColor',colorList(i,:));
end

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

2.4 添加图例

添加图例并标注标准数据组(使用SText函数):

% Legend
NameList = {'AAA','BBB','CCC','DDD','EEE'};
legend(NameList,'FontSize',13,'FontName','Times New Roman')

% Annotation
TD.SText(STATS(1,1),STATS(2,1),STATS(3,1),{'reference';' '},'FontWeight','bold',...
    'FontSize',20,'FontName','Times New Roman','Color',colorList(1,:),...
    'VerticalAlignment','bottom','HorizontalAlignment','center')

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

2.5 标注每个点

循环使用SText函数即可:

for i = 1:size(Data,2)
    TD.SText(STATS(1,i),STATS(2,i),STATS(3,i),"   "+string(NameList{i}),'FontWeight','bold',...
    'FontSize',14,'FontName','Times New Roman',...
    'VerticalAlignment','middle','HorizontalAlignment','left')
end

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图


3 属性修饰

统一使用set函数进行修改,大概这么用:

  • TD.set(对象名, 属性名, 属性值,…)

对象名就是由各个评价指标首字母( C , R , S C,R,S C,R,S)以及这个玩意的MATLAB内常用名称组合而成的,例如标准差轴就是SAxis,相关系数网格就是CGrid

3.1 基础属性

那些刻度长度啊,各个轴范围呀啥的要最先修饰。例如刻度长度:

TD.set('TickLength',[.015,.05])

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

各个轴范围:

TD.set('SLim',[0,300])
TD.set('RLim',[0,175])

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

主刻度及次刻度值:

TD.set('STickValues',0:50:300)
TD.set('SMinorTickValues',0:25:300)
TD.set('RTickValues',0:25:175)
TD.set('CTickValues',[.1,.2,.3,.4,.5,.6,.7,.8,.9,.95,.99])

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

3.2 网格属性

设置网格粗细及颜色:

% Set Grid(修饰各个网格)
TD.set('SGrid','Color',[.7,.7,.7],'LineWidth',1.5)
TD.set('RGrid','Color',[.77,.6,.18],'LineWidth',1.5)
TD.set('CGrid','Color',[0,0,.8],'LineStyle',':','LineWidth',.8);

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

3.3 标签属性

修饰轴标签及刻度标签:

% Set Tick Label(修饰刻度标签)
TD.set('STickLabelX','Color',[.8,0,0],'FontWeight','bold')
TD.set('STickLabelY','Color',[.8,0,0],'FontWeight','bold')
TD.set('RTickLabel','Color',[.77,.6,.18],'FontWeight','bold')
TD.set('CTickLabel','Color',[0,0,.8],'FontWeight','bold')

% Set Label(修饰标签)
TD.set('SLabel','Color',[.8,0,0],'FontWeight','bold')
TD.set('CLabel','Color',[0,0,.8],'FontWeight','bold')

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

3.4 轴属性

设置轴颜色、粗细:

% Set Axis(修饰各个轴)
TD.set('SAxis','Color',[.8,0,0],'LineWidth',2)
TD.set('CAxis','Color',[0,0,.8],'LineWidth',2)

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

3.5 刻度属性

刻度粗细、颜色、线型啥的都能设置:

% Set Tick and MinorTick(修饰主次刻度)
TD.set('STick','Color',[.8,0,0],'LineWidth',8)
TD.set('CTick','Color',[0,0,.8],'LineWidth',8)
TD.set('SMinorTick','Color',[.8,0,0],'LineWidth',5)
TD.set('CMinorTick','Color',[0,0,.8],'LineWidth',5)

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图


4 绘图复刻

4.1 数据说明

没去找原始论文数据,这里随便用了组数据且四个坐标区域用的数据也一样,到时候大家可自行更换:

clc; clear
Data = load('testData.mat');
Data = Data.Data;
% % 不想下数据的可以用随便捏造的数据试试
% % 随便捏造了点数据(Made up some data casually)
% Data = randn(100,6).*.2+[(linspace(-1,.5,100)').*ones(1,2),...
%                          (linspace(-.5,.7,100)').*ones(1,2),...
%                          (linspace(-.9,.2,100)').*ones(1,2)];

% Calculate STD RMSD and COR(计算标准差、中心均方根误差、相关系数)
STATS = zeros(4,size(Data,2));
for i = 1:size(Data,2)
    STATS(:,i) = SStats(Data(:,1),Data(:,i));
end
STATS(1,:) = [];

4.2 子图创建

硬创建呗:

%% Create figure and axes(生成基础布局)
fig=figure('Units','normalized','Position',[.2,.1,.54,.74]);
bkgAx=axes(fig,'Position',[.13,.11,.67,.88],'XTick',[],'YTick',[],'Box','on',...
    'Color',[253,228,203]./255,'XLim',[0,100],'YLim',[0,88],'NextPlot','add');
plot(bkgAx,[50,50],[0,88],'Color','k','LineWidth',.8)
text(bkgAx,25,42,'Autumn','FontSize',16,'FontName','Times New Roman','HorizontalAlignment','center')
text(bkgAx,75,42,'Winter','FontSize',16,'FontName','Times New Roman','HorizontalAlignment','center')
text(bkgAx,25,86,'Spring','FontSize',16,'FontName','Times New Roman','HorizontalAlignment','center')
text(bkgAx,75,86,'Summer','FontSize',16,'FontName','Times New Roman','HorizontalAlignment','center')
bkgAx.XLabel.String='Standard Deviation(mm month^{-1})';
bkgAx.XLabel.FontSize=18;
bkgAx.XLabel.FontName='Times New Roman';
bkgAx.XLabel.Position=[50,-3,-1];
bkgAx.YLabel.String='Standard Deviation(mm month^{-1})';
bkgAx.YLabel.FontSize=18;
bkgAx.YLabel.FontName='Times New Roman';
bkgAx.YLabel.Position=[-7,44,-1];
% -------------------------------------------------------------------------
ax1 = axes(fig,'Position',[.13,.11,.335,.4],'Box','on');
ax2 = axes(fig,'Position',[.465,.11,.335,.4],'Box','on');
ax3 = axes(fig,'Position',[.13,.55,.335,.4],'Box','on');
ax4 = axes(fig,'Position',[.465,.55,.335,.4],'Box','on');

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图

4.3 创建泰勒图坐标区域

可以将第一个参数换成坐标区域对象,就能将特定坐标区域修改成泰勒图坐标区域,以下是生成后做了点属性调整:

%% Create taylor axes(生成泰勒图坐标区域)
TD1 = STaylorDiag(ax1,STATS);
set(ax1,'Box','on','XTick',[],'YTick',[],'XColor','k','YColor','k',...
    'XLim',TD1.SLim.*1.13,'YLim',TD1.SLim.*1.15);
TD1.set('SLabel','Color','none');
TD1.set('RGrid','Color',[.77,.6,.18],'LineWidth',1.2)
TD1.set('RTickLabel','Color',[.77,.6,.18],'FontWeight','bold')
TD1.set('CLabel','FontSize',16)

TD2 = STaylorDiag(ax2,STATS);
set(ax2,'Box','on','XTick',[],'YTick',[],'XColor','k','YColor','k',...
    'XLim',TD2.SLim.*1.13,'YLim',TD2.SLim.*1.15);
TD2.set('SLabel','Color','none');
TD2.set('STickLabelY','Color','none');
TD2.set('RGrid','Color',[.77,.6,.18],'LineWidth',1.2)
TD2.set('RTickLabel','Color',[.77,.6,.18],'FontWeight','bold')
TD2.set('CLabel','FontSize',16)

TD3 = STaylorDiag(ax3,STATS);
set(ax3,'Box','on','XTick',[],'YTick',[],'XColor','k','YColor','k',...
    'XLim',TD2.SLim.*1.13,'YLim',TD2.SLim.*1.15);
TD3.set('SLabel','Color','none');
TD3.set('STickLabelX','Color','none');
TD3.set('RGrid','Color',[.77,.6,.18],'LineWidth',1.2)
TD3.set('RTickLabel','Color',[.77,.6,.18],'FontWeight','bold')
TD3.set('CLabel','FontSize',16)

TD4 = STaylorDiag(ax4,STATS);
set(ax4,'Box','on','XTick',[],'YTick',[],'XColor','k','YColor','k',...
    'XLim',TD2.SLim.*1.13,'YLim',TD2.SLim.*1.15);
TD4.set('SLabel','Color','none');
TD4.set('STickLabelX','Color','none');
TD4.set('STickLabelY','Color','none');
TD4.set('RGrid','Color',[.77,.6,.18],'LineWidth',1.2)
TD4.set('RTickLabel','Color',[.77,.6,.18],'FontWeight','bold')
TD4.set('CLabel','FontSize',16)

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图


4.4 绘制散点

最后一组散点绘制后对象被存到lgdPltHdl的矩阵,这是为了之后生成图例方便(只显示第2-6组数据的图例,不显示标准数据):

%% 绘制散点
% Color list(颜色列表)
colorList = [145,81,155;217,34,30;68,127,183;76,181,75;145,81,155;248,130,7]./255;
% Plot(绘制散点图)
for i = 1:size(Data,2)
    TD1.SPlot(STATS(1,i),STATS(2,i),STATS(3,i),'Marker','o','MarkerSize',10,...
        'Color',colorList(i,:),'MarkerFaceColor',colorList(i,:));
    TD2.SPlot(STATS(1,i),STATS(2,i),STATS(3,i),'Marker','o','MarkerSize',10,...
        'Color',colorList(i,:),'MarkerFaceColor',colorList(i,:));
    TD3.SPlot(STATS(1,i),STATS(2,i),STATS(3,i),'Marker','o','MarkerSize',10,...
        'Color',colorList(i,:),'MarkerFaceColor',colorList(i,:));
    lgdPltHdl(i)=TD4.SPlot(STATS(1,i),STATS(2,i),STATS(3,i),'Marker','o','MarkerSize',10,...
        'Color',colorList(i,:),'MarkerFaceColor',colorList(i,:));
end

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图


4.5 添加图例和标注

% legend
lgdHdl = legend(ax4,lgdPltHdl(2:end),{'# 1 1/x','# 2 e\^-x(x/0.1\^2)','# 3 e\^-x(x/0.5\^2)','# 4 e\^-x(x/0.2\^2)','# 5 e\^-x(x/0.25\^2)'},...
    'Position',[.825,.47,0.15,0.2]);
lgdHdl.Title.String='Weighting Scheme';
lgdHdl.Title.FontSize=14;
lgdHdl.Title.FontName='Times New Roman';
lgdHdl.FontSize=12;
lgdHdl.FontName='Times New Roman';
lgdHdl.Box='off';
% Annotation
TD1.SText(STATS(1,1),STATS(2,1),STATS(3,1),{'observed';''},'FontWeight','bold',...
    'FontSize',13,'FontName','Times New Roman','Color',colorList(1,:),...
    'VerticalAlignment','bottom','HorizontalAlignment','center');
TD2.SText(STATS(1,1),STATS(2,1),STATS(3,1),{'observed';''},'FontWeight','bold',...
    'FontSize',13,'FontName','Times New Roman','Color',colorList(1,:),...
    'VerticalAlignment','bottom','HorizontalAlignment','center');
TD3.SText(STATS(1,1),STATS(2,1),STATS(3,1),{'observed';''},'FontWeight','bold',...
    'FontSize',13,'FontName','Times New Roman','Color',colorList(1,:),...
    'VerticalAlignment','bottom','HorizontalAlignment','center');
TD4.SText(STATS(1,1),STATS(2,1),STATS(3,1),{'observed';''},'FontWeight','bold',...
    'FontSize',13,'FontName','Times New Roman','Color',colorList(1,:),...
    'VerticalAlignment','bottom','HorizontalAlignment','center');
text(ax1,TD1.SLim(2),TD1.SLim(2),'RMS error','Color',[.77,.6,.18],...
    'VerticalAlignment','bottom','HorizontalAlignment','right',...
    'FontSize',15,'FontName','Times New Roman','FontWeight','bold')
text(ax2,TD1.SLim(2),TD1.SLim(2),'RMS error','Color',[.77,.6,.18],...
    'VerticalAlignment','bottom','HorizontalAlignment','right',...
    'FontSize',15,'FontName','Times New Roman','FontWeight','bold')
text(ax3,TD1.SLim(2),TD1.SLim(2),'RMS error','Color',[.77,.6,.18],...
    'VerticalAlignment','bottom','HorizontalAlignment','right',...
    'FontSize',15,'FontName','Times New Roman','FontWeight','bold')
text(ax4,TD1.SLim(2),TD1.SLim(2),'RMS error','Color',[.77,.6,.18],...
    'VerticalAlignment','bottom','HorizontalAlignment','right',...
    'FontSize',15,'FontName','Times New Roman','FontWeight','bold')

MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图


5 工具函数完整代码

5.1 SStats

function Data=SStats(Cr,Cf)
% Copyright (c) 2023, Zhaoxu Liu / slandarer
% Zhaoxu Liu / slandarer (2023). taylor diagram class 
% (https://www.mathworks.com/matlabcentral/fileexchange/130889-taylor-diagram-class), 
% MATLAB Central File Exchange.
Cr = Cr(:); 
Cf = Cf(:);
nanInd = isnan(Cr)|isnan(Cf);
Cr(nanInd) = [];
Cf(nanInd) = [];

% N  = length(Cf);
MEAN = mean(Cf);
STD  = std(Cf,1);
RMSD = std(Cf-Cr,1);
COR  = corrcoef(Cf,Cr);
Data = [MEAN, STD, RMSD, COR(1,2)].';

%% calculation formula of STD RMSD and COR
% N = length(Cf);
%
% 		    /  sum[ {C-mean(C)} .^2]  \
% STD = sqrt|  ---------------------  |
% 		    \          N              /
%
% Equivalent calculation formula:
% STD = sqrt(sum((Cf-mean(Cf)).^2)./N);
% STD = norm(Cf-mean(Cf))./sqrt(N);
% STD = rms(Cf-mean(Cf));
% STD = sqrt(var(Cf,1));
% STD = std(Cf,1);
  

% 		     /  sum[  { [C-mean(C)] - [Cr-mean(Cr)] }.^2  ]  \
% RMSD = sqrt|  -------------------------------------------  |
% 		     \                      N                        /
% 
% Equivalent calculation formula:
% RMSD = sqrt(sum((Cf-mean(Cf)-(Cr-mean(Cr))).^2)./N);
% RMSD = norm(Cf-mean(Cf)-Cr+mean(Cr))./sqrt(N);
% RMSD = rmse(Cr-mean(Cr),Cf-mean(Cf));
% RMSD = rms(Cf-mean(Cf)-Cr+mean(Cr));
% RMSD = sqrt(var(Cf-Cr,1));
% RMSD = std(Cf-Cr,1);


% 		sum( [C-mean(C)].*[Cr-mean(Cr)] ) 
% COR = --------------------------------- 
% 		         N*STD(C)*STD(Cr)
%
% Equivalent calculation formula:
% COR = sum((Cf-mean(Cf)).*(Cr-mean(Cr)))./N./std(Cf,1)./std(Cr,1);
% COR = (Cf-mean(Cf)).'*(Cr-mean(Cr))./N./std(Cf,1)./std(Cr,1);
% COR = [1,0]*cov(Cf,Cr,1)./std(Cf,1)./std(Cr,1)*[0;1];
% COR = [1,0]*corrcoef(Cf,Cr)*[0;1];
end

5.2 STaylorDiag

classdef STaylorDiag < handle
% Copyright (c) 2023, Zhaoxu Liu / slandarer
    properties
        STATS;  % STD RMSD and COR
        ax; TickLength=[.015,.008];
        % S-Axis means STD Axis
        SAxis; RAxis; CAxis;
        SGrid; RGrid; CGrid;
        SLabel; RLabel; CLabel;   
        STickLabelX; STickLabelY; RTickLabel; CTickLabel;
        % STD Tick and MinorTick
        STick; SMinorTick; STickValues; SMinorTickValues; SLim;
        %
        RTickValues; RLim;
        %
        CTick; CMinorTick; CLim = [0,1];
        CTickValues=[.1,.3,.5,.7,.9,.95,.99];
        CMinorTickValues=[.05,.15,.2,.25,.35,.4,.45,.55,.6,.65,.75,.8,.85,.91,.92,.93,.94,.96,.97,.98,1]; 
    end
    methods
        function obj = STaylorDiag(varargin)
            if isa(varargin{1},'matlab.graphics.axis.Axes')
                obj.ax = varargin{1}; varargin(1) = [];
            else
                obj.ax = gca;
            end
            obj.STATS = varargin{1};
            obj.ax.Parent.Color = [1,1,1];
            obj.ax.NextPlot = 'add';
            obj.ax.XGrid = 'off';
            obj.ax.YGrid = 'off';
            obj.ax.Box = 'off';
            obj.ax.DataAspectRatio = [1,1,1];
            % -------------------------------------------------------------
            obj.SLim = [0,max(obj.STATS(1,:)).*1.15];
            obj.ax.XLim = obj.SLim;
            obj.STickValues = obj.ax.XTick;
            obj.RLim = [0,max(obj.STATS(2,:)).*1.15];
            obj.ax.XLim = obj.RLim;
            obj.RTickValues = obj.ax.XTick;
            obj.RTickValues(1) = [];
            obj.ax.XLim = obj.SLim; obj.ax.YLim = obj.SLim;
            obj.SMinorTickValues = ...
                linspace(obj.STickValues(1),obj.STickValues(end),(length(obj.STickValues)-1).*5+1);
            obj.SMinorTickValues=setdiff(obj.SMinorTickValues,obj.STickValues);
            obj.CMinorTickValues=setdiff(obj.CMinorTickValues,obj.CTickValues);
            % -------------------------------------------------------------
            % STD Tick, MinorTick, Grid, TickLabel
            [tYTickX,tYTickY,tYTickMX,tYTickMY,tRGridX,tRGridY] = obj.getSValue();
            obj.SGrid = plot(obj.ax,tRGridX(:),tRGridY(:),'LineWidth',.5,'Color','k');
            obj.SAxis = plot(obj.ax,[0,0,obj.SLim(2)],[obj.SLim(2),0,0],'LineWidth',1.2,'Color','k');
            obj.STick = plot(obj.ax,[tYTickX(:);tYTickY(:)],[tYTickY(:);tYTickX(:)],'LineWidth',.8,'Color','k');
            obj.SMinorTick = plot(obj.ax,[tYTickMX(:);tYTickMY(:)],[tYTickMY(:);tYTickMX(:)],'LineWidth',.8,'Color','k');
            obj.STickLabelX = text(obj.ax,obj.STickValues,0.*obj.STickValues,string(obj.STickValues),...
                'FontName','Times New Roman','FontSize',13,'VerticalAlignment','top','HorizontalAlignment','center');
            obj.STickLabelY = text(obj.ax,0.*obj.STickValues(2:end),obj.STickValues(2:end),string(obj.STickValues(2:end))+" ",...
                'FontName','Times New Roman','FontSize',13,'VerticalAlignment','middle','HorizontalAlignment','right');
            obj.SLabel = text(obj.ax,obj.ax.YLabel.Position(1),obj.ax.YLabel.Position(2),'Standard Deviation',...
                'FontName','Times New Roman','FontSize',20,'VerticalAlignment','bottom','HorizontalAlignment','center','Rotation',90);
            obj.SGrid.Annotation.LegendInformation.IconDisplayStyle='off';
            obj.SAxis.Annotation.LegendInformation.IconDisplayStyle='off';
            obj.STick.Annotation.LegendInformation.IconDisplayStyle='off';
            obj.SMinorTick.Annotation.LegendInformation.IconDisplayStyle='off';
            % -------------------------------------------------------------
            % RMSD Grid TickLabel
            [tR2GridX,tR2GridY] = obj.getRValue();
            obj.RGrid = plot(obj.ax,tR2GridX(:),tR2GridY(:),'LineWidth',.5,'Color','k','LineStyle','--');
            obj.RTickLabel = text(obj.ax,cos(pi*5/6).*obj.RTickValues+obj.STATS(1,1),sin(pi*5/6).*obj.RTickValues,string(obj.RTickValues),...
                'FontName','Times New Roman','FontSize',13,'VerticalAlignment','bottom','HorizontalAlignment','center','Rotation',60);
            obj.RGrid.Annotation.LegendInformation.IconDisplayStyle='off';
            % -------------------------------------------------------------
            % RMSD^2 = STD_r^2 + STD_f^2 - 2*STD_r*STD_f*COR
            %
            %        STD_r^2 + STD_f^2 - RMSD^2
            % COR = ----------------------------
            %              2*STD_r*STD_f
            %
            [tCAxisX,tCAxisY,tTRMSD,tCTickX,tCTickY,tCTickMX,tCTickMY,tRMSDGridX,tRMSDGridY]=obj.getCValue();
            obj.CGrid = plot(obj.ax,tRMSDGridX(:),tRMSDGridY(:),'LineWidth',.5,'Color',[.8,.8,.8],'LineStyle','-');
            obj.CAxis = plot(obj.ax,tCAxisX,tCAxisY,'LineWidth',1.2,'Color','k');
            obj.CTick = plot(obj.ax,tCTickX(:),tCTickY(:),'LineWidth',.8,'Color','k');
            obj.CMinorTick = plot(obj.ax,tCTickMX(:),tCTickMY(:),'LineWidth',.8,'Color','k');
            for i=1:length(tTRMSD)
                obj.CTickLabel{i} = text(obj.ax,cos(tTRMSD(i)).*obj.SLim(2),sin(tTRMSD(i)).*obj.SLim(2)," "+string(obj.CTickValues(i)),...
                    'FontName','Times New Roman','FontSize',13,'VerticalAlignment','middle','HorizontalAlignment','left','Rotation',tTRMSD(i)./pi.*2.*90);
            end
            obj.CLabel = text(obj.ax,cos(pi/4).*(obj.SLim(2)-obj.ax.YLabel.Position(1)),...
                sin(pi/4).*(obj.SLim(2)-obj.ax.YLabel.Position(1)),'Correlation',...
                'FontName','Times New Roman','FontSize',20,'VerticalAlignment','bottom','HorizontalAlignment','center','Rotation',-45);
            obj.CGrid.Annotation.LegendInformation.IconDisplayStyle='off';
            obj.CAxis.Annotation.LegendInformation.IconDisplayStyle='off';
            obj.CTick.Annotation.LegendInformation.IconDisplayStyle='off';
            obj.CMinorTick.Annotation.LegendInformation.IconDisplayStyle='off';
            % -------------------------------------------------------------
            obj.ax.XColor = 'none';
            obj.ax.YColor = 'none';
        end
        % =================================================================
        function [tYTickX,tYTickY,tYTickMX,tYTickMY,tRGridX,tRGridY]=getSValue(obj)
            tTPi_2 = linspace(0,pi/2,200).';
            tYTickX = [0.*obj.STickValues;obj.STickValues.*0+obj.TickLength(1).*obj.SLim(2);nan.*obj.STickValues];
            tYTickY = [obj.STickValues;obj.STickValues;nan.*obj.STickValues];
            tYTickMX = [0.*obj.SMinorTickValues;obj.SMinorTickValues.*0+obj.TickLength(2).*obj.SLim(2);nan.*obj.SMinorTickValues];
            tYTickMY = [obj.SMinorTickValues;obj.SMinorTickValues;nan.*obj.SMinorTickValues];
            tRGridX = [obj.STickValues.*cos(repmat(tTPi_2,[1,length(obj.STickValues)]));nan.*obj.STickValues];
            tRGridY = [obj.STickValues.*sin(repmat(tTPi_2,[1,length(obj.STickValues)]));nan.*obj.STickValues];
        end
        function [tR2GridX,tR2GridY]=getRValue(obj)
            tTPi = linspace(0,pi,200).';
            tR2GridX = [obj.RTickValues.*cos(repmat(tTPi,[1,length(obj.RTickValues)]));nan.*obj.RTickValues]+obj.STATS(1,1);
            tR2GridY = [obj.RTickValues.*sin(repmat(tTPi,[1,length(obj.RTickValues)]));nan.*obj.RTickValues];
            tR2GridN = sqrt(tR2GridX.^2+tR2GridY.^2)>obj.SLim(2);
            tR2GridX(tR2GridN) = nan; tR2GridY(tR2GridN) = nan;
        end
        function [tCAxisX,tCAxisY,tTRMSD,tCTickX,tCTickY,tCTickMX,tCTickMY,tRMSDGridX,tRMSDGridY]=getCValue(obj)
            tTPi_2 = linspace(0,pi/2,200).';
            tCAxisX = cos(tTPi_2).*obj.SLim(2);
            tCAxisY = sin(tTPi_2).*obj.SLim(2);
            tRMSD = sqrt(2.*(obj.STATS(1,1).^2)-2.*(obj.STATS(1,1).^2).*obj.CTickValues);
            tTRMSD = asin(tRMSD./2./obj.STATS(1,1)).*2;
            tCTickX = [cos(tTRMSD).*obj.SLim(2);cos(tTRMSD).*obj.SLim(2).*(1-obj.TickLength(1));tTRMSD.*nan];
            tCTickY = [sin(tTRMSD).*obj.SLim(2);sin(tTRMSD).*obj.SLim(2).*(1-obj.TickLength(1));tTRMSD.*nan];
            tRMSDM = sqrt(2.*(obj.STATS(1,1).^2)-2.*(obj.STATS(1,1).^2).*obj.CMinorTickValues);
            tTRMSDM = asin(tRMSDM./2./obj.STATS(1,1)).*2;
            tCTickMX = [cos(tTRMSDM).*obj.SLim(2);cos(tTRMSDM).*obj.SLim(2).*(1-obj.TickLength(2));tTRMSDM.*nan];
            tCTickMY = [sin(tTRMSDM).*obj.SLim(2);sin(tTRMSDM).*obj.SLim(2).*(1-obj.TickLength(2));tTRMSDM.*nan];
            tRMSDGridX = [cos(tTRMSD).*obj.SLim(2);0.*tTRMSD;nan.*tTRMSD];
            tRMSDGridY = [sin(tTRMSD).*obj.SLim(2);0.*tTRMSD;nan.*tTRMSD];
        end
        % =================================================================
        function pltHdl=SPlot(obj,STD,~,COR,varargin)
            tTheta = acos(COR);
            pltHdl = plot(obj.ax,cos(tTheta).*STD,sin(tTheta).*STD,varargin{:},'LineStyle','none');
        end
        function txtHdl=SText(obj,STD,~,COR,varargin)
            tTheta = acos(COR);
            txtHdl = text(obj.ax,cos(tTheta).*STD,sin(tTheta).*STD,varargin{:});
        end
        % =================================================================
        function set(obj,target,varargin)
            if isa(varargin{1},'char')||isa(varargin{1},'string')
            switch target
                case {'SAxis','CAxis','SLabel','CLabel','STick','CTick','SMinorTick','CMinorTick','RTickLabel','SGrid','RGrid','CGrid'}
                    set(obj.(target),varargin{:});
                case 'STickLabelX'
                    set(obj.STickLabelX,varargin{:});
                case 'STickLabelY'
                    set(obj.STickLabelY,varargin{:});
                case 'CTickLabel'
                    for i=1:length(obj.CTickLabel)
                        set(obj.CTickLabel{i},varargin{:});
                    end
            end
            else
                oriRLim = obj.RLim;
                obj.(target) = varargin{1};
                obj.ax.XColor = 'k';
                obj.ax.YColor = 'k';
                if abs(obj.SLim(2)-obj.ax.XLim(2))>eps||abs(obj.RLim(2)-oriRLim(2))>eps
                    obj.ax.XLim = obj.SLim;
                    obj.STickValues = obj.ax.XTick;
                    obj.ax.XLim = obj.RLim;
                    obj.RTickValues = obj.ax.XTick;
                    obj.RTickValues(1) = [];
                    obj.ax.XLim = obj.SLim; obj.ax.YLim = obj.SLim;
                    obj.SMinorTickValues = ...
                        linspace(obj.STickValues(1),obj.STickValues(end),(length(obj.STickValues)-1).*5+1);
                end
                obj.(target) = varargin{1};
                obj.SMinorTickValues=setdiff(obj.SMinorTickValues,obj.STickValues);
                obj.CMinorTickValues=setdiff(obj.CMinorTickValues,obj.CTickValues);        
                %
                [tYTickX,tYTickY,tYTickMX,tYTickMY,tRGridX,tRGridY] = obj.getSValue();
                set(obj.SGrid,'XData',tRGridX(:),'YData',tRGridY(:));
                set(obj.SAxis,'XData',[0,0,obj.SLim(2)],'YData',[obj.SLim(2),0,0]);
                set(obj.STick,'XData',[tYTickX(:);tYTickY(:)],'YData',[tYTickY(:);tYTickX(:)]);
                set(obj.SMinorTick,'XData',[tYTickMX(:);tYTickMY(:)],'YData',[tYTickMY(:);tYTickMX(:)]);
                delete(obj.STickLabelX);delete(obj.STickLabelY);delete(obj.SLabel)
                obj.STickLabelX = text(obj.ax,obj.STickValues,0.*obj.STickValues,string(obj.STickValues),...
                    'FontName','Times New Roman','FontSize',13,'VerticalAlignment','top','HorizontalAlignment','center');
                obj.STickLabelY = text(obj.ax,0.*obj.STickValues(2:end),obj.STickValues(2:end),string(obj.STickValues(2:end))+" ",...
                    'FontName','Times New Roman','FontSize',13,'VerticalAlignment','middle','HorizontalAlignment','right');
                obj.SLabel = text(obj.ax,obj.ax.YLabel.Position(1),obj.ax.YLabel.Position(2),'Standard Deviation',...
                    'FontName','Times New Roman','FontSize',20,'VerticalAlignment','bottom','HorizontalAlignment','center','Rotation',90);
                %
                [tR2GridX,tR2GridY] = obj.getRValue();
                set(obj.RGrid,'XData',tR2GridX(:),'YData',tR2GridY(:));
                delete(obj.RTickLabel)
                obj.RTickLabel = text(obj.ax,cos(pi*5/6).*obj.RTickValues+obj.STATS(1,1),sin(pi*5/6).*obj.RTickValues,string(obj.RTickValues),...
                    'FontName','Times New Roman','FontSize',13,'VerticalAlignment','bottom','HorizontalAlignment','center','Rotation',60);
                %
                [tCAxisX,tCAxisY,tTRMSD,tCTickX,tCTickY,tCTickMX,tCTickMY,tRMSDGridX,tRMSDGridY]=obj.getCValue();
                set(obj.CGrid,'XData',tRMSDGridX(:),'YData',tRMSDGridY(:));
                set(obj.CAxis,'XData',tCAxisX,'YData',tCAxisY);
                set(obj.CTick,'XData',tCTickX(:),'YData',tCTickY(:));
                set(obj.CMinorTick,'XData',tCTickMX(:),'YData',tCTickMY(:));
                for i=length(obj.CTickLabel):-1:1
                    delete(obj.CTickLabel{i});
                end
                delete(obj.CLabel);
                for i=1:length(tTRMSD)
                    obj.CTickLabel{i} = text(obj.ax,cos(tTRMSD(i)).*obj.SLim(2),sin(tTRMSD(i)).*obj.SLim(2)," "+string(obj.CTickValues(i)),...
                        'FontName','Times New Roman','FontSize',13,'VerticalAlignment','middle','HorizontalAlignment','left','Rotation',tTRMSD(i)./pi.*2.*90);
                end
                obj.CLabel = text(obj.ax,cos(pi/4).*(obj.SLim(2)-obj.ax.YLabel.Position(1)),...
                    sin(pi/4).*(obj.SLim(2)-obj.ax.YLabel.Position(1)),'Correlation',...
                    'FontName','Times New Roman','FontSize',20,'VerticalAlignment','bottom','HorizontalAlignment','center','Rotation',-45);
                obj.ax.XColor = 'none';
                obj.ax.YColor = 'none';
            end
        end
    end
end

未经允许本代码请勿作商业用途,引用的话可以引用我file exchange上的链接,可使用如下格式:

Zhaoxu Liu / slandarer (2023). taylor diagram class (https://www.mathworks.com/matlabcentral/fileexchange/130889-taylor-diagram-class), MATLAB Central File Exchange. 检索来源 2023/6/11.

若转载请保留以上file exchange链接及本文链接!!!!!

本文全部代码已同时上传gitee仓库,可从gitee或者fileexchange下载:

https://gitee.com/slandarer/PLTreprint文章来源地址https://www.toymoban.com/news/detail-480029.html

到了这里,关于MATLAB | 绘图复刻(九) | 泰勒图及组合泰勒图的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 还在被机组组合问题困扰?快来试试这个用处极大的考虑安全约束机组组合模型!

    前言 所谓安全约束机组组合,即在满足电力系统安全性约束的条件下,以系统购电成本最低等为优化目标,制定多时段的机组开停机计划。 机组组合(Unit commitment, Uc)优化问题旨在电力系统运行时,安全给定以及调整发电机组的启/停与实时出力,使发电机组的总运行成本最小

    2024年03月27日
    浏览(52)
  • Matlab中的基本绘图操作,Matlab中如何绘图

    目录 一.示例基本程序 二.图片 三.说明         1.首先应该给定初值 2.matlab中的Π用pi代替 3.figure的作用是建立一个幕布,有时可以不写 4.plot( x=sin(x))作用是绘制一幅 x=sin(x)当前函数的图 5.title(\\\'   x=sin(x) \\\')的中可以添加图片的标题 x=sin(x) 6.xlabel(‘  x   ’)与ylabel(

    2024年02月16日
    浏览(33)
  • Matlab绘图系列教程-Matlab 34 种绘图函数示例(下)

    1.1 简介 关于本教程的目的与范围 欢迎来到Matlab绘图指南!本教程的目标是帮助您从一个绘图小白蜕变为Matlab绘图大神。无论您是科学研究人员、学生还是对数据可视化感兴趣的爱好者,本教程将为您揭示绘制高质量科学图表的技巧和策略,让您的图表在论文和报告中脱颖而

    2024年02月13日
    浏览(41)
  • Matlab绘图系列教程-基础绘图:柱状图 (bar函数 )

    4.1 介绍 4.1.1 引言 柱状图是一种常用的数据可视化方式,用于比较不同类别的数据或展示数据的分布。在Matlab中,使用 bar 函数可以轻松地绘制出精美的柱状图。本篇博客将为您介绍如何使用Matlab绘制优雅的柱状图,展示数据的视觉效果和科研价值。 4.1.2 目标和受众 本篇博客

    2024年02月12日
    浏览(45)
  • Matlab学习——初阶绘图

    此时会根据x、y的值来画图 结果: 此时x会默认从1开始等差数列的取值,而y是和我们规定的值一致。 输出:  输出: 输出:  hold on 保持原来的图,使其不会被新的图给覆盖调 hoid off 解除hold on,使得新的图会覆盖原来的图 输出:  xlable()指定x轴方向的标题 ylable()指定y轴方

    2024年02月05日
    浏览(31)
  • MATLAB绘图

    在MATLAB中绘制函数图形的步骤如下: 先定义变量 x,通过指定的变量 x 值的范围,该函数被绘制; 然后定义函数, y = f(x); 最后调用 plot 命令,如 plot(x, y)。 接下来我们通过例子绘制简单的函数 y = x , x 值的范围从0到100,增量为5。 在MATLAB中建立一个脚本文件,输入下述代

    2024年02月05日
    浏览(64)
  • MATLAB 的 plot 绘图

    plot的作用: 2-D line plot plot(X,Y) plot(X,Y,LineSpec) plot(X1,Y1,…,Xn,Yn) plot(X1,Y1,LineSpec1,…,Xn,Yn,LineSpecn) plot(Y) plot(Y,LineSpec) plot(tbl,xvar,yvar) plot(tbl,yvar) plot(ax,___) plot(___,Name,Value) p = plot(___) 1. plot(X, Y) plot(X, Y) creates a 2-D line plot of the data in Y versus the corresponding values in X. To plot a set of coordinat

    2024年02月09日
    浏览(42)
  • MATLAB绘图——加强篇

    虽然在MATLAB绘图/数据可视化中介绍了绘图函数并给出了可直接使用的代码,但如果仅掌握这些,还远做不到随心所欲的绘图,因此,本篇博客将在上篇的基础上进一步深入讲解绘图方法。 例如,我们在上一篇介绍了 plot 函数。 plot(list0) 为以列表list0中元素下标为横坐标,元

    2023年04月08日
    浏览(24)
  • Matlab:自定义绘图颜色

    Matlab:自定义绘图颜色 在 Matlab 中绘制图形时,我们可能需要使用自己指定的颜色来填充线条、散点或者其他图案,这可以让我们的图像更加美观和易读。下面介绍两种常见的设置自定义颜色的方法。 使用 RGB 颜色值 RGB 颜色值是一种由红、绿、蓝三种颜色组成的值,在 Mat

    2024年02月12日
    浏览(35)
  • 【MATLAB绘图进阶第3弹】Matlab绘制热图系列

    热图的主要作用是直观展示重点研究对象的差异情况,多用于经济学与工学差异性分析之中,我们常见的多变量 相关系数矩阵与混淆矩阵 就可以通过热图增加图示的美感,南同学将和大家一起实现一张多样化的热图绘制! 配色 重要的事情说三遍:配色、配色、配色!!!好

    2024年02月09日
    浏览(44)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包