Move x-axis labels below the axis after relocation

14 次查看(过去 30 天)
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?

回答(2 个)

Les Beckham
Les Beckham 2023-2-14
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 个评论
Josh Tome
Josh Tome 2023-2-16
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 2023-2-16
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
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';

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by