How to add a horizontal line in a bar plot????

55 visualizaciones (últimos 30 días)
Thor
Thor el 1 de Feb. de 2013
Editada: Pablo Sánchez el 8 de Dic. de 2020
Dear all,
i use the command bar for a plot. I want to insert a horizontal line in a bar plot at y = 30. How can I do that? Thank you!

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 1 de Feb. de 2013
Editada: Azzi Abdelmalek el 1 de Feb. de 2013
xlim=get(gca,'xlim');
hold on
plot(xlim,[30 30])
  2 comentarios
Image Analyst
Image Analyst el 1 de Feb. de 2013
Isn't the first line unnecessary? xlim is already the x limits - you don't have to call get() to retrieve it, it's already ready to be used "as is". xlim is actually a function itself that returns the x limits.
Thor
Thor el 2 de Feb. de 2013
bar(X);
hold on
plot(xlim,[30 30], 'r')
works too! Thank you all!

Iniciar sesión para comentar.

Más respuestas (1)

Vivian Hauss
Vivian Hauss el 19 de Jul. de 2016
Editada: Vivian Hauss el 19 de Jul. de 2016
A bit shorter:
hline(30,':k','This Line is horizontal')
  1 comentario
Pablo Sánchez
Pablo Sánchez el 8 de Dic. de 2020
Editada: Pablo Sánchez el 8 de Dic. de 2020
Does hline() exist? Is yline()

Iniciar sesión para comentar.

Categorías

Más información sobre Bar Plots 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