how to flip the direction of the axis?
조회 수: 313 (최근 30일)
이전 댓글 표시
Dear all,
I want to change the x-axis direction from right to left but also keeping the values to be not affected (reversed/flipped). when I used the fooling command the mentioned problem is caused:
set(gca, 'XDir','reverse')
How can I solve that?
thanks
댓글 수: 0
채택된 답변
madhan ravi
2018년 10월 28일
xticklabels([1:10]) %an example
set ( gca, 'xdir', 'reverse' )
댓글 수: 2
DGM
2024년 2월 11일
편집: DGM
2024년 2월 11일
"incorrect"
While that's a valid point, please use comments and try to explain what you mean to readers instead of just sniping with unhelpful single-word comments.
set() and get() are case-insensitive:
xticklabels([1:10]) %an example
set ( gca, 'XDir', 'reverse' ) % set still works
% see also:
get(gca,'XDir') % the actual case of the property name
get(gca,'xdir') % lower case
get(gca,'xdIR') % goofy case
% case does matter if you directly use dot indexing on the axes object
hax = gca;
hax.XDir % there is an XDir property
hax.xdir % but there is no xdir property
As to what the nuances of OP's actual problem were, I can't know.
추가 답변 (1개)
Oli Fairfax
2025년 1월 16일
편집: Oli Fairfax
2025년 1월 16일
You're probably better off reversing the data and the axes rather than playing with the tick lables, in my opinion:
% Example data
x = [1:0.1:10];
y = sin(x);
% Normal plot
figure;
plot(x,y)
% Reversed axes plot
figure
plot(flip(x),y)
set(gca, 'XDir','reverse')
댓글 수: 1
DGM
2025년 1월 17일
Yes, sometimes it's necessary to do some combination of flipping the data and/or the axes. This is often an issue when trying to plot data overlaid atop images.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
