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 Center および File ExchangeAxis Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by