フィルターのクリア

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 Center および File Exchange2-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