Ternary plot (Contour lines)

28 views (last 30 days)
Angshuman Podder
Angshuman Podder on 6 Apr 2023
Answered: Milan Bansal on 13 Sep 2024
Hi, I am trying to draw some contour lines of a ternary phase diagram. I am currently just using closely spaced digitized points on the ternary plot. I am using the package: Ternary Plots. However, I want smooth lines connecting them. So far, I have this:
The code is:
B = readmatrix('dataset.xlsx');
close all
clc
B1 = B*0.01; %liquidus line
fig = figure('units','pixels','position',[100 100 1000 800]);
colormap(jet)
%-- Plot the axis system
[h,htick]=terplot3;
hter1=ternaryc(B1(1:188,1),B1(1:188,2),B1(1:188,3)); %phase boundaries
set(hter1,'marker','o','markerfacecolor','none','markersize',4)
hlabels=terlabel2('MnO','Al_2O_3','SiO_2');
The dataset is here. Thanks for any help.

Answers (1)

Milan Bansal
Milan Bansal on 13 Sep 2024
Hi Angshuman Podder,
I understand that you wish to plot the smooth contour lines instead of marker points in the ternary phase diagram.
To achieve this, you can modify the code in the function "ternaryc" to enable plotting the lines instead of marker points as shown in the following code snippet.
function [hd,hcb]=ternaryc(c1,c2,c3,d,symbol)
if max(c1+c2+c3)>1
c1=c1./(c1+c2+c3);
c2=c2./(c1+c2+c3);
c3=c3./(c1+c2+c3);
end
if nargin == 3
% Constant data, set line drawing instead of marker
marker = 1;
else
marker = 0;
miv=min(d);
mav=max(d);
% If no marker specified use the default one
if nargin==4
symbol='-'; % Default is a line ('-')
end
% Get the current colormap
map=colormap;
end
% Plot the points as continuous lines
hold on
x = 0.5 - c1*cos(pi/3) + c2/2; % X-coordinates for ternary plot
y = 0.866 - c1*sin(pi/3) - c2*cot(pi/6)/2; % Y-coordinates for ternary plot
if marker == 1
%%%% Plot continuous lines instead of points %%%%
hd = plot(x, y, '-b', 'LineWidth', 1.5); % Blue line with width 1.5
else
% Use the color map for colored lines
for i=1:length(c1)-1
in=round((d(i)-miv)*(length(map)-1)/(mav-miv));
if in==0;in=1;end
if in > length(map);in=length(map);end
% Plot a colored segment between consecutive points
hd(i)=plot(x(i:i+1), y(i:i+1), 'color', map(in,:), 'LineWidth', 1.5);
end
end
hold off
axis image
% % Re-format the colorbar if marker is disabled
if marker == 0
hcb=colorbar;
yal=linspace(0,1,10);
set(hcb,'ytick',yal);
ytl=linspace(miv,mav,10);
s=char(10,4);
for i=1:10
if abs(min(log10(abs(ytl)))) <= 3
B=sprintf('%-4.3f',ytl(i));
else
B=sprintf('%-4.2E',ytl(i));
end
s(i,1:length(B))=B;
end
set(hcb,'yticklabel',s,'fontsize',9,'ycolor','k','xcolor','k');
end
You will also need to remove the following line from your code to disable plotting of markers.
set(hter1,'marker','o','markerfacecolor','none','markersize',4)
Here is the output plot after making these changes.
Refer to the documentation to learn more about different options in plot function.
Hope this helps!

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!