问题描述
在MATLAB中,我有一个与引用对象R相关联的矩阵map_data(在
我想使用 geoshow()
或类似的东西,允许我随意重新投射和覆盖shapefiles在顶部的光栅。但真正让我在正确的轨道上的任何东西将非常感激。
我使用MATLAB r2014b。以下是色彩映射的相关信息:
R G B
0 0.001< = map_data< 0.005 153 153 153
0.005< = map_data< 0.01 255 255 178
0.01< = map_data< 0.05 254 204 92
0.05< = map_data< 0.1 253 141 60
0.1< = map_data< 0.25 240 59 32
0.25 0.5< = map_data< 1 0 0 0
在MATLAB回答中交叉。
In MATLAB, I have a matrix map_data associated with referencing object R (both in this MAT-file). I want to map it with a discrete colorbar given an irregular range of values to look something like this:
I would like to use geoshow()
or something similar that allows me to reproject at will and to overlay shapefiles on top of the raster. But really anything that gets me on the right track would be much appreciated.
I'm using MATLAB r2014b. Here is the relevant information for the colormap:
R G B
0 <= map_data < 0.001 204 204 204
0.001 <= map_data < 0.005 153 153 153
0.005 <= map_data < 0.01 255 255 178
0.01 <= map_data < 0.05 254 204 92
0.05 <= map_data < 0.1 253 141 60
0.1 <= map_data < 0.25 240 59 32
0.25 <= map_data < 0.5 189 0 38
0.5 <= map_data < 1 0 0 0
Cross-posted at MATLAB answers.
Will had a great idea to use histc()
, but I had to edit his code to make it work for me. Here's what I ended up with.
my_colormap = [204 204 204
153 153 153
255 255 178
254 204 92
253 141 60
240 59 32
189 0 38
0 0 0]/255 ;
binEdges = [0 0.001 0.005 0.01 0.05 0.1 0.25 0.5 1] ;
labels = textscan(num2str(binEdges*100),'%s') ;
labels = labels{1} ;
labels{length(labels)} = [labels{length(labels)} '%'] ;
[~,indices] = histc(map_data,binEdges);
indices(isnan(map_data)) = NaN ;
indices(isinf(map_data)) = NaN ;
figure ;
pcolor(indices-1) % Instead of image(), to display NaN values as white
shading flat
axis equal tight
colormap(gca,my_colormap); % gca as first argument prevents
% colormap from changing for all
% subsequent plots
h = colorbar;
caxis([0 length(binEdges)-1])
h.YTickLabel = labels ;
这篇关于MATLAB:使用自定义色彩映射绘制栅格图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!