Custom grid on a plot

32 Ansichten (letzte 30 Tage)
BN
BN am 19 Apr. 2020
Bearbeitet: Adam Danz am 21 Apr. 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 Kommentar
Ameer Hamza
Ameer Hamza am 19 Apr. 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Adam Danz
Adam Danz am 20 Apr. 2020
Bearbeitet: Adam Danz am 21 Apr. 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)

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by