How to create Pie chart using plotly

share link

by vsasikalabe dot icon Updated: Oct 30, 2023

technology logo
technology logo

Solution Kit Solution Kit  

A pie chart is a type of circular statistical chart. We can divide it into sectors to display numerical proportions. This is also a circular analytical chart. 

We can split into regions to symbolize numerical percentages. We can divide the pie chart into sectors. Each sector is a part of the whole data set. We can divide all sectors by names. The Pie chart will show the percentage of the corresponding part of the pie. It helps understand well because of its different portions of the color.scalegroup. We should note it according to their totals.   

Plotly is an open-source data visualization library. It provides a large quality of chart types. A Plotly Dash tool helps make a Dashboard with callbacks. We can also show the percentage and the data labels inside the pie sectors. It uses the textinfo parameter of the Pie class. You can display or hide the pie trace in a chart by setting the attribute. It provides many chart types. 

It can show different types of data. It includes bar charts, scatter plots, and heat maps. Each piece of the pie chart's size depends on the proportion of numerical data. By default, Plotly Express uses the color sequence from the active template's attribute. The default active template uses the plotly color sequence. We must pass a data frame or array of values and labels inside the function to create a pie chart.   

A pie chart is sometimes called a circle chart. This describes a set of nominal data. Also, it displays the different values of a given variable. We can split this type of chart into a series of segments in a circle. This chart indicates how to divide a total part between different categorical variables. We can divide a circle into proportional parts. Each categorical element corresponds with a single part of the circle.  

Each arc length represents the proportion of each category. The Plotly Python library supports over 40 unique chart types. It covers various statistical, financial, geographic, and scientific use cases. The benefit of using pie charts is the ability to add interactivity to our charts. With Plotly, you can hover over individual parts of the pie chart to see specific data points. You can click on a slice to see more detailed information.   


  • It permits a visual check of the reasonable accuracy of calculations.   
  • It requires minimal extra explanation.   
  • It will be easily understood due to its widespread use in business and the media.   

Preview of the output that you will get on running this code from your IDE.


In this solution, we used the Plotly library.


Follow the steps carefully to get the output easily.

  1. Download and Install the PyCharm Community Edition on your computer.
  2. Open the terminal and install the required libraries with the following commands.
  3. Install Plotly - pip install plotly.
  4. Create a new Python file on your IDE.
  5. Copy the snippet using the 'copy' button and paste it into your python file.
  6. Run the current file to generate the output.

I hope you found this useful. I have added the link to dependent libraries, and version information in the following sections.

I found this code snippet by searching for ' How to subplot pie chart in plotly?' in Kandi. You can try any such use case!

Environment Tested

I tested this solution in the following versions. Be mindful of changes when working with other versions.

  1. The solution is created in PyCharm 2022.3.
  2. The solution is tested on Python 3.11.1
  3. Plotly version- 5.18.0

Using this solution, we are able to create Pie chart using plotly with simple steps. This process also facilitates an easy-way-to use hassle-free method to create a hands-on working version of code which would help us to create Pie chart using plotly.

Dependent Libraries

plotly.pyby plotly

Python doticonstar image 13630 doticonVersion:v5.15.0doticon
License: Permissive (MIT)

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!


            plotly.pyby plotly

            Python doticon star image 13630 doticonVersion:v5.15.0doticon License: Permissive (MIT)

            The interactive graphing library for Python :sparkles: This project now includes Plotly Express!

                      If you do not have the Plotly library that is required to run this code, you can install it by clicking on the above link.

                      You can search for any dependent library on Kandi like Plotly.


                      1. What are the advantages and disadvantages of using Plotly's interactive pie charts?  

                      It shows data in slices. It has a circular shape. The name comes from a resemblance to pie. The Pie chart works well. This is simple to create and understand. This pie chart is not as suitable for complex as it needs visualization tools like a bar graph.   


                      • It shows the relative proportions of many classes of data.   
                      • We can make the size of the circle equal to the total quantity.  
                      • It displays a large data set in visual form.   
                      • It is visually simpler.   


                      • It only sometimes gives exact values.   
                      • We may need many pie charts to display changes over time.   
                      • Fail to show key assumptions, causes, effects, or patterns.   
                      • It may be easily manipulated to yield false impressions.   


                      2. How does a bar chart in Plotly compare with a pie chart when visually representing data?   

                      We can use a pie chart only if the sum of the individual parts adds to a meaningful whole. This will help us visualize how each part contributes to that whole. Meanwhile, a bar chart can help with various data types. It is not just for breaking down a whole into components.   


                      3. How can I display labels on my plotly pie sectors?   

                      Sometimes, Plotly Express needs to provide a better starting point. So, it is possible to use the more generic go.Pie class from plotly.graph_objects in the go.Pie. So now we can visualize the data by the sectors of the pie. It is set in values. The sector labels are set in labels.  


                      4. What is an open-source data visualization library?  

                      Plotly is an open-source data visualization library. It provides many chart types. A Plotly Dash tool helps make a Dashboard with callbacks. With this plot, we can add charts to any article or blog. We can also create charts in the chart studio of plotly.   


                      5. Are there differences between a donut and a regular plotly pie chart?   

                      Donut charts and pie charts are equal. But, except that also to slice size & color pie charts. It includes angles we can process to make more sense of the data. But we can use both charts to compare a part to the whole.   


                      6. Can I assign different colors for each sector in my plotly pie chart?   

                      We can change the color of the pie in the plotly module. Different colors help to differentiate the data from each other. It helps to understand the data more efficiently.  


                      1. For any support on kandi solution kits, please use the chat
                      2. For further learning resources, visit the Open Weaver Community learning page.

                      See similar Kits and Libraries