.pie()
Anonymous contributor
Anonymous contributor1 total contribution
Anonymous contributor
Published Sep 5, 2024
Contribute to Docs
In Plotly, the .pie()
method is used to create a pie chart, which visually represents data proportions. This method helps transform data into an appealing visual format, making it easier for readers to understand the relationships between variables.
Syntax
plotly.express.pie(data_frame=None, values=None, names=None, title=None, hole=None, color_discrete_sequence=None, hover_data=None, labels=None, ...)
data_frame
: TheDataFrame
to be used.values
: The values to be used to define the pie slices.names
: The labels for each pie slice.title
: The title of the chart.hole
: Creates a donut chart if value is between0
and1
.color_discrete_sequence
: The color sequence for the pie slices.hover_data
: The column name for the additional data to show on hover.labels
: The custom labels to be used instead of column names in the figure.
Note: The ellipsis (…) indicates that there can be additional optional parameters beyond those listed here.
Example
The example below shows the usage of the .pie()
method:
# Import necessary librariesimport plotly.express as pximport pandas as pd# Define example datadata = {'Category': ['A', 'B', 'C', 'D'],'Value': [45, 55, 30, 15]}# Create a DataFramedf = pd.DataFrame(data)# Create and display a pie chartfig = px.pie(df,values='Value',names='Category',title='Example Pie Chart',hole=0.3,color_discrete_sequence=px.colors.sequential.RdBu,labels={'Category': 'Category Name'})# Display the plotfig.show()
The code above generates the following output:
All contributors
- Anonymous contributorAnonymous contributor1 total contribution
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.