How to generate a geographical heat map? (worldwide, country-level granularity)
    14 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Franck Dernoncourt
      
 el 14 de Jun. de 2013
  
    
    
    
    
    Comentada: MikCh
 el 23 de Abr. de 2022
            I want to create a geographical heat map like the following in MATLAB:

Each color is based on a list of country with a percentage associated to each of them:
Country with Codes: % of Hits
 - United States (US): 36.29% 
 - India (IN): 18.24% 
 - United Kingdom (GB): 12.93% 
 - Spain(ES): 8.22% 
 - Australia (AU): 3.32% 
 - Canada (CA): 3.05%
 - Germany (DE): 2.49% 
 - Netherlands (NL): 1.66% 
 - Israel (IL): 1.39% 
 - China (CN): 0.83%
How can I do it in MATLAB?
I looked at http://mathworks.com/products/mapping and Googled around but I didn't find any easy way to do it. Such kind of maps are commonly used (e.g. straightforward to do with the Google Chart API) so I'm hoping someone here shares his/her experience.
Thanks,
Franck
[1]: http://i.stack.imgur.com/64DJY.png
2 comentarios
  Brahim HAMADICHAREF
 el 3 de En. de 2014
				I am curious ... have you ever managed to do the same with the Mapping toolbox ? I also use Google maps API, but an only MATLAB solution would prefer !
Brahim
Respuesta aceptada
  Antti
    
 el 30 de Jun. de 2016
        This can be quite easily done with the Mapping toolbox. Here's an example:
% read a shapefile with some regions in it
S = shaperead('usastatelo.shp');
numRegions = length(S);
% show the map
mapshow(S)
% get the current colormap
cmap = colormap;
numColors = size(cmap,1);
% create some random data [1 numRegions], each data point is associated with a region
data = randi(numColors,1,numRegions);
% set the colors of the regions using the 'FaceColor' -property
for i = 1:length(S)
    % FaceColor is now a color from the current colormap, determined by
    % it's data value
    mapshow(S(i),'FaceColor',cmap(data(i),:))
end
This gives me the map figure in the attachment.
2 comentarios
  Rui Li (AIRicky)
 el 18 de Feb. de 2019
				Thank you. I have a question on the answer. If my data is not integer, and  range from 0.1 to 50.9, how can I specify the color for each region and add corresponding colorbar? 
  MikCh
 el 23 de Abr. de 2022
				Nice approach! 
What if the data variable include both positive and negative values?
How do we need to modify mapshow(S(i),'FaceColor',cmap(data(i),:)) in the loop so as to accept negative values?
Más respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!