Dear All, I could improve the bar.fig figure. I edited its xticks in Property Editor. Now it shows every date but unfortunately, the x-axis is slipped a bit. Could someone suggest me a solution?
How can I create a bar plot from sorted values with correct sorted label values?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dear All, I would like to create a bar plot with sorted precipitation data (pr) along its sorted date (date). I tried the following:
labels=num2str(date);
bar(pr);
set(gca,'XTickLabel',labels);
I got the attached figure. I do not understand why the figure shows the date incorrectly? I am mean I would like to have every bar one label value. Could someone suggest me a solution? Thank you for your help in advance!
Respuestas (1)
Rik
el 24 de Feb. de 2017
Editada: Rik
el 1 de Mzo. de 2017
As far as I understand this plot and the axis and bar objects it contains, you have only put in 4 years, but you have many more bars in pr. What you should try is the following:
sorted_date=sort(date);
labels=num2str(sorted_date);%date must be a col-vector (nx1)
bar(date,pr);
set(gca,'XTick',sorted_date);
set(gca,'XTickLabel',labels);
2 comentarios
Rik
el 1 de Mzo. de 2017
Your dates are apparently not sorted, which I did not expect. I'll edit my answer.
Ver también
Categorías
Más información sobre Annotations 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!