Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustment of source codes,'ternplot_pro' function, and 'terndemo' according to the latest modification #5

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions ternaxes.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@
% 20160405 (SA) Added lines to change the order/direction of axes (i.e.
% clockwise or counter-clockwise) cooresponding to user-specified
% option on terncoords
% 20161305 (SA) the offsets of tick labels (text) along x and y axes are
% modified

% Modifiers
% (CS) Carl Sandrock
% (SA) Shahab Afshari

function [hold_state, cax, next] = ternaxes(majors)
%majors = 10;
if nargin < 1
majors = 10;
end

direction = 'clockwise';
percentage = false;

%TODO: Get a better way of offsetting the labels
xoffset = 0.25;
Expand All @@ -40,10 +47,10 @@
fUnits = get(cax, 'DefaultTextUnits');

set(cax, 'DefaultTextFontAngle', get(cax, 'FontAngle'), ...
'DefaultTextFontName', get(cax, 'FontName'), ...
'DefaultTextFontSize', get(cax, 'FontSize'), ...
'DefaultTextFontWeight', get(cax, 'FontWeight'), ...
'DefaultTextUnits','data')
'DefaultTextFontName', get(cax, 'FontName'), ...
'DefaultTextFontSize', get(cax, 'FontSize'), ...
'DefaultTextFontWeight', get(cax, 'FontWeight'), ...
'DefaultTextUnits','data')

% only do grids if hold is off
if ~hold_state
Expand All @@ -59,24 +66,32 @@
'edgecolor',tc,'facecolor',get(gca,'color'),...
'handlevisibility','off');
end

% Generate labels
majorticks = linspace(0, 1, majors + 1);
majorticks = majorticks(1:end-1);
%%% Counter-clockwise
%labels = num2str(majorticks'); %*100
%%% Clockwise
labels = num2str(sort(majorticks','descend')); %*100

if percentage
multiplier = 100;
else
multiplier = 1;
end

if ~strcmp(direction, 'clockwise')
labels = num2str(majorticks'*multiplier);
else
labels = num2str(majorticks(end:-1:1)'*multiplier);
end

zerocomp = zeros(size(majorticks)); % represents zero composition

% Plot right labels (no c - only b a)
[lxc, lyc] = terncoords(1-majorticks, majorticks, zerocomp);
text(lxc+0.05, lyc-0.025, [repmat(' ', length(labels), 1) labels]);
text(lxc+0.065, lyc-0.025, [repmat(' ', length(labels), 1) labels]); % the offsets are modified

% Plot bottom labels (no b - only a c)
[lxb, lyb] = terncoords(majorticks, zerocomp, 1-majorticks); % fB = 1-fA
text(lxb-0.115, lyb-0.065, labels, 'VerticalAlignment', 'Top');
text(lxb-0.1, lyb-0.07, labels, 'VerticalAlignment', 'Top'); % the offsets are modified

% Plot left labels (no a, only c b)
[lxa, lya] = terncoords(zerocomp, 1-majorticks, majorticks);
Expand Down
8 changes: 8 additions & 0 deletions terndemo.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
legend('Data', 'Fit')
hold off

%% Simple two-d density plot
num_axes_steps = 5;
num_color_classes = 5;
ternplot_pro(dataA,dataB,dataC,num_axes_steps,num_color_classes)
ternlabel('A', 'B', 'C')
hold on
ternplot(dataA, dataB, dataC, 'r.');

%% Three D plot for viscosity of HIPS, ABS and PETG polymer blends
experimental = [...
1.000 0.000 0.000
Expand Down
6 changes: 3 additions & 3 deletions ternpcolor.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

% To do: Better error checking

function ternpcolor(varargin)
ternsurf(varargin{:});
view(0, 90);
function h_ternpcolor = ternpcolor(varargin) % plot handle is added as function output
h_ternpcolor = ternsurf(varargin{:});
view(0, 90);
17 changes: 9 additions & 8 deletions ternplot_pro.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
% / \
% c --- a

% HFINAL = TERNPLOT_PRO(dataA,dataB,dataC,NUM_AXES_STEPS,NUM_COLOR_CLASSES)
% HFINAL = TERNPLOT_PRO(dataA, dataB, dataC, NUM_AXES_STEPS, NUM_COLOR_CLASSES)
% plots ternary phase diagram for three components,i.e. dataA,dataB,
% and dataC, each being as Nx1 vector, where is overall counts of data.
% and dataC, each being as Nx1 vector, where N is overall counts of data.
% NUM_AXES_STEPS, is a user specified number of steps (major ticks) on a-c, c-b, and b-a axes.
% NUM_COLOR_CLASSES, is a user specified number of classes of assigned
% facecolor of triangulare cells corresponding to computed point density within a particular cell.
Expand All @@ -30,18 +30,19 @@
% To Do

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

% Modifiers
% (SA) Shahab Afshari

function hfinal = ternplot_pro(dataA,dataB,dataC,num_axes_steps,num_color_classes)

% preliminary effort for getting the indices of values of verticies and faces of
% each triangular cell generated according to desired number of axial steps
h0 = figure;
elev = zeros(num_axes_steps,1);
experimental = [linspace(0,1,num_axes_steps)',linspace(1,0,num_axes_steps)',elev];
h = ternpcolor(experimental(:, 1)', experimental(:, 2)', experimental(:, 3)',num_axes_steps);
h = ternpcolor(experimental(:, 1)', experimental(:, 2)', experimental(:, 3)','majors',num_axes_steps);
h.FaceColor = 'none';
v = h.Vertices;
f = h.Faces;
Expand All @@ -57,7 +58,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

total_data_count = length(dataA);
% counting poits located within polygon extent
% counting points located within polygon extent
for i = 1: size(f2,1)

inpoly_data_count = inpolygon(x, y,v(f2(i,:),1),v(f2(i,:),2));
Expand All @@ -74,7 +75,7 @@
%
% Plotting Ternary Diagram
hfinal = figure;
ternplot(dataA, dataB, dataC,num_axes_steps,'.','color','none')
ternplot(dataA, dataB, dataC,'majors', 10,'.','color','none') % here the 'majors' is fixed to 10 to avoid text-lable interruption.
set(gca, 'visible', 'off');
hold on
for i = 1: size(f2,1)
Expand All @@ -94,9 +95,9 @@
h_colbar = colorbar('XTickLabel',{num2str(round(c_mat_down,2));...
modified_color_bar}, ...
'XTick',linspace(0,1,num_color_classes)','location','eastoutside');
ylabel(h_colbar,['Density of AHG (% of Tot. Counts),','Tot. Counts =', num2str(length(dataA))],'fontsize',10,'rotation',90)
ylabel(h_colbar,['Density (% of Tot. Counts),','Tot. Counts =', num2str(length(dataA))],'fontsize',10,'rotation',90)
set(gca, 'visible', 'off');
ht = ternlabel('b^{*}', 'f^{*}', 'm^{*}');
%ht = ternlabel('b^{*}', 'f^{*}', 'm^{*}');
% h_text = ternlabel('b', 'f', 'm');
% h_text(1).FontSize = 14;
% h_text(2).FontSize = 14;
Expand Down
18 changes: 11 additions & 7 deletions ternsurf.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
% TERNSURF plot surface diagram for ternary phase diagram
% TERNSURF(A, B, MAJORS, Z) plots surface fitted over Z on ternary phase diagram for three components. C is calculated
% TERNSURF(A, B, Z) plots surface fitted over Z on ternary phase diagram for three components. C is calculated
% as 1 - A - B. Number of steps in axes will be enter by user as MAJORS
%
% TERNSURF(A, B, C, MAJORS, Z) plots surface of Z on ternary phase data for three components A B and C. If the values
% TERNSURF(A, B, C, Z) plots surface of Z on ternary phase data for three components A B and C. If the values
% are not fractions, the values are normalised by dividing by the total. Number of steps in axes will be enter by user as MAJORS
%
% NOTES
Expand All @@ -27,20 +27,24 @@
% Modifications
% 20031006 (CS) Added call to SIMPLETRI to plot triangular surface
% 20070107 (CS) Modified to use new structure (more subroutines)
% 20160405 (SA) Added an input argument 'major', and an output argument 'handel'
% 20160405 (SA) Added an input argument 'major', and an output argument 'handle'
% 20161305 (SA) Removed 'Z' input argument, changed upper limit of nargin
% from 4 to 6

% Modifiers
% CS Carl Sandrock
% SA Shahab Afshari

function handel = ternsurf(A, B, C,majors,Z)
function handle = ternsurf(A, B, C, varargin) % Z arguement is removed


if nargin < 5
if nargin < 6 % it was orginally 4
Z = C;
C = 1 - (A+B);
end;

[varargin, majors] = extractpositional(varargin , 'majors', 10);


[fA, fB, fC] = fractions(A, B, C);
[x, y] = terncoords(fA, fB, fC);

Expand Down Expand Up @@ -70,7 +74,7 @@
tri = simpletri(N);

%tri = delaunay(xg, yg, zg);
handel = trisurf(tri, xg, yg, zg);
handle = trisurf(tri, xg, yg, zg);
%h = trimesh(tri, xg, yg, zg);
view([-37.5, 30]);

Expand Down