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

Update: comments #830

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 37 additions & 5 deletions utils/display/plot_figure.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
function [ax, dline] = plot_figure(x_field, x_var, y_field, y_var, varargin)
% Plot figure
% Plot figure with customizable settings
%
% Args:
% x_field (string): Field name for the x-axis data
% x_var (cell): Cell array containing the x-axis data
% y_field (string): Field name for the y-axis data
% y_var (cell): Cell array containing the y-axis data
%
% Optional Name-Value Pair Args:
% * config (struct): Struct with the configuration for plots
% * leg or legend (cell): Cell array of strings containing the legend names
% * legend_location (string): Location of the legend
% * ax or axes (object): Handle of the axes to plot on
% * linestyle (string): Line style
% * linewidth (float): Line width
% * fontsize (float): Font size
% * title (string): Title of the figure
% * labelx, xlabel, label_x, or x_label (string): x-axis label
% * labely, ylabel, label_y, or 'y_label (string): y-axis label
% * label_type (string): Label type
% * xscale (string): Set x-axis scale (linear or log)
% * yscale (string): Set y-axis scale (linear or log)
% * xdir (string): Set x-axis direction (normal or reverse)
% * ydir (string): Set y-axis direction (normal or reverse)
% * color (float): Line color [R, G, B]
%
% Returns:
% Tuple containing
%
% * ax (object): Handle of the axes
% * dline (object): Handle of the plotted line

% Default settings
FLAG_COLOR_NEW = false;
Misc = Miscellaneous();
config = Misc.config;
config.labelx = interpreter_label(x_field, config.label_type); % Set x label
config.labely = interpreter_label(y_field, config.label_type); % Set y label
ax = []; % Set empty axes
config.labelx = interpreter_label(x_field, config.label_type);
config.labely = interpreter_label(y_field, config.label_type);
ax = [];

% Get x and y values
x = cell2vector(x_var, x_field);
y = cell2vector(y_var, y_field);

% Check aditional inputs
for i = 1:2:nargin - 5

Expand All @@ -23,7 +55,7 @@
config.legend_name = varargin{i + 1};
case {'legend_location'}
config.legend_location = varargin{i + 1};
case {'ax', 'axes', 'figure'}
case {'ax', 'axes'}
ax = varargin{i + 1};
case 'linestyle'
config.linestyle = varargin{i + 1};
Expand Down
17 changes: 12 additions & 5 deletions utils/display/plot_molar_fractions.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
% x_field (char): Fieldname to plot on the x-axis
% y_field (char): Fieldname to plot on the y-axis
%
% Optional Args:
% Optional Name-Value Pair Args:
% * validation (struct): Struct that contains validations with (x_field, y_field)
% * nfrec (float): Frequency points to plot validations
% * mintol (float): Minimum limit i-axis with the composition of the mixture
Expand All @@ -18,24 +18,26 @@
% * yscale (char): Set y-axis scale (linear or log)
% * xdir (char): Set x-axis direction (normal or reverse)
% * ydir (char): Set y-axis direction (normal or reverse)
% * ax (object): Handle of the axes to plot on
%
% Returns:
% Tuple containing
%
% * ax (axes): Axes object
% * fig (figure): Figure object
% * ax (object): Handle of the axes
% * fig (object): Handle of the figure

% Default values
ax = [];
results2 = [];
nfrec = 1;
config = self.Misc.config;
config.labelx = interpreter_label(x_field, config.label_type); % Set x label
config.labely = interpreter_label(y_field, config.label_type); % Set y label
config.labelx = interpreter_label(x_field, config.label_type);
config.labely = interpreter_label(y_field, config.label_type);
mintol_display = self.C.mintol_display;
config.yscale = 'log';
[species, LS] = get_display_species(self);
y_var = x_var;

% Unpack
for i = 1:2:nargin - 5

Expand Down Expand Up @@ -75,10 +77,13 @@
mix1.(x_field) = cell2vector(x_var, x_field);
mix1.(y_field) = cell2vector(y_var, y_field);
end

% Get index species
index_species_CT = find_ind(LS, species);

% Remove species that do not appear
[species, index_species_CT] = clean_display_species(mix1.Xi, LS, index_species_CT);

% Set figure
if isempty(ax)
[ax, ~, fig] = set_figure(config);
Expand Down Expand Up @@ -109,6 +114,7 @@
SYMBOL_STYLES = {'d', 'o', 's', '<'};
NUM_STYLES = length(LINE_STYLES);
colorbw = brewermap(NUM_COLORS, config.colorpalette);

% Plot main results
k = 1;
z = 1;
Expand Down Expand Up @@ -201,6 +207,7 @@
end

legend(h, legendname, 'FontSize', config.fontsize - 6, 'Location', 'northeastoutside', 'interpreter', 'latex');

% Set title
title(create_title(self), 'Interpreter', 'latex', 'FontSize', config.fontsize + 4);
end
Expand Down