필터 지우기
필터 지우기

Plotting and reversing axis direction

조회 수: 577 (최근 30일)
Maeve  Ryan
Maeve Ryan 2011년 11월 26일
댓글: MISBAH MEHAK 2024년 2월 3일
Hello, I want to plot a graph with one x axis and two y axes. I want one of the y axes to be reversed i.e. beginning at the top so the data hangs off the top of the graph. Additionally I want the reversed y axis plot to be a bar graph and the other to be an ordinary line plot.
I tried this function
plot (a,b)
bar(a,c)
Set (gca,'Ydir','reverse')
but this reversed both y axes.

채택된 답변

Daniel Shub
Daniel Shub 2011년 11월 26일
a = (1:10)';
b = rand(10, 1);
c = rand(10, 1);
figure
h1 = axes
bar(a, c)
set(h1, 'Ydir', 'reverse')
set(h1, 'YAxisLocation', 'Right')
h2 = axes
plot(a,b)
set(h2, 'XLim', get(h1, 'XLim'))
set(h2, 'Color', 'None')
set(h2, 'Xtick', [])
  댓글 수: 2
Maeve  Ryan
Maeve Ryan 2011년 11월 26일
Thanks Daniel :)
MISBAH MEHAK
MISBAH MEHAK 2024년 2월 3일
It is not working in case of subplot. The latter plot considers full figure instead of subplot. Can you please tell me how to make it work in a subplot.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 11월 26일
Consider using plotyy(), recording the axes generated, and applying the set() to the appropriate one.
  댓글 수: 3
Walter Roberson
Walter Roberson 2011년 11월 26일
ax = plotyy(...)
set(ax(2),'YDir','reverse')
Y Budi Sulistioadi
Y Budi Sulistioadi 2013년 6월 10일
this answer rocks! Thanks

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by