Custom grid on a plot
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
BN
el 19 de Abr. de 2020
Hey all,
I have a plot that represents an error of 7 models in the months. I wanted to split each month's results by a line or grid to determine it more clear. so I used this code:
set( gca, 'YGrid', 'on' );
But as you can see the bars not adjusted between the grids; for example, if you look at Jan results, some of them appear before Jan line and some of them appear after this line. How I can have a line that split each month's results?
Thank you so much.
1 comentario
Ameer Hamza
el 19 de Abr. de 2020
Can you show the commands used to plot this graph? It would be better if you can also attach the variables used to make this bar plot.
Respuesta aceptada
Adam Danz
el 20 de Abr. de 2020
Editada: Adam Danz
el 21 de Abr. de 2020
If the x-axis is a datetime axis, compute the 15th of each month and use plot(), line(), or xline() to plot vertical lines on the 15th from min(ylim()) to max(ylim()).
If the x-axis is numeric and each month is represented by x = 1,2,...,12, then your x values will be +0.5.
If you get stuck, show us what you've got and I'd be glad to help straighten it out.
Demo
fig = figure();
ax = axes(fig);
xlim([0,13])
ylim([0,10])
hold on
plot((.5:1:12.5).*[1;1], [min(ylim(ax)),max(ylim(ax))], '-k', 'Color', [.5 .5 .5])
ax.XTick = 1:12;
Or use xline()
fig = figure();
ax = axes(fig);
xlim([0,13])
ylim([0,10])
ax.XTick = 1:12;
hold on
arrayfun(@(x)xline(x,'-','Color',[.5 .5 .5]), .5:1:12.5)
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Line 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!