Borrar filtros
Borrar filtros

Plotting and reversing axis direction

587 visualizaciones (últimos 30 días)
Maeve  Ryan
Maeve Ryan el 26 de Nov. de 2011
Comentada: MISBAH MEHAK el 3 de Feb. de 2024
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.

Respuesta aceptada

Daniel Shub
Daniel Shub el 26 de Nov. de 2011
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 comentarios
Maeve  Ryan
Maeve Ryan el 26 de Nov. de 2011
Thanks Daniel :)
MISBAH MEHAK
MISBAH MEHAK el 3 de Feb. de 2024
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.

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 26 de Nov. de 2011
Consider using plotyy(), recording the axes generated, and applying the set() to the appropriate one.
  3 comentarios
Walter Roberson
Walter Roberson el 26 de Nov. de 2011
ax = plotyy(...)
set(ax(2),'YDir','reverse')
Y Budi Sulistioadi
Y Budi Sulistioadi el 10 de Jun. de 2013
this answer rocks! Thanks

Iniciar sesión para comentar.

Categorías

Más información sobre Two y-axis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by