How to interpret colorbar values in geodensityplot?
Show older comments
I am using Geographic Density Plot to analyze cyclone track data.
I am successful in implementing and using the code. I essentially used the sample code in the documentation for geodensityplot.
geodensityplot([latall{:}],[lonall{:}],'FaceColor','interp');
This is the result with the colorbar.

I understand that a higher number indicates a higher density but I do not know what the values on the colorbar exactly represent. The colorbar limits range from 0 to ~2.8x10^-9. Is this the number of points per unit area or some other measurement?
1 Comment
Sebastián Inzunza
on 28 Jun 2022
Hi Luke!
Finally, do you have an idea about interpret the colorbar values? I have the same problem.
Answers (1)
This took some trial and error, but I was trying to solve the same problem. There is no documentation for this which is highly annoying! The values are weighted by R^2 (not pi*R^2). No pi. It says radius, but leg or width would be more discriptive. In your case, it should be the number of occurences in area.
If you can pre-calculate your weights or know the radius of influence:
% radius of influence (see geodensityplot docs) in meters
R = 10e3;
gx = geodensityplot(lat, lon, gWeights*R^2, 'FaceColor','interp', 'radius', R)
cbh = colorbar;
It will be properly weighted by gWeights.
If you do NOT know the weights, you can still calculate the number of events in an area.
% for the maximum value
cbh.Limits(2)*gx.Radius^2
or
% for all of the tick marks
cbh.Ticks*gx.Radius^2
7 Comments
世园 李
on 15 Sep 2023
How should the units for the colorbar be labeled? Should it be labeled as density, relative density probability, or something else?
世园 李
on 15 Sep 2023
And why is the color patch in the colorbar that represents the minimum value so transparent and light in color, causing a mismatch between the colorbar and the image? How should this be adjusted? Thanks!
Douglas
on 15 Sep 2023
For your case, the weights are being calculated by number of events at each coordinate. Since the R^2 factor unweights the geographical aspect, the label would be "events". Without the R^2, it would be events/unit^2. This is not a probability distribution, unless you have created one using your input data.
You could try to rescale the colorbar. As for light, I'm not sure what you mean. If it is too transparent, you should adjust the alpha value in the output of the geodensityplot
世园 李
on 16 Sep 2023
In the example given in the official MATLAB documentation: openExample('graphics/CreateGeographicDensityPlotFromTabularDataExample')
load cycloneTracks
head(cycloneTracks)
figure
latAll = cycloneTracks.Latitude; lonAll = cycloneTracks.
lonAll = cycloneTracks.Longitude; windspeedAll = cycloneTracks.
windspeedAll = cycloneTracks.
geodensityplot(latAll,lonAll,windspeedAll,'FaceColor','interp')
“windspeedAll” is the weight that the geodensityplot calculates, and the variable takes values in the range of about 0-100.
If I change it to:
R = 10e4;
windspeedAll = cycloneTracks.WindSpeed;
geodensityplot(latAll,lonAll,windspeedAll*R^2,'FaceColor','interp','radius', R);
The range of colorbar is 0-1600;
And if I reset the weights myself: take every 10th interval between 0-100, set the weight to 1 for the interval 0-10, and set the weight to 11 for windspeeds over 100, so that the weights are set to 11 levels, with each level represented by the Arabic numerals 1-11. After substituting the new weights into the geodensityplot function, the range of the colorbar becomes 0-160. Since the "events" of hurricanes passing through the delineated area during these years is a certain number of times, the number of events shown on the colorbar changes just because of the change in weights, which confuses me.
I don't know if I can set the weights myself in practice, or if I should not change the variable "wind speed" like in the documentation, please give me some guidance, thank you very much!
Dealing with transparent colormapped objects overlaid atop a variable background creates a fundamental ambiguity. Anywhere that the object is not 100% opaque is mixed with some other color, so it necessarily won't correspond to the colorbar anymore. Just what color it is depends on the opacity and what's behind it. In this case, the opacity mapping seems to be linear, and there's only really two background colors.
You could jump through a bunch of hoops to fake a complicated 2D colorbar that represents the colors from the original colormap as they would appear after compositing with the various background colors:
% some fake data (from the webdocs for geodensityplot())
lon = linspace(-170,170,3000) + 10*rand(1,3000);
lat = 50 * cosd(3*lon) + 10*rand(size(lon));
weights = 101 + 100*(sind(2*lon));
% by default, facealpha is scaled according to the parent geoaxes 'Alphamap' property.
axes(gcf,'position',[0.1260 0.1100 0.7100 0.8150]); % make room for fake colorbar
hgd = geodensityplot(lat,lon,weights,'FaceColor','interp');
% get some basic things established
mapCT = [208 207 212; 239 239 239]/255; % the map colors [ocean; land] (streets-light default)
baseCT = jet(256); % the nominal desired colormap
colormap = baseCT; % the main geoaxes uses the colormap as-is
%colorbar % this will always be wrong unless facealpha is 1
% the default alphamap is a linear ramp, but let's just fetch it instead of assuming
drawnow % force draw before trying to access axes properties
alpha = hgd.Parent.Alphamap; % assume it might not always be linear
axin = linspace(0,1,numel(alpha));
axout = linspace(0,1,size(baseCT,1));
alpha = interp1(axin,alpha,axout); % interpolate so that it's the same length as baseCT
alpha = alpha(:); % reshape to a column vector
% combine everything in sRGB
modifiedCT = alpha.*baseCT + (1-alpha).*permute(mapCT,[3 2 1]); % one map per page
modifiedCT = permute(modifiedCT,[1 3 2]); % now it's a 2px-wide color stripe
% use an image to create a fake colorbar
% representing the base colormap at variable opacity over two different BG colors
hax2 = axes(gcf,'position',[0.8832 0.1102 0.050 0.8143]); % second axes for fake colorbar
hi = image(1:size(modifiedCT,2),hgd.Parent.CLim,modifiedCT);
hax2.YDir = 'normal';
hax2.TickLength = [0 0];
hax2.XTickLabel = {'Sea','Lnd'};
hax2.XTickLabelRotation = -90;
... but I don't know that it's that much less confusing. Also, this immediately gets worse if the background isn't as simple.
You'll have to adjust the axes positions and labels as needed. I had to resort to some silly things to get it to draw correctly on the forum.
Shiyuan
on 16 Sep 2023
Thank you very much for your answer! I will try to modify the question about color transparency.
Also, regarding the physical meaning of the colorbar, as mentioned before, it should represent "events", but after modifying the weights, the value field of the colorbar will change. In the example mentioned in the last comment, should the number of times a hurricane passes through the high frequency region be 1600 or 160? Though the image remains the same, the value domain of colorbar changes after the setting of weights is changed, I don't know what the real number of times is actually. Thanks!
Shiyuan
on 16 Sep 2023
Interestingly, I've tried colormap(jet(7)), colormap(jet(9)), etc. before, and found that the color scale [0.0,0.5,1.0], which represents the low-value area, doesn't seem to distort the colors as much when using colormap(jet(5)). Sorry, these are the only very simple methods I can think of at the moment.
h = geodensityplot(allLat, allLon,weights*R*R, 'FaceColor', 'interp','Radius',R);
alphamap(normalize((1:64).^0.1,'range'));
geobasemap none
colormap(jet(5));
Categories
Find more on Color and Styling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!