Make a pie chart map
0 Comments
Answers (1)
2 Comments
@Trevor King,
Your problem doesn’t sound like , ““Houston, we've had a problem” , so to achieve the desired outcome of displaying pie charts on a map with proportional circle sizes, you need to make several modifications to the existing code. I will integrate pie charts into the map visualization to represent the relative contributions of A, B, and C at each location. Here is the updated Matlab code that includes pie charts on the map:
% PieChartMap_Pie.m
%% Create data.
Name = {'London', 'Edinburgh', 'Amsterdam', 'Paris', 'Rome'};
Lat = [51.508530, 55.953251, 52.379189, 48.864716, 41.890251];
Lon = [-0.076132, -3.188267, 4.899431, 2.349014, 12.492373];
A = [3, 7, 5, 1, 8];
B = [1, 7, 9, 5, 7];
C = [2, 6, 8, 2, 7];
Total = A + B + C;
%% Scale data for circle sizes on the map.
maxCircleSize = 2000;
Total_forMapCircles = maxCircleSize * (Total / max(Total));
%% Create map with circles and pie charts.
figure;
worldmap('World');
load coastlines;
plotm(coastlat, coastlon);
for i = 1:numel(Lat)
[x, y] = mfwdtran(Lat(i), Lon(i));
subplot('Position', [x/1e6, y/1e6, 0.1, 0.1]);
pie([A(i), B(i), C(i)], Name{i});
end
scatterm(Lat, Lon, Total_forMapCircles, [0.5 0.5 0.5], 'filled');
So, in the above modified code, a new figure is created for the map visualization and then iterating over each location and plot a pie chart at the corresponding map coordinates. The subplot function is used to position the pie charts at the correct locations on the map and the pie function is employed to create pie charts representing the relative proportions of A, B, and C at each location. Finally, retaining the scatter plot with circle sizes proportional to the total of the three quantities. Hope, this answers your question.
See Also
Categories
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!