Move x-axis labels below the axis after relocation

조회 수: 14 (최근 30일)
Josh Tome
Josh Tome 2023년 2월 14일
댓글: Les Beckham 2023년 2월 16일
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
Sulaymon Eshkabilov 2023년 2월 14일
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에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by