0

I have a dataset with 3 vectors X, Y, and Z and I want to plot a 2D image from this dataset. I don't know how to define X, Y and Z and the color represent by different Z. Do you have any idea how to do this task?

Thanks in advance

  • Have you tried constructing a [bitmap](http://msdn.microsoft.com/en-us/library/system.drawing.bitmap(v=vs.110).aspx)? – Felix Castor Feb 10 '14 at 17:45
  • are x and y coordinates on a regular grid? Otherwise use [**`scatter`**](http://www.mathworks.es/es/help/matlab/ref/scatter.html). Some inspiration you can finde [**here**](http://stackoverflow.com/questions/21658031/plot-x-y-z-triplets-over-coordinates-x-y-with-color-z/21658182#21658182)! (just consider the part, where `scatter` is used) – Robert Seifert Feb 10 '14 at 17:50
  • 1
    x and y are on regular grid, I'd like to do exactly the same plot that heatmap to color image matlab – user3177755 Feb 10 '14 at 18:44
  • OK, then your answer will be to use `ind2rgb` as described in the linked question, but you will likely need to rescale your `Z` so they can be use as indexes into the colormap. Specifically, see [this answer](http://stackoverflow.com/a/21464968/2778484). – chappjc Feb 10 '14 at 20:10

1 Answers1

1

This will be a bit slow if there are thousands of points but should work:

>> x=1:10;
>> y=x.^2;
>> z=y/10;
>> cmap = jet(64); % Define a color map
>> idx = ceil(z/max(z)*64); % Indices into the map
>> figure
>> hold on
>> for i=1:length(x);plot(x(i),y(i),'o','Color',cmap(idx(i),:));end

I do like the suggestions in Plot (x,y,z) triplets over coordinates (x,y) with color z though

Community
  • 1
  • 1