現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
How to merge a pie chart with a map
176 ビュー (過去 30 日間)
古いコメントを表示
Hongyun
2024 年 7 月 28 日 8:55
How to merge a pie chart with a map using MATLAB Mapping Toolbox? Just like this one.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1741776/image.jpeg)
19 件のコメント
dpb
2024 年 7 月 28 日 19:17
I see you found <Merging a bar chart with a map>; I would suggest that is a good starting point. The code that draws the bar patches would be replaced by the code to draw the pie. You might be able to get away with using the builtin pie or piechart with the map axes as the axes handle, but it is also possible that won't work because of the map axes...in that case you would be forced to either the patch() solution of the given code with the X,Y coordinates computed to trace out the circle or see if rectangle will be accepted. In one of the most incongrous things still extant in MATLAB HG (handle graphics), there is no native circle function.
If you want/expect somebody here to provide working code, you'll need to at least provide one map and some corresponding data I think...expecting volunteers here to build something from complete scratch is asking quite a lot...
Hongyun
2024 年 7 月 29 日 1:31
Thanks. Although you have provided many suggestions, it is of no help in solving my problem.
Umar
2024 年 7 月 29 日 4:46
Hi @Hongyun,
@dpb and @Walter have many years of experience and they are one of the best technical experts in Matlab. They have given me best tips to resolve problems and helped others when someone gets stuck in the program. You can learn a lot from their tips. However, to answer your question about merging a pie chart with a map in MATLAB using the Mapping Toolbox, I can provide you guidance. First, create a geographic axes by start creating a geographic axes using the geoplot function. This will serve as the base map for your visualization.
figure
ax = geoaxes;
geoplot(ax, 'your_map.shp') % Example map data
Then, add pie chart data by defining the data for the pie chart that you want to overlay on the map. You can use the pie function to create the pie chart.
data = [30 20 15 35]; % Example data for the pie chart
labels = {'A', 'B', 'C', 'D'}; % Example labels for the pie chart
pie(ax, data, labels)
To position the pie chart correctly on the map, you can adjust the Position property of the pie chart. This property specifies the location and size of the pie chart within the axes.
ax.Position = [0.1 0.1 0.6 0.6]; % Adjust the position of the pie chart within the axes
Now time to customize the appearance of the pie chart by changing properties such as colors, labels, and explode slices if needed.
colormap(ax, jet) % Change the colormap of the pie chart
Once you have set up the map and pie chart overlay, you can finalize any additional customization and display the combined visualization.
title(ax, 'Map with Pie Chart Overlay') % Add a title to the visualization
So, if you follow these steps, you can effectively merge a pie chart with a map using MATLAB's Mapping Toolbox, creating a visually informative and engaging representation of geographic data with associated proportions. Please let me know if you have any further questions.
Hongyun
2024 年 7 月 29 日 10:29
Your answer only can add one pie into the map. I need merge multiple pies within the map.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1742401/image.jpeg)
dpb
2024 年 7 月 29 日 13:31
編集済み: dpb
2024 年 7 月 29 日 19:40
"So how to add multiple pies into the map?"
"Wash, rinse, repeat..." as the instructions on the shampoo bottle said.
Put the code to make the pie chart fit onto the map coordinates where desired in a function and then put that in a loop passing the data and coordinates.
Or, put the loop inside the function and then you can call it only once passing the data as arrays.
But, you've yet to follow up with my very first suggestion of putting up data files and code that generates the map and provides the needed data for somebody to play with...expecting volunteers to also create a working example as well of something pretty complicated is passing the buck too much. I don't have the TB so only way I could do anything at all further would be to poke at something here online in the forum...
Hongyun
2024 年 7 月 30 日 11:52
Thanks. Although you have provided many suggestions, it is still of no help in solving my problem.
Umar
2024 年 7 月 30 日 12:44
Hi @Hongyun ,
To add multiple pie charts to a geographic map in MATLAB, repeat the step to create the geographic map as shown in code snippet example below.
figure
ax = geoaxes;
geoplot(ax, 'your_map.shp') % Example map data
Add pie charts by defining the data and labels for each pie chart you want to overlay on the map by using the pie function to create each pie chart.
data1 = [30 20 15 35]; % Example data for the first pie chart
labels1 = {'A', 'B', 'C', 'D'}; % Example labels for the first pie chart
pie(ax, data1, labels1)
data2 = [25 30 20 25]; % Example data for the second pie chart
labels2 = {'X', 'Y', 'Z', 'W'}; % Example labels for the second pie chart
pie(ax, data2, labels2)
% Add more pie charts as needed
Then, adjust each pie chart positions by adjusting the Position property of each pie chart. This property specifies the location and size of the pie chart within the axes.
ax.Position = [0.1 0.1 0.6 0.6]; % Adjust the position of the first pie chart within the axes
% Adjust positions for other pie charts as necessary
Then, customize the appearance of each pie chart by changing properties such as colors, labels, and exploding slices if needed.
dpb
2024 年 7 月 30 日 16:29
編集済み: dpb
2024 年 7 月 31 日 14:37
We knew you could if just gave it a go... :)
Looks good except maybe you could get them to rearrange their province boundaries some so it's not so cluttered in the SE? <VBG>
ADDENDUM/ERRATUM
One tiny nit caught my eye -- there's an "e" missing in "R[e]vised" in the caption...
Umar
2024 年 7 月 30 日 17:26
@ Hongyun,
Glad to know your problem is resolved. I will @dpb suggestion under consideration. He has been given good tips. We tried our best to help you out and you finally able to resolve problem, I am happy 😃 for you. Please let us know if you have any further questions and don’t forget to vote for @dpb.
Hongyun
2024 年 8 月 1 日 2:43
@Umar Although @dpb put forward some sugestions for my questions, they were all just empty talk on paper. He should learn to answer others' questions more through code programming rather than lengthy arguments.
You can challenge another difficult problem I posted here How can I hide the black line on the right side of colorbar. You can find the source code for cbarrow here https://www.mathworks.com/matlabcentral/fileexchange/52515-cbarrow-pointy-ends-for-colorbars.
Umar
2024 年 8 月 1 日 3:08
@ Hongyun,
I took a gland through the documentation of charrow function,and then I came across this as quoted verbatim by author of the code. Hope you are aware of it. I probably have to do some side research on it and then do some code experimentation, if that is okay with you. Hope, you are not in a rush.
“Known issues ,This function only works once per figure. If you have multiple subplots,you can only use it once, and you'll have to call cbarrow last. Also, editing plots after calling cbarrow can sometimes be a bit glitchy.”
Umar
2024 年 8 月 1 日 7:04
@Hongyun,
Please check my solution regarding your query about, “ You can challenge another difficult problem I posted here How can I hide the black line on the right side of colorbar. You can find the source code for cbarrow here https://www.mathworks.com/matlabcentral/fileexchange/52515-cbarrow-pointy-ends-for-colorbars.”
dpb
2024 年 8 月 1 日 12:40
"@Umar Although @dpb put forward some sugestions for my questions, they were all just empty talk on paper. He should learn to answer others' questions more through code programming rather than lengthy arguments."
@Hongyun - if you'll look you'll see I've posted a great deal of code here over the years. If you will recall, my very first reply asked you to simply attach the data so folks had something as a starting point to which end you never responded.
When the solution to a problem is straightforward application of principles outlined, seeing effort towards solving the problem instead of whining also tends to elicit more willingness to invest what time I have...
Umar
2024 年 8 月 3 日 20:54
編集済み: Umar
2024 年 8 月 4 日 2:28
Hi @Hongyun,
I was quiet for sometime but I would like to speak in defense of @dpb, although his sense of humor sometimes offend people but look at all of us, dealing with all technical issues, family problems even myself I lost everything in my life, went through lot of hardships,at this platform I have seen brilliant group of people including @dpb whom I consider as a brother, helped me through lot of issues, provided guidance and he is very exceptional and has helped lot of engineers, research students, teachers etc, you name it, his motivation excelled me at this platform and @Walter Robertson as well, @Walter goes above and beyond solving people problems even helps us by formatting our code. We need to work together as a team to solve our problems and should not be embarrassed to ask for tips or help even having higher ego. Again, @dpb is a gem in stone whose value should not be depreciated and I would like to thank both @Walter Robertson and @dpb for what they do to help out people at this platform among others such as @DGM, @Torsten, @Image Analyst,@Cyclist, it’s like Avengers Team.
dpb
2024 年 8 月 4 日 13:43
編集済み: dpb
2024 年 8 月 4 日 15:08
@Umar, thank you first for your service; secondly for the kind words. I do figure there's no reason for a little jocularity not to tag along with the technical, agreed, and I am a sucker for bad puns and the like...and my preferred technique is to coach/teach rather than provide canned solutions that ime too often are just pasted into the asker's code without any attempt to understand or effort on their part. OTOH, sometimes one just does want to show off MATLAB's facilities when a particularly concise/neat solution is available...vectorization and/or logical indexing and the like that most newcomers find strange and daunting.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Geographic Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)