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!