Plotting with true colors in an uneven grid

4 vues (au cours des 30 derniers jours)
Ellen
Ellen le 7 Déc 2012
I would like to plot data 1) on an uneven grid, with 2) a pre-defined RGB color for each grid cell, not an indexed colormap. pcolor allows 1) and image allows 2). But is there a function that lets me do both?
Here is an example:
%Data
x = 1:3; %Both pcolor and image
y = [1 2 4 8]; %Both
z = [1:12 repmat(NaN,1,8)]; %z data for pcolor
z = reshape(z,5,4);
[xmesh,ymesh] = meshgrid([x 4],[y 10]); %Mesh for pcolor
c = reshape(lines(12),4,3,3); %Colors for image
%Pcolor
figure;
pcolor(xmesh,ymesh,z);
title('pcolor: correct grid');
%Image
figure;
image(x,y,c);
set(gca,'YDir','Normal');
title('image: correct colors');
I realize that I could index my data relative to a colormap containing only the colors I want, but is there a more direct solution?

Réponse acceptée

Sean de Wolski
Sean de Wolski le 7 Déc 2012
pcolor is just creating a surface so you could do this explicitly yourself and then view it in two dimensions:
surf(xmesh,ymesh,z,c);view(2) %c is color!
You will have to figure out how you want to handle NaN data though.
  1 commentaire
Ellen
Ellen le 7 Déc 2012
Thanks, that solved the problem!

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 7 Déc 2012

Catégories

En savoir plus sur Color and Styling dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by