필터 지우기
필터 지우기

Custom grid on a plot

조회 수: 25 (최근 30일)
BN
BN 2020년 4월 19일
편집: Adam Danz 2020년 4월 21일
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
Ameer Hamza
Ameer Hamza 2020년 4월 19일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2020년 4월 20일
편집: Adam Danz 2020년 4월 21일
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개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by