Borrar filtros
Borrar filtros

Change the x axis labels in plot.

4 visualizaciones (últimos 30 días)
Manuel S Mathew
Manuel S Mathew el 31 de Oct. de 2020
Comentada: Ameer Hamza el 1 de Nov. de 2020
I have a dataset of hourly production throughout a year. So that is 8760 data points. I would like to plot all these 8760 points. But, I just want to label months. So, what I would like to do is to label the x-axis January, February, ... , December instead of what I have now, which is 1,2,3, ..., 8760. Any help is highly appreciated.

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 31 de Oct. de 2020
This code shows an example
x = rand(1, 8760); % your vector
t = datetime(2019,1,1,0,0,0):hours(1):datetime(2019,12,31,23,0,0); % 2019 is used because 2020 is leap year
ax = axes();
hold(ax);
plot(t, x)
ax.XTickLabelMode = 'manual';
ax.XTick = datetime(2019,1,1,0,0,0):calmonths(1):datetime(2019,12,31,23,0,0);
ax.XTickLabel = datestr(ax.XTick,'mmm');
  2 comentarios
Manuel S Mathew
Manuel S Mathew el 1 de Nov. de 2020
Thank you so much. This solved it.
Ameer Hamza
Ameer Hamza el 1 de Nov. de 2020
I am glad to be of help!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by