Reputation: 193
I'm making a whole bunch of separate scatter plots. Each one represents a timestep, so it would be nice to have the color gradient consistent from plot to plot. The default color gradient for a scatter plot depends on the range of values in the plot. Is there a way for me to define the max and min values of the range (so the max and min values in all of my plots combined), and use that as the gradient range for each individual plot?
Right now I just have:
h = scatter(ModelInfo.X(:,1),ModelInfo.X(:,2),50,ModelInfo.y,'filled')
where ModelInfo.y is the "value" assigned to each (X1,X2) pair. I would like to create a gradient from ModelInfo.y=0 to 30.
Upvotes: 1
Views: 2179
Reputation: 74940
You want to use the CAXIS command to set the limits on the color bar.
After every new plot, call
caxis([0 30])
This way, the colormap maps from 0 to 30. Values below 0 are mapped to the first, values above 30 to the last color of the colormap, respectively.
Upvotes: 4
Reputation: 26069
Not near Matlab at the moment but you should be able to set the color scale using caxis
caxis([minVal, maxVal]);
where minVal maxVal are the limits to specified minimum and maximum values. Data values less than minVal or greater than maxVal map to minVal and maxVal , respectively. Values between minValand maxVallinearly map to the current colormap.
Upvotes: 2