Non-existent data point added to plot when using YScale set to log

1 view (last 30 days)
I am having trouble with my box charts.
I want to use a logarithmic scale on the y-axis, but when I set the YScale to 'log' the figure gains a non-existent data point in the lower right corner.
Below I have added pictures of the same plot using first:
set(gca,'YScale','linear');
And then:
set(gca,'YScale','log');
Notice the small x in the bottom, right corner of the second plot where the log scale is used.
Any help to get rid of this seemingly misprinted data point is much appreciated. The complete code used for plotting is appended below.
%% Run time
close all;
clear;
clc;
%% Data
run_times = [1.4634 1.5331 1.4921 1.3144 1.0671;
1.3962 1.3904 1.4602 1.2182 1.1692;
1.4932 1.4054 1.2830 1.2400 1.1326;
1.5038 1.3657 1.1776 1.0256 1.1283;
1.7159 1.4243 1.2277 1.0248 1.1027;
1.4595 1.3683 1.3592 1.0343 1.1770;
1.3933 1.3528 1.4153 1.0389 1.1779;
1.4677 1.3328 1.1518 1.0293 1.0091;
1.5231 1.4361 1.1591 1.1834 0.9311;
1.5266 1.3547 1.1698 1.3268 0.9344;
1.4179 1.3956 1.3281 1.3119 1.0316;
1.7265 1.3067 1.2173 1.2612 1.0231;
1.7641 1.3872 1.2086 1.0228 0.9045;
1.6448 1.3595 1.1600 1.0287 0.9136;
1.4732 1.3832 1.1769 1.0213 0.8964;
1.5144 1.3128 1.4429 1.0217 0.9178;
1.6277 1.3571 1.2957 1.0618 0.9330;
1.5958 1.6076 1.1443 1.0634 0.9082;
1.5744 1.6343 1.1444 1.0780 0.9363;
1.7770 1.6009 1.4395 1.2499 0.9666];
run_time_size = size(run_times);
%Group data with even spaces without regard for actual space between groups
x_axis_groups = repmat(1:run_time_size(2),run_time_size(1),1);
label_x_axis = repmat([50 60 70 80 90],run_time_size(1),1);
%% Plot
%For formatting
font_size = 14;
y_padding = 0.1;
%Create figure
figure;
hold('on');
%Create box chart
box_chart_time = boxchart(x_axis_groups(:),run_times(:));
%Box chart properties
box_chart_time.BoxFaceColor = 'b';
box_chart_time.BoxFaceAlpha = 0;
box_chart_time.MarkerStyle = 'x';
box_chart_time.MarkerColor = 'k';
grid('on');
box('on');
set(gca,'FontSize',font_size);
set(gca,'ycolor','k');
%Labels
xlabel('Outlier Fraction [\%]','Interpreter','latex');
ylabel('Runtime [s]','Interpreter','latex');
%X-axis
set(gca,'XTick',x_axis_groups(1,:));
set(gca,'XTickLabel',label_x_axis(1,:));
set(gca,'XLimitMethod','padded');
%Y-axis
% set(gca,'YScale','linear'); %Linear y-axis
set(gca,'YScale','log'); %Logarithmic y-axis
rounded_min_log_value_time = floor(log10(min(run_times(:))));
rounded_max_log_value_time = ceil(log10(max(run_times(:))));
y_lim_min_time = 10^(rounded_min_log_value_time - y_padding);
y_lim_max_time = 10^(rounded_max_log_value_time + y_padding);
ylim([y_lim_min_time y_lim_max_time]);

Accepted Answer

Sourav Karmakar
Sourav Karmakar on 17 Feb 2022
Edited: Sourav Karmakar on 17 Feb 2022
Hey Torbjorn ,
This is a bug known to the development team and they will try to fix it in future releases. One workaround would be to use boxplot function.
Hope this helps!
  1 Comment
Torbjørn Smith
Torbjørn Smith on 17 Feb 2022
Edited: Torbjørn Smith on 17 Feb 2022
Hello Sourav.
Thank you for the response.
I fixed it by adding 10 to the x_axis_groups, making them 11, 12, 13, 14, 15,... and not 1, 2, 3, 4, 5,... like they were before. I guess (do not know) this pushed the non-existant data points out of the figure.
The new code look like this:
[...]
%Group data with even spaces without regard for actual space between groups
x_axis_groups = repmat(1:run_time_size(2),run_time_size(1),1) + 10;
label_x_axis = repmat([50 60 70 80 90],run_time_size(1),1);
[...]

Sign in to comment.

More Answers (0)

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!