Move x-axis labels below the axis after relocation

14 views (last 30 days)
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?

Answers (2)

Les Beckham
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
Josh Tome
Josh Tome on 16 Feb 2023
Sure, here is the part of the code I think is relevant to the issue...
AnkleData = table2array(readtable('NormativeData.xlsx','Sheet','Gait_Ankle_Sagittal','Range','A2:B102','ReadVariableNames',false));
AnkleAvg = (AnkleData(:,1))';
AnkleStDev = (AnkleData(:,2))';
%Plot the normative figure average with +/- 1 St.Dev
x=(0:1:100);
y1 = AnkleAvg+AnkleStDev;
y2 = AnkleAvg-AnkleStDev;
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 (+)');
Les Beckham
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 (+)');

Sign in to comment.


Sulaymon Eshkabilov
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';

Community Treasure Hunt

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

Start Hunting!