How color fill grid squares in plot?

I want to make a with color filled boxes instead of data points. Where instead of plotting specific points against time, the grid box/space is filled with that color for certain Y values. I know how to create the plot with gridlines but I'm not sure how to color-fill the grid squares (see other picture with red scribble for what I mean). Where the red scribble is, I want it completely filled with red. Any tips?

댓글 수: 2

Adam Danz
Adam Danz 2023년 6월 20일
See doc pages for pcolor and imagesc. Is this what you're looking for?
Robert Daly
Robert Daly 2023년 8월 11일
A tip: Depending on your grid resolution, the first time you run pcolor it can come out all black with grid lines.
To see the colours you should use the following command after you run pcolor
shading flat
or
shading interp

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

답변 (1개)

Star Strider
Star Strider 2023년 6월 20일

0 개 추천

The patch function would be appropriate here.
Perhaps something like this —
x = 0:5:20;
y = 0:7;
figure
patch([5 10 10 5], [5 5 6 6], 'r', 'EdgeColor','none')
grid
xticks(x)
yticks(y)
xlim([min(x) max(x)])
ylim([min(y) max(y)])
This could of course be generalised (using a for loop) to fill other squares. (I did not draw the diagnoal blue line because I do not know if it is significant. It would be straightforward to add it.)
.

카테고리

도움말 센터File Exchange에서 Images에 대해 자세히 알아보기

제품

태그

질문:

2023년 6월 20일

댓글:

2023년 8월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by