Move x-axis labels below the axis after relocation
14 views (last 30 days)
Show older comments
When I move my x-axis position using the command
ax.XAxisLocation = 'origin';
the labels of the x-axis move above the axis and tick marks, but I'd like them to remain below. I know there is probably a simple solution to this, but could someone enlighten me?
0 Comments
Answers (2)
Les Beckham
on 14 Feb 2023
I think we are going to need to see more of your code to figure out what is happening.
It seems to work for me (I tried it in my desktop 2022b as well).
x = 0:0.01:4*pi; % create some fake data to plot
y1 = sin(x);
y2 = y1 + 0.2*x;
figure
ax = axes;
patch([x fliplr(x)], [y1 fliplr(y2)], [0.8 0.8 0.8], 'EdgeColor', 'none', 'FaceAlpha', 0.5)
grid on
ax.XAxisLocation = 'origin';
2 Comments
Les Beckham
on 16 Feb 2023
Seems to work with my code approach
x = 0:0.01:4*pi; % create some fake data to plot since you didn't provide the data
y1 = sin(x);
y2 = y1 + 0.2*x;
figure
ax = axes;
patch([x fliplr(x)], [y1 fliplr(y2)], [0.8 0.8 0.8], 'EdgeColor', 'none', 'FaceAlpha', 0.5)
grid on
ax.XAxisLocation = 'origin';
or with yours
figure
patch([x fliplr(x)], [y1 fliplr(y2)], [0.8 0.8 0.8], 'EdgeColor', 'none','facealpha',0.5)
ax = gca;
set(gca, 'XAxisLocation', 'bottom')
ax.XAxisLocation = 'origin';
title('Ankle Flexion');
ylabel('Plantar (-) / Dorsi (+)');
Sulaymon Eshkabilov
on 14 Feb 2023
Here is how it can be done, e.g.:
x = linspace(-pi, 3*pi);
y = sin(2*x);
plot(x, y), grid on
ax=gca;
set(gca, 'XAxisLocation', 'bottom')
ax.XAxisLocation='origin';
0 Comments
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!