Is there a way to relate colorbar values to geodensityplot weight?

19 vues (au cours des 30 derniers jours)
Joseph Kovach
Joseph Kovach le 5 Mar 2021
Commenté : Marin Akter le 4 Nov 2023
I am trying to relate the values of my geodensityplot to the colorbar.
The values in the colorbar range from 0 to 2.5 x 10^-8.
The weight values in my geodensityplot range from 1 - 11.
How can I make the colorbar values correspond to my weight values?
I know that I could replace the colorbar values with Tick Labels but I'm uncertain of the relationship between colorbar colors/values and my geodensityplot weight data.
Sample code.
%% GeoDensityPlot of GPS grid weighted by number of Cell Towers within Range
figure(1)
geodensityplot(inRangeGridAll(:,1),inRangeGridAll(:,2),inRangeGridAll(:,3),'FaceColor','interp');
geobasemap('darkwater')
colorbar
%Annotations
title("Cell Tower Signal Density Map")

Réponse acceptée

Mathieu NOE
Mathieu NOE le 5 Mar 2021
hello
if you have the weights values , you can use them in the colorbar TickLabels
some example below :
figure(1)
n = 32;
map = colormap(jet(n)) ; %Create Colormap
cbh = colorbar ; %Create Colorbar
cbh.Ticks = linspace(0, 1, n) ; %Create n ticks from zero to 1
cbh.TickLabels = num2cell(round(logspace(log10(10),log10(1000),n))) ; %Replace the labels of these n ticks with the given numbers
  3 commentaires
Mathieu NOE
Mathieu NOE le 8 Mar 2021
hello Joseph
sorry, maybe a added a layer of confusion here - my example was from another submission answer ...
I tried here to fix the colorbar problem using the matlab demo code for geodensityplot
so I hope you can use it for your own usage :
lon = linspace(-170,170,3000) + 10*rand(1,3000);
lat = 50 * cosd(3*lon) + 10*rand(size(lon));
weights = 101 + 100*(sind(2*lon));
geodensityplot(lat,lon,weights,'FaceColor','interp')
geobasemap('darkwater')
% colorbar (modified)
cbh = colorbar ; %Create Colorbar
existingTicks = get(cbh,'Ticks');
N = numel(existingTicks);
tmp = round(linspace(min(weights),max(weights),N));
cbh.TickLabels = num2cell(tmp) ; %Replace with the "weights" numbers
Marin Akter
Marin Akter le 4 Nov 2023
Thank you so much dear

Connectez-vous pour commenter.

Plus de réponses (1)

Douglas
Douglas le 18 Août 2023
This took some trial and error, but I was trying to solve the same problem. I also wanted to use and pre-scale a lot of plots so just relabeling the ticks was not desirable.
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.
If you can pre-calculate your weights or know the radius of influence:
% radius of influence (see geodensityplot docs) in meters
R = 10e2;
gx = geodensityplot(inRangeGridAll(:,1),inRangeGridAll(:,2),inRangeGridAll(:,3)*R^2, 'FaceColor','interp', 'radius', R)
cbh = colorbar;
It will be properly weighted by inRangeGridAll(:,3). In your case, 1-11.
If you do NOT know the radius of influence, you can still properly interpret your data using the in function calculated radius of influence.
% for the maximum value
cbh.Limits(2)*gx.Radius^2
or
% for all of the tick marks
cbh.Ticks*gx.Radius^2

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by