{"id":4014,"date":"2024-12-17T19:14:09","date_gmt":"2024-12-17T10:14:09","guid":{"rendered":"https:\/\/secondlife.lol\/?p=4014"},"modified":"2024-12-17T21:23:22","modified_gmt":"2024-12-17T12:23:22","slug":"donut-chart-python-visualization","status":"publish","type":"post","link":"https:\/\/secondlife.lol\/en\/donut-chart-python-visualization\/","title":{"rendered":"How to draw and nest doughnut charts with Python Visualization"},"content":{"rendered":"<style>.kb-image4014_43d89b-e2 .kb-image-has-overlay:after{opacity:0.3;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;}.kb-image4014_43d89b-e2 img.kb-img, .kb-image4014_43d89b-e2 .kb-img img{border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;box-shadow:0px 0px 14px 0px rgba(0, 0, 0, 0.2);}<\/style>\n<div class=\"wp-block-kadence-image kb-image4014_43d89b-e2\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"467\" height=\"469\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc-2.jpg\" alt=\"\ud30c\uc774\uc36c \uc2dc\uac01\ud654 \uc911\ucca9 \ub3c4\ub11b \ucc28\ud2b8\" class=\"kb-img wp-image-4019\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc-2.jpg 467w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc-2-300x301.jpg 300w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc-2-150x150.jpg 150w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc-2-12x12.jpg 12w\" sizes=\"(max-width: 467px) 100vw, 467px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"http:\/\/python.org\" target=\"_blank\" rel=\"noopener\">Python<\/a> Visualizations allow you to present complex data in beautiful, easy-to-understand charts. In particular, donut charts are a great tool for visualizing ratios. But don't settle for just representing ratios! Nested doughnut charts allow you to create trendy and in-depth visualizations.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we'll use the <strong>The Python visualization library <code>matplotlib<\/code>How to draw a doughnut chart step by step using<\/strong>in this tutorial. We'll cover everything from basic donut charts to more advanced techniques for drawing nested donut charts, so follow along!<\/p>\n\n\n<style>.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap{padding-top:var(--global-kb-spacing-sm, 1.5rem);padding-right:var(--global-kb-spacing-sm, 1.5rem);padding-bottom:var(--global-kb-spacing-sm, 1.5rem);padding-left:var(--global-kb-spacing-sm, 1.5rem);border-top:3px solid var(--global-palette2, #2B6CB0);border-right:3px solid var(--global-palette2, #2B6CB0);border-bottom:3px solid var(--global-palette2, #2B6CB0);border-left:3px solid var(--global-palette2, #2B6CB0);border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;box-shadow:0px 0px 14px 0px rgba(0, 0, 0, 0.2);}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title-wrap{padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title-wrap{color:var(--global-palette2, #2B6CB0);}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title{color:var(--global-palette2, #2B6CB0);font-size:28px;font-weight:regular;font-style:normal;}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap .kb-table-of-content-list{color:var(--global-palette1, #3182CE);line-height:2em;font-weight:regular;font-style:normal;margin-top:var(--global-kb-spacing-sm, 1.5rem);margin-right:0px;margin-bottom:0px;margin-left:0px;}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap .kb-table-of-content-list .kb-table-of-contents__entry:hover{color:var(--global-palette6, #718096);}@media all and (max-width: 1024px){.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap{border-top:3px solid var(--global-palette2, #2B6CB0);border-right:3px solid var(--global-palette2, #2B6CB0);border-bottom:3px solid var(--global-palette2, #2B6CB0);border-left:3px solid var(--global-palette2, #2B6CB0);}}@media all and (max-width: 1024px){.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title{font-size:28px;}}@media all and (max-width: 767px){.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-content-wrap{border-top:3px solid var(--global-palette2, #2B6CB0);border-right:3px solid var(--global-palette2, #2B6CB0);border-bottom:3px solid var(--global-palette2, #2B6CB0);border-left:3px solid var(--global-palette2, #2B6CB0);}.kb-table-of-content-nav.kb-table-of-content-id83_5f28a6-34 .kb-table-of-contents-title{font-size:28px;}}<\/style>\n\n\n<h2 class=\"wp-block-heading\">What is a donut chart?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A doughnut chart is a <strong>A variation of the pie chart with a hollow center<\/strong>This empty space adds to the cleanliness of the chart and is a great place to include additional information.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Key Features<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Data rate<\/strong>in an intuitive way.<\/li>\n\n\n\n<li>Overlaying multiple pieces of data enables multidimensional visualizations.<\/li>\n\n\n\n<li>The clean, modern design is perfect for trendy data visualizations.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Drawing basic charts with Python visualizations<\/h2>\n\n\n<style>.kb-image4014_6cea83-2a .kb-image-has-overlay:after{opacity:0.3;border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;}.kb-image4014_6cea83-2a img.kb-img, .kb-image4014_6cea83-2a .kb-img img{border-top-left-radius:5px;border-top-right-radius:5px;border-bottom-right-radius:5px;border-bottom-left-radius:5px;box-shadow:0px 0px 14px 0px rgba(0, 0, 0, 0.2);}<\/style>\n<div class=\"wp-block-kadence-image kb-image4014_6cea83-2a\"><figure class=\"aligncenter size-full\"><img decoding=\"async\" width=\"436\" height=\"411\" src=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc-1.jpg\" alt=\"\ud30c\uc774\uc36c \uc2dc\uac01\ud654 \ub3c4\ub11b \ucc28\ud2b8\" class=\"kb-img wp-image-4017\" srcset=\"https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc-1.jpg 436w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc-1-300x283.jpg 300w, https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ub2e4\uc6b4\ub85c\ub4dc-1-13x12.jpg 13w\" sizes=\"(max-width: 436px) 100vw, 436px\" \/><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">First, let's take a look at how to draw a basic chart like the one above, where we'll use the <code>matplotlib<\/code>to utilize the<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Python Code Example - Basic Donut Chart<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>Importing the # library\nimport matplotlib.pyplot as plt\n\nSet up the # data\nlabels = ['Country A', 'Country B', 'Country C', 'Country D']\nsizes = [30, 20, 35, 15]\ncolors = ['#ff9999', '#66b3ff', '#99ff99', '#ffcc99']\n\nCreate a # donut chart\nfig, ax = plt.subplots()\nax.pie(sizes, labels=labels, colors=colors, wedgeprops=dict(width=0.3), autopct='%1.1f%%')\n\nAdd a # center circle (make it donut-shaped)\ncentre_circle = plt.Circle((0, 0), 0.70, fc='white')\nfig.gca().add_artist(centre_circle)\n\nSet the # chart title\nplt.title('Basic Donut Chart')\nplt.show()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Drawing a nested chart<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A nested chart shows the <strong>Two tiers<\/strong>simultaneously, with each layer providing a richer view of the data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Python code example - Nested doughnut chart<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import matplotlib.pyplot as plt\n\nSet up the # outer donut data\nouter_labels = ['Germany', 'France', 'China', 'UK', 'Italy']\nouter_sizes = [30, 23, 16, 18, 13]\n\n# inner donut data settings\ninner_labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']\ninner_sizes = [15, 15, 12, 11, 8, 8, 8, 9, 9, 9, 7, 6]\n\n# color settings\nouter_colors = plt.cm.Blues([0.6, 0.7, 0.8, 0.9, 1.0])\ninner_colors = plt.cm.RdYlBu_r([0.6, 0.6, 0.7, 0.7, 0.8, 0.8, 0.8, 0.9, 0.9, 1.0, 1.0])\n\nCreate a # nested doughnut chart\nfig, ax = plt.subplots()\n\n# outer donut layer\nax.pie(outer_sizes, labels=outer_labels, radius=1.3, colors=outer_colors,\n       wedgeprops=dict(width=0.3), labeldistance=1.1, autopct='%1.1f%%', pctdistance=0.85)\n\n# inner donut layer\nax.pie(inner_sizes, labels=inner_labels, radius=1.0, colors=inner_colors,\n       wedgeprops=dict(width=0.3), labeldistance=0.7, autopct='%1.1f%%', pctdistance=0.6)\n\nHollow out the center of # (completing the donut shape)\ncentre_circle = plt.Circle((0, 0), 0.6, fc='white')\nfig.gca().add_artist(centre_circle)\n\nSet up the # title (adjust spacing with the pad option)\nplt.title('Improved Nested Donut Chart with Adjusted Labels', pad=30)\n\nSet the # layout\nplt.tight_layout()\nplt.show()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Common mistakes<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>When you have too much data<\/strong>: Too many items clutter the chart. Include only key data.<\/li>\n\n\n\n<li><strong>Color confusion<\/strong>: Using similar colors can make it difficult to distinguish between items. Use a color palette.<\/li>\n\n\n\n<li><strong>Ratio and label mismatches<\/strong>: <code>autopct<\/code>to ensure that the correct percentage is displayed.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Frequently asked questions (FAQ)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q1. When should I use this chart?<br>This chart shows the ratio<\/strong> Great for situations where you need comparisons but want a clean, modern design.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q2. What is the purpose of a nested doughnut chart?<\/strong><br>It is effective when comparing and analyzing two layers of data simultaneously.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Q3. How is it different from a pie chart?<\/strong><br>Donut charts are hollow in the center to display additional information or are more aesthetically pleasing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Finalize<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Donut charts are a popular technique in Python visualization that breaks up the monotony of pie charts. Once you've followed along from basic charts to nested charts, it's time to try your hand at creating some cool doughnut charts with real data! You'll be one step closer to falling in love with data visualization.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a side note, there are a lot of people in Python visualization who do time series analysis. <a href=\"https:\/\/secondlife.lol\/en\/stock-data-time-series-analysis-trend-forecasting\/\" data-type=\"post\" data-id=\"2545\">Python Data Analysis Example: Analyze S&amp;P 500 Stock Data Time Series and Predict Future Prices<\/a> Check out this post to learn how!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"># Explanation of the code<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Draw a basic chart<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>Importing the # library\nimport matplotlib.pyplot as plt  <\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Importing libraries<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>matplotlib.pyplot<\/code>: The <code>matplotlib<\/code>which is a submodule of<\/li>\n\n\n\n<li>This module uses the <strong>Graphs, charts<\/strong> and more.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Set up # data\nlabels = ['Country A', 'Country B', 'Country C', 'Country D']\nsizes = [30, 20, 35, 15]\ncolors = ['#ff9999', '#66b3ff', '#99ff99', '#ffcc99']  <\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Data settings<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>labels<\/code>: The name of each fragment (section). For example: 'Country A', 'Country B', etc.<\/li>\n\n\n\n<li><code>sizes<\/code>: Sets the proportion of each piece. Examples: 30%, 20%, 35%, 15%.<\/li>\n\n\n\n<li><code>colors<\/code>: The color code to use for each section.\n<ul class=\"wp-block-list\">\n<li><code>'#ff9999'<\/code>: light pink<\/li>\n\n\n\n<li><code>'#66b3ff'<\/code>: light blue<\/li>\n\n\n\n<li><code>'#99ff99'<\/code>: light green<\/li>\n\n\n\n<li><code>'#ffcc99'<\/code>: orange color<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Create a # Donut Chart\nfig, ax = plt.subplots()  <\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Create a chart<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>fig, ax<\/code>: <strong>figure<\/strong>(canvas) and <strong>axes<\/strong>(the area where the graph will be plotted).<\/li>\n\n\n\n<li><code>plt.subplots()<\/code>: Prepare the space for drawing a new chart.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>ax.pie(sizes, labels=labels, colors=colors, wedgeprops=dict(width=0.3), autopct='%1.1f%%')  <\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Create a doughnut chart<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>sizes<\/code>: Indicates the percentage of each section (piece).<\/li>\n\n\n\n<li><code>labels=labels<\/code>Sets the label (name) that will appear in the : section.<\/li>\n\n\n\n<li><code>colors=colors<\/code>Sets the color of the : section.<\/li>\n\n\n\n<li><code>wedgeprops=dict(width=0.3)<\/code>: <strong>Donut shape<\/strong>to adjust the width of the fragment.\n<ul class=\"wp-block-list\">\n<li><code>width=0.3<\/code>is a setting that empties the inner 70% of the full width of the circle.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>autopct='%1.1f%%'<\/code>: Displays the ratio (%) for each piece.\n<ul class=\"wp-block-list\">\n<li><code>%1.1f<\/code>: Set to show up to the first decimal place.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Add a # center circle (make it donut-shaped)\ncentre_circle = plt.Circle((0, 0), 0.70, fc='white')\nfig.gca().add_artist(centre_circle)  <\/code><\/pre>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li><strong>Add a center circle (to make it donut-shaped)<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>plt.Circle((0, 0), 0.70, fc='white')<\/code>:\n<ul class=\"wp-block-list\">\n<li><code>(0, 0)<\/code>: The coordinates of the center of the circle.<\/li>\n\n\n\n<li><code>0.70<\/code>Sets the radius of the circle.<\/li>\n\n\n\n<li><code>fc='white'<\/code>: Sets the color of the circle to white.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>fig.gca().add_artist(centre_circle)<\/code>:\n<ul class=\"wp-block-list\">\n<li>Add the white circle created above to the current axes (graph area).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>This code allows us to create a centered empty <strong>Donut shape<\/strong>is complete.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Setting the # chart title\nplt.title('Basic Donut Chart')  <\/code><\/pre>\n\n\n\n<ol start=\"6\" class=\"wp-block-list\">\n<li><strong>Setting the chart title<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>plt.title()<\/code>: Add a title to the top of the chart.<\/li>\n\n\n\n<li><code>'Basic Donut Chart'<\/code>: The title string for the chart.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>plt.show()  <\/code><\/pre>\n\n\n\n<ol start=\"7\" class=\"wp-block-list\">\n<li><strong>Output the results<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>plt.show()<\/code>: Displays the chart on the screen.<\/li>\n\n\n\n<li>This command must be run before the chart is finally output.<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Drawing a nested chart<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<pre class=\"wp-block-code\"><code>import matplotlib.pyplot as plt  <\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Importing libraries<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Data Visualization <code>matplotlib<\/code>The <code>pyplot<\/code> Import the module.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># outer donut data settings\nouter_labels = ['Germany', 'France', 'China', 'UK', 'Italy']\nouter_sizes = [30, 23, 16, 18, 13]  <\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>Setting up external donut data<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>outer_labels<\/code>: The name of each piece that will appear on the outer donut.<\/li>\n\n\n\n<li><code>outer_sizes<\/code>: Represents the proportion of each piece of the outer donut (%).<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Set up # inner donut data\ninner_labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']\ninner_sizes = [15, 15, 12, 11, 8, 8, 8, 9, 9, 9, 7, 6]  <\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><strong>Setting up internal donut data<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>inner_labels<\/code>: The name of each piece that will appear in the inner donut.<\/li>\n\n\n\n<li><code>inner_sizes<\/code>: The proportion of each piece of the inner donut, divided by the proportion of the outer piece.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># color settings\nouter_colors = plt.cm.Blues([0.6, 0.7, 0.8, 0.9, 1.0])\ninner_colors = plt.cm.RdYlBu_r([0.6, 0.6, 0.7, 0.7, 0.8, 0.8, 0.8, 0.9, 0.9, 1.0, 1.0])  <\/code><\/pre>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>Color settings<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>plt.cm.Blues<\/code>: Create a shade of blue as the color palette for the outer donut.<\/li>\n\n\n\n<li><code>plt.cm.RdYlBu_r<\/code>: Apply a red-yellow-blue combination as the color palette to use for the inner donut.<\/li>\n\n\n\n<li><code>[]<\/code> The number inside sets the darkness of the color (0 to 1).<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Create a # Nested Donut Chart\nfig, ax = plt.subplots()  <\/code><\/pre>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li><strong>Create a chart<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>fig, ax<\/code>: Create new figure and axes objects.<\/li>\n\n\n\n<li><code>plt.subplots()<\/code>: Prepare a canvas to draw the chart on.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># Outer Donut Layer\nax.pie(outer_sizes, labels=outer_labels, radius=1.3, colors=outer_colors,\n       wedgeprops=dict(width=0.3), labeldistance=1.1, autopct='%1.1f%%', pctdistance=0.85)  <\/code><\/pre>\n\n\n\n<ol start=\"6\" class=\"wp-block-list\">\n<li><strong>Create an outer donut<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>outer_sizes<\/code>: Enter the percentage of the outer donut.<\/li>\n\n\n\n<li><code>labels=outer_labels<\/code>: Set the label (country name) that will be displayed on each fragment.<\/li>\n\n\n\n<li><code>radius=1.3<\/code>Sets the radius of the outer donut.<\/li>\n\n\n\n<li><code>colors=outer_colors<\/code>Sets the color of the outer donut.<\/li>\n\n\n\n<li><code>wedgeprops=dict(width=0.3)<\/code>: Sets the width of each piece to create a donut shape.<\/li>\n\n\n\n<li><code>labeldistance=1.1<\/code>: Move the label (country name) a little further to the outside of the donut.<\/li>\n\n\n\n<li><code>autopct='%1.1f%%'<\/code>: Displays the percentage of each piece to one decimal place.<\/li>\n\n\n\n<li><code>pctdistance=0.85<\/code>Position the : ratio text closer to the inside of the donut piece.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># Inner Donut Layer\nax.pie(inner_sizes, labels=inner_labels, radius=1.0, colors=inner_colors,\n       wedgeprops=dict(width=0.3), labeldistance=0.7, autopct='%1.1f%%', pctdistance=0.6)  <\/code><\/pre>\n\n\n\n<ol start=\"7\" class=\"wp-block-list\">\n<li><strong>Create an inner donut<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>inner_sizes<\/code>: Enter the percentage of the donut inside.<\/li>\n\n\n\n<li><code>labels=inner_labels<\/code>Sets the label that will be displayed on each fragment.<\/li>\n\n\n\n<li><code>radius=1.0<\/code>: Sets the radius of the inner donut.<\/li>\n\n\n\n<li><code>colors=inner_colors<\/code>Sets the color of the inner donut.<\/li>\n\n\n\n<li><code>wedgeprops=dict(width=0.3)<\/code>: Create a donut shape.<\/li>\n\n\n\n<li><code>labeldistance=0.7<\/code>: Place the label (string) close to the inside of the fragment.<\/li>\n\n\n\n<li><code>autopct='%1.1f%%'<\/code>: Displays the ratio to one decimal place.<\/li>\n\n\n\n<li><code>pctdistance=0.6<\/code>Moves the : ratio text further inward.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Hollow out the center of # (completing the donut shape)\ncentre_circle = plt.Circle((0, 0), 0.6, fc='white')\nfig.gca().add_artist(centre_circle)  <\/code><\/pre>\n\n\n\n<ol start=\"8\" class=\"wp-block-list\">\n<li><strong>Center Hollow<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>plt.Circle((0, 0), 0.6, fc='white')<\/code>: Add a white circle in the center to complete the donut shape.<\/li>\n\n\n\n<li><code>add_artist(centre_circle)<\/code>: Adds a white circle to the chart.<\/li>\n\n\n\n<li><code>(0, 0)<\/code>: The center coordinates.<\/li>\n\n\n\n<li><code>0.6<\/code>: The radius of the white circle.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Setting up a # title (adjust spacing with the pad option)\nplt.title('Improved Nested Donut Chart with Adjusted Labels', pad=30)  <\/code><\/pre>\n\n\n\n<ol start=\"9\" class=\"wp-block-list\">\n<li><strong>Setting titles and adjusting spacing<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>plt.title()<\/code>: Add a title to the top of the chart.<\/li>\n\n\n\n<li><code>pad=30<\/code>: Adjust the spacing between the title and the chart to 30 pixels.<\/li>\n\n\n\n<li><code>\"Improved Nested Donut Chart with Adjusted Labels\"<\/code>: The chart title.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code># Layout Setup\nplt.tight_layout()  <\/code><\/pre>\n\n\n\n<ol start=\"10\" class=\"wp-block-list\">\n<li><strong>Optimize layout<\/strong>\n<ul class=\"wp-block-list\">\n<li><code>plt.tight_layout()<\/code>Automatically adjust margins so that chart elements don't overlap each other.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>plt.show()<\/code><\/pre>\n\n\n\n<ol start=\"11\" class=\"wp-block-list\">\n<li><strong>Output the results<\/strong>\n<ul class=\"wp-block-list\">\n<li>Display the chart on the screen.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Python visualization allows you to represent complex data in beautiful, easy-to-understand charts...<\/p>","protected":false},"author":3,"featured_media":4033,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[3],"tags":[162,164,618,619,450],"class_list":["post-4014","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-coding","tag-matplotlib","tag-164","tag-618","tag-619","tag-450"],"taxonomy_info":{"category":[{"value":3,"label":"\ud30c\uc774\uc36c(Python)"}],"post_tag":[{"value":162,"label":"Matplotlib"},{"value":164,"label":"\ub370\uc774\ud130 \uc2dc\uac01\ud654"},{"value":618,"label":"\ub3c4\ub11b \ucc28\ud2b8"},{"value":619,"label":"\uc911\ucca9 \ub3c4\ub11b \ucc28\ud2b8"},{"value":450,"label":"\ud30c\uc774\uc36c \uc2dc\uac01\ud654"}]},"featured_image_src_large":["https:\/\/secondlife.lol\/wp-content\/uploads\/2024\/12\/\ud30c\uc774\uc36c-\uc2dc\uac01\ud654-\ub3c4\ub11b-\ucc28\ud2b8-\uadf8\ub9ac\uae30-\ud3ec\uc2a4\ud2b8-\uc378\ub124\uc77c-1-600x600.jpg",600,600,true],"author_info":{"display_name":"TERE","author_link":"https:\/\/secondlife.lol\/en\/author\/tere\/"},"comment_info":0,"category_info":[{"term_id":3,"name":"\ud30c\uc774\uc36c(Python)","slug":"python-coding","term_group":0,"term_taxonomy_id":3,"taxonomy":"category","description":"","parent":20,"count":119,"filter":"raw","cat_ID":3,"category_count":119,"category_description":"","cat_name":"\ud30c\uc774\uc36c(Python)","category_nicename":"python-coding","category_parent":20}],"tag_info":[{"term_id":162,"name":"Matplotlib","slug":"matplotlib","term_group":0,"term_taxonomy_id":162,"taxonomy":"post_tag","description":"","parent":0,"count":19,"filter":"raw"},{"term_id":164,"name":"\ub370\uc774\ud130 \uc2dc\uac01\ud654","slug":"%eb%8d%b0%ec%9d%b4%ed%84%b0-%ec%8b%9c%ea%b0%81%ed%99%94","term_group":0,"term_taxonomy_id":164,"taxonomy":"post_tag","description":"","parent":0,"count":52,"filter":"raw"},{"term_id":618,"name":"\ub3c4\ub11b \ucc28\ud2b8","slug":"%eb%8f%84%eb%84%9b-%ec%b0%a8%ed%8a%b8","term_group":0,"term_taxonomy_id":618,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":619,"name":"\uc911\ucca9 \ub3c4\ub11b \ucc28\ud2b8","slug":"%ec%a4%91%ec%b2%a9-%eb%8f%84%eb%84%9b-%ec%b0%a8%ed%8a%b8","term_group":0,"term_taxonomy_id":619,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":450,"name":"\ud30c\uc774\uc36c \uc2dc\uac01\ud654","slug":"%ed%8c%8c%ec%9d%b4%ec%8d%ac-%ec%8b%9c%ea%b0%81%ed%99%94","term_group":0,"term_taxonomy_id":450,"taxonomy":"post_tag","description":"","parent":0,"count":18,"filter":"raw"}],"_links":{"self":[{"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/posts\/4014","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/comments?post=4014"}],"version-history":[{"count":9,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/posts\/4014\/revisions"}],"predecessor-version":[{"id":4026,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/posts\/4014\/revisions\/4026"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/media\/4033"}],"wp:attachment":[{"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/media?parent=4014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/categories?post=4014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/secondlife.lol\/en\/wp-json\/wp\/v2\/tags?post=4014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}