Skip to content

Commit 4465fca

Browse files
committed
Merge pull request #7 from sha17hab/master
Ternary histogram function
2 parents 8a18100 + 5e4958d commit 4465fca

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

Diff for: terndemo.m

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
legend('Data', 'Fit')
1515
hold off
1616

17+
%% Simple two-d density plot
18+
num_axes_steps = 5;
19+
num_color_classes = 5;
20+
ternplot_pro(dataA,dataB,dataC,num_axes_steps,num_color_classes)
21+
ternlabel('A', 'B', 'C')
22+
hold on
23+
ternplot(dataA, dataB, dataC, 'r.');
24+
1725
%% Three D plot for viscosity of HIPS, ABS and PETG polymer blends
1826
experimental = [...
1927
1.000 0.000 0.000

Diff for: ternplot_pro.m

+37-6
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,54 @@
3030
% To Do
3131

3232
% Modifications
33+
% SA The value of 'majors' at the final plot is fixed to 10 to avoid tick
34+
% label interruption
3335

3436
% Modifiers
3537
% (SA) Shahab Afshari
3638

3739
function hfinal = ternplot_pro(dataA,dataB,dataC,num_axes_steps,num_color_classes)
38-
3940
% preliminary effort for getting the indices of values of verticies and faces of
4041
% each triangular cell generated according to desired number of axial steps
4142
h0 = figure;
4243
elev = zeros(num_axes_steps,1);
4344
experimental = [linspace(0,1,num_axes_steps)',linspace(1,0,num_axes_steps)',elev];
44-
h = ternpcolor(experimental(:, 1)', experimental(:, 2)', experimental(:, 3)',num_axes_steps);
45+
%%%%
46+
Z = experimental(:, 3)';
47+
[fA, fB, fC] = fractions(experimental(:, 1)', experimental(:, 2)', experimental(:, 3)');
48+
[x, y] = terncoords(fA, fB, fC);
49+
% Sort data points in x order
50+
[x, i] = sort(x);
51+
y = y(i);
52+
Z = Z(i);
53+
% The matrixes we work with should be square for the triangulation to work
54+
N = num_axes_steps+1;
55+
% Now we have X, Y, Z as vectors.
56+
% use meshgrid to generate a grid
57+
Ar = linspace(min(fA), max(fA), N);
58+
Br = linspace(min(fB), max(fB), N);
59+
[Ag, Bg] = meshgrid(Ar, Br);
60+
[xg, yg] = terncoords(Ag, Bg);
61+
% ...then use griddata to get a plottable array
62+
zg = griddata(x, y, Z, xg, yg, 'v4');
63+
zg(Ag + Bg > 1) = nan;
64+
% Make ternary axes
65+
[hold_state, cax, next] = ternaxes(num_axes_steps);
66+
% plot data
67+
tri = simpletri(N);
68+
h = trisurf(tri, xg, yg, zg);
69+
view([-37.5, 30]);
70+
if ~hold_state
71+
set(gca,'dataaspectratio',[1 1 1]), axis off;
72+
set(cax,'NextPlot',next);
73+
end
74+
view(0, 90);
4575
h.FaceColor = 'none';
4676
v = h.Vertices;
4777
f = h.Faces;
4878
close(h0)
49-
79+
clear fA fB fC x y N Ag Bg Ar Br xg yg hold_state cax next
80+
%%%%
5081
f2 = f;
5182
f2(ismember(f2(:,1),find(isnan(v(:,3)))),:)=[];
5283
f2(ismember(f2(:,2),find(isnan(v(:,3)))),:)=[];
@@ -74,7 +105,7 @@
74105
%
75106
% Plotting Ternary Diagram
76107
hfinal = figure;
77-
ternplot(dataA, dataB, dataC,num_axes_steps,'.','color','none')
108+
ternplot(dataA, dataB, dataC,'majors', 10,'.','color','none') % here the 'majors' is fixed to 10 to avoid text-lable interruption.
78109
set(gca, 'visible', 'off');
79110
hold on
80111
for i = 1: size(f2,1)
@@ -94,9 +125,9 @@
94125
h_colbar = colorbar('XTickLabel',{num2str(round(c_mat_down,2));...
95126
modified_color_bar}, ...
96127
'XTick',linspace(0,1,num_color_classes)','location','eastoutside');
97-
ylabel(h_colbar,['Density of AHG (% of Tot. Counts),','Tot. Counts =', num2str(length(dataA))],'fontsize',10,'rotation',90)
128+
ylabel(h_colbar,['Density (% of Tot. Counts),','Tot. Counts =', num2str(length(dataA))],'fontsize',10,'rotation',90)
98129
set(gca, 'visible', 'off');
99-
ht = ternlabel('b^{*}', 'f^{*}', 'm^{*}');
130+
%ht = ternlabel('b^{*}', 'f^{*}', 'm^{*}');
100131
% h_text = ternlabel('b', 'f', 'm');
101132
% h_text(1).FontSize = 14;
102133
% h_text(2).FontSize = 14;

0 commit comments

Comments
 (0)