【MATLAB基础绘图第15棒】绘制三元相图

三元相图(Ternary Plot)

三元相图(Ternary Plot)是一种用于表示三个变量之间关系的图表。它通常被用于化学、地质、生态学、环境科学等领域,用于表示三种组分或属性在一个系统中的相对量或比例。
三元相图以一个三角形为基础,其中每个顶点代表系统中的一种组分或属性,因此三元相图也被称为三角图或三角坐标图。

方法1:函数alchemyst/ternplot

下载一:MATLAB中文帮助-alchemyst/ternplot
在这里插入图片描述
下载二:GitHub-alchemyst/ternplot

1.1 案例1:

方法2:STernary在这里插入图片描述

MATLAB代码如下:

%% 基础设置:

figure(2);
% 初始化三元相图(Init ternary plot)
STA2=STernary();

% 设置刻度值/网格值/刻度标签
% 'GridValues'/'TickValues'
% 'MinorGridValues'/'MinorTickValues'
% 'A_TickLabelStr'/'B_TickLabelStr'/'C_TickLabelStr'
STA2.set('MinorGridValues',5:5:100)
STA2.set('MinorTickValues',2.5:2.5:100)
STA2.set('A_TickLabelStr',{'20%','40%','60%','80%','100%'})

% 设置轴刻度标签字体和颜色
set(STA1,'A_TickLabel','Color',[0,0,0],'FontSize',14,'fontname','Times New Roman')
set(STA1,'B_TickLabel','Color',[0,0,0],'FontSize',14,'fontname','Times New Roman')
set(STA1,'C_TickLabel','Color',[0,0,0],'FontSize',14,'fontname','Times New Roman')

2.1 案例1:散点图

成图如下:
在这里插入图片描述
MATLAB代码如下:

clc
close all
clear
%% 基础设置
pathFigure= '.\Figures\' ;

%% 开始绘图-散点图

A=rand(1,20);
B=rand(1,20);
C=rand(1,20);

figure(1);
% 初始化三元相图(Init ternary plot)
STA1=STernary();

% 绘制散点图(Draw scatter plot)
STA1.SScatter(A,B,C,40,'filled','CData',[0,0,0]);

% 背景色变为灰色(Set the background color to gray)
set(STA1,'Color',[.9,.9,.9]);
hl = legend("Scatter Plot");
set(hl,'Box','off','location','NorthEast','FontSize',12,'FontName','Times New Roman');    

% 设置A轴刻度标签字体和颜色
set(STA1,'A_TickLabel','Color',[0,0,0],'FontSize',14,'fontname','Times New Roman')
set(STA1,'B_TickLabel','Color',[0,0,0],'FontSize',14,'fontname','Times New Roman')
set(STA1,'C_TickLabel','Color',[0,0,0],'FontSize',14,'fontname','Times New Roman')

% 设置标签文本(Set Label string)
set(STA1,'A_Label','String','LabelA','fontname','Times New Roman');
set(STA1,'B_Label','String','LabelB','fontname','Times New Roman');
set(STA1,'C_Label','String','LabelC','fontname','Times New Roman');
% 将标签移动到侧边(Move the label to the side)
STA1.label2Side();

str= strcat(pathFigure, "Figure1", '.tiff');
print(gcf, '-dtiff', '-r600', str);

2.2 案例2:折线图

成图如下:
在这里插入图片描述

MATLAB代码如下:

%% 绘图-折线图

figure(3);
% 初始化三元相图(Init ternary plot)
STA3=STernary();

% 初始化三元相图(Init ternary plot)
STA3=STernary();

% 绘制折线图及散点(Draw lines and scatter)
STA3.SPlot([2,2],[3,0],[5,8],'LineWidth',4,'Color',[.8,0,0]);
STA3.SPlot([2,7],[3,3],[5,0],'LineWidth',4,'Color',[0,.8,0]);
STA3.SPlot([2,0],[3,5],[5,5],'LineWidth',4,'Color',[0,0,.8]);
STA3.SScatter(2,3,5,180,'filled','CData',[1,1,1],'MarkerEdgeColor',[0,0,0],'LineWidth',2);

% 绘制文本(Draw text)
STA3.SText(2+1,3,5,'(20%,30%,50%)','FontSize',16,'FontName','Times New Roman')

% 设置轴刻度标签字体和颜色
set(STA1,'A_TickLabel','Color',[0,0,0],'FontSize',14,'fontname','Times New Roman')
set(STA1,'B_TickLabel','Color',[0,0,0],'FontSize',14,'fontname','Times New Roman')
set(STA1,'C_TickLabel','Color',[0,0,0],'FontSize',14,'fontname','Times New Roman')

参考

MATLAB | 如何用MATLAB如何绘制各式各样精致的三元相图(ternary plot)

另:其它语言绘制三元相图

公众号文章-我汇总了所有三元相图(ternary plots)的绘制方法,超实用!!

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

WW、forever

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值