Let’s see how Exploding out slices of a Pie Chart in Plotly works.
To see how to explode slice out I need example pie chart. I imported Plotly Express and use tips data which is defined in Plotly as example data set to work on.
This is a code of my example pie chart.
import plotly.express as px data_frame = px.data.tips() pie_chart = px.pie(data_frame, names='day', values='tip', title='Tips values by day', template='gridon') pie_chart.show()
How to define pull
To explode out slices of my pie chart I need to update traces and define pull parameter. The higher the pull the more slices are exploded out from the pie chart.
pie_chart.update_traces(pull=0.1)
How to explode one slice of a pie
There is also a possibility to explode only one slice of a pie. To explode only one of them you need to create a list of pull parameter.
pie_chart.update_traces(pull=[0.1, 0, 0, 0])
And this is how one exploded out slice look like. Thanks to that I impored visibility of Sundays tips.
Key Takeaways
- To explode out slices of a pie chart in Plotly, you can use the `pull` parameter.
- The higher the `pull` value, the more the slices are exploded out.
- You can also explode only one slice of a pie chart by passing a list of `pull` values to the `update_traces()` function.
FAQ
- Q: What is the `pull` parameter?
- A: The `pull` parameter controls how much the slices of a pie chart are exploded out.
- Q: How do I set the `pull` parameter?
- A: You can set the `pull` parameter by passing it to the `update_traces()` function.
- Q: How do I explode only one slice of a pie chart?
- A: You can explode only one slice of a pie chart by passing a list of `pull` values to the `update_traces()` function.