data = np.random.rand(3)

# Set `animation_duration` (in milliseconds) to have smooth transitions
fig = plt.figure(animation_duration=1000)
pie = plt.pie(data, display_labels='outside')
fig

"""
Explanation: Basic Pie Chart
End of explanation
"""


n = np.random.randint(1, 10)
pie.sizes = np.random.rand(n)

"""
Explanation: Update Data
End of explanation
"""


with pie.hold_sync():
    pie.display_values = True
    pie.values_format = '.1f'

"""
Explanation: Display Values
End of explanation
"""


pie.sort = True

"""
Explanation: Enable sort
End of explanation
"""


pie.selected_style = {'opacity': '1', 'stroke': 'white', 'stroke-width': '2'}
pie.unselected_style = {'opacity': '0.2'}
pie.selected = [1]

pie.selected = None

"""
Explanation: Set different styles for selected slices
End of explanation
"""


pie.labels = list('ABCDEF')

"""
Explanation: Update labels
End of explanation
"""


pie.label_color = 'Red'
pie.font_size = '20px'
pie.font_weight = 'bold'

"""
Explanation: For more on piechart interactions, see the Mark Interactions notebook
Modify label styling
End of explanation
"""


fig1 = plt.figure(animation_duration=1000)
pie1 = plt.pie(np.random.rand(6), inner_radius=0.05)
fig1

"""
Explanation: Update pie shape and style
End of explanation
"""


# As of now, the radius sizes are absolute, in pixels
with pie1.hold_sync():
    pie1.radius = 150
    pie1.inner_radius = 100

# Angles are in radians, 0 being the top vertical
with pie1.hold_sync():
    pie1.start_angle = -90
    pie1.end_angle = 90

"""
Explanation: Change pie dimensions
End of explanation
"""


pie1.y = 0.1
pie1.x = 0.6
pie1.radius = 180

"""
Explanation: Move the pie around
x and y attributes control the position of the pie in the figure.
If no scales are passed for x and y, they are taken in absolute 
figure coordinates, between 0 and 1.
End of explanation
"""


pie1.stroke = 'brown'
pie1.colors = ['orange', 'darkviolet']
pie1.opacities = [.1, 1]
fig1

"""
Explanation: Change slice styles
Pie slice colors cycle through the colors and opacities attribute, as the Lines Mark.
End of explanation
"""


from bqplot import ColorScale, ColorAxis

n = 7
size_data = np.random.rand(n)
color_data = np.random.randn(n)

fig2 = plt.figure()
plt.scales(scales={'color': ColorScale(scheme='Reds')})
pie2 = plt.pie(size_data, color=color_data)
fig2

"""
Explanation: Represent an additional dimension using Color
The Pie allows for its colors to be determined by data, that is passed to the color attribute. 
A ColorScale with the desired color scheme must also be passed.
End of explanation
"""


