To add a shadow to the wedge of a pie chart, we use the shadow
parameter, which is added as a parameter value to the pie()
method.
pie(x, shadow)
x
: The data array to be represented on the pie chart
shadow
: This is used to add the shadow to the pie chart. It takes the True
value.
The wedge of the pie chart is exploded using the
explode
parameter value of thepie()
method. Theexplode
parameter takes a list values of which each represents the wedge values from the center of the pie chart.
To differentiate between a pie chart having or not having a shadow, let us take a closer look at the output of the code below.
from matplotlib.pyplot import pie, showfrom numpy import arrayy = array([35, 25, 25, 15, 10])mylabels = ["Tomatoes", "Mangoes", "Oranges", "Apples", "Bamamas"]myexplode = [0.2, 0, 0.4, 0, 0]pie(y, labels = mylabels, explode = myexplode)show()
matplotlib
) and module(pyplot
).numpy
library.y
.mylabels
that will represent the label parameter of the pie()
method.myexplode
that contains values that represents the explode
parameter of the pie()
method.pie()
method to create a pie chart with parameter values x
, labels
, and explode
.show()
method to show our plot.We will create an exploded pie chart with shadows in the code below.
from matplotlib.pyplot import pie, showfrom numpy import arrayy = array([35, 25, 25, 15, 10])mylabels = ["Tomatoes", "Mangoes", "Oranges", "Apples", "Bamamas"]myexplode = [0.2, 0, 0.4, 0, 0]pie(y, labels = mylabels, explode = myexplode)show()
Like the first code, we created an exploded pie chart. But this time, we used the shadow
parameter, which created a shadow on our pie chart, as can be seen in the code’s output.