How do I plot the data as patches rather than vertices in a grid or a mesh?
조회 수: 10 (최근 30일)
이전 댓글 표시
I have been trying to visualize a set of stochastic data like the matrix below:
1 1 1 2 2 3 3;
1 1 1 2 2 3 3;
1 1 1 1 2 2 3;
1 1 1 1 2 2 3;
1 1 1 1 2 2 3;
I want to create something similar to a chess board, with 1 being blue, 2 being yellow and 3 being red (see the attached figure).
I have tried contourf and surf, but they all put data on the vertices of the lattices, so if the shading function is faceted, it will give
And if the shading is interp, it will be
The boundaries between ones, twos and threes is an artificial transition at the blank area where no data exist.
I then tried adding an additional row and column, or, as Youssef KHMOU suggested, using the kron function. Both ways gave the right lattice pattern, but then I had to manually adjust the position of the ticks to produce the first graph, which is what I need.
Is there a better way to do this?
댓글 수: 0
답변 (3개)
Star Strider
2014년 5월 8일
A = 1 1 1 1 1 1 1;
1 1 1 1 1 1 1;
1 2 2 1 1 1 2;
2 2 2 2 3 3 2;
2 2 3 3 3 3 3];
figure(1)
pcolor(A)
axis equal
colormap(gray)
댓글 수: 2
Star Strider
2014년 5월 9일
This may be what you want:
A = [1 1 1 1 1 1 1;
1 1 1 1 1 1 1;
1 2 2 1 1 1 2;
2 2 2 2 3 3 2;
2 2 3 3 3 3 3];
x = [0:6]+0.5;
y = [0:4]+0.5;
figure(1)
image(x, y, A)
axis equal tight
colormap(gray(3))
grid on
h = get(gca)
set(gca, 'YTick', 0:5, 'GridLineStyle','-')
produces:
Youssef Khmou
2014년 5월 8일
Tensor product can be efficient in representing each number with different color, but try this way i think it is convenient to your description :
M=ones(4,1)*(1:4)
surface(M)
댓글 수: 3
Youssef Khmou
2014년 5월 8일
it was only a way to create a matrix similar to that you posted, so surface is not working?
Kun
2014년 5월 8일
편집: Kun
2014년 5월 8일
댓글 수: 2
Youssef Khmou
2014년 5월 8일
try :
M=ones(4,1)*(1:4);
B=kron(M,ones(3));
figure; surface(B);
% shading interp
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!