Merging a bar chart with a map

버전 1.0.0 (8.56 MB) 작성자: O.Hubert
Seamlessly merge a bar chart with a map to display geographically-coded categorical variables
다운로드 수: 9
업데이트 날짜: 2024/5/16

라이선스 보기

Let us break down the example code that calls the bar_chart function:
  1. Data Loading:
  • The code begins by loading data from a file named dataexample.
  1. Data Description:
  • The following variables are described:
  • Idx: Index of data. This could be countries, provinces, etc.
  • BoundingBox: Maximum and minimum latitude and longitude values.
  • Lon and Lat: Vertices defining the boundaries of the map object. These can be obtained from loading a .SHP object and extracting the vertices.
  • centerLon and centerLat: By default, the center of BoundingBox, but this can be any coordinates that the user requires.
  • The column titles VarX_categY are the Yth category of variable X.
  1. Selecting Data to Plot:
  • The code defines sets of indices (idxtoplot{n}) to select the specific columns of the data table for plotting.
  • These indices correspond to the columns containing data to be plotted on the bar chart.
  1. Creating Useful Things:
  • The colormap for the bars is set using Colors=colormap('Lines'), but any type of color map can be used.
  1. Merging Geographical Map and Bar Chart:
  • The barchart_map function is called with the loaded data (dataexample), selected indices (idxtoplot), and options (optionsfig).
  • The resulting figure handle (h) and other relevant elements (hmap and hdata) are stored.
  1. Aesthetics and Annotations:
  • After the graph is generated, the user can tweak and add various objects by making explicit references to the graph objects.
Now let us dive into the plotting function barchart_map.
The function called barchart_map generates a graph combining geographical limits with a bar chart.
  1. Inputs:
  • data: A table containing the data.
  • idxtoplot: A cell array specifying the columns of data to be plotted.
  • options: A structure collecting various plot options.
  1. Options:
  • The function checks if options is provided. If not, default values are set:
  • options.factorLon: Shrinkage factor for the width of the bars.
  • options.factorLat: Shrinkage factor for the height of the bars.
  • options.offsetLon: Spacing between bars.
  • options.newfigure: Determines whether a new figure needs to be generated.
  • options.Colors: Colormap for the bars.
  1. Data Processing:
  • The function processes the data and organizes it into YData for plotting.
  1. Plotting:
  • It plots the geographical map using plot(data.Lon{i,1}, data.Lat{i,1}).
  • For each data point, it creates stacked bars based on the specified columns and their values.
  1. Outputs:
  • out: Figure handle.
  • outmap: Elements corresponding to the map.
  • outdata: Elements corresponding to the data bars.

인용 양식

O.Hubert (2024). Merging a bar chart with a map (https://www.mathworks.com/matlabcentral/fileexchange/166031-merging-a-bar-chart-with-a-map), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2021b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0