Clear Filters
Clear Filters

semilog x in boundedline doesn't work

1 view (last 30 days)
T
T on 1 Oct 2023
Commented: Voss on 1 Oct 2023
I tried multiple solutions offered, but once I make the x-axis logarithmic, the shading disappears.
for e.g. in this example
%% Example 1: Plotting lines using various syntax options
%
% This example builds the 4-panel example image used on the MatlabCentral
% File Exchange, which shows several different methods for supplying line
% coordinates, bounds coordinates, and shading options.
%
% The first axis plots two lines using the LineSpec option for input, which
% allows yoy to set line color, line color, and marker type for each line.
% The bounds on the first line vary over x, while the bounds on the second
% line are constant for all x. An outline is added to the bounds so the
% overlapping region can be seen more clearly.
x = linspace(0, 2*pi, 50);
y1 = sin(x);
y2 = cos(x);
e1 = rand(size(y1))*.5+.5;
e2 = [.25 .5];
ax(1) = subplot(2,2,1);
[l,p] = boundedline(x, y1, e1, '-b*', x, y2, e2, '--ro');
outlinebounds(l,p);
title('Opaque bounds, with outline');
axis tight;
The code works fine but if I add the line -
set(gca,'xscale','log')
in the end to make semilog x plot, the shading disappears. Any help is appreciated. Thanks!

Accepted Answer

Voss
Voss on 1 Oct 2023
Edited: Voss on 1 Oct 2023
The problem is the 0 in your x vector. Non-positive numbers cannot be represented on log scale. (Specifically, log(0) is negative infinity, which causes a problem drawing a patch with an infinite x-coordinate.) Change the zero to something small but positive.
x = linspace(1e-2, 2*pi, 50);
y1 = sin(x);
y2 = cos(x);
e1 = rand(size(y1))*.5+.5;
e2 = [.25 .5];
ax(1) = subplot(2,2,1);
[l,p] = boundedline(x, y1, e1, '-b*', x, y2, e2, '--ro');
outlinebounds(l,p);
title('Opaque bounds, with outline');
axis tight;
set(gca,'xscale','log')
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!