Plotly Pie Chart
Plotly is a tool for creating charts, which works with Jupyter Notebook. Among its options is the Pie Chart. We've got some examples ready to demonstrate their appearance and functionality, so you can see how they work.
- simple pie chart
- pie chart with
numpydata - pie chart with
pandasdata - an interactive pie chart
If you need any information about Plotly check their docs: Plotly Docs (opens in a new tab).
After plotly installation remember to restart your Jupyter before doing anything.
All of code examples are availabe as Jupyter Notebooks in our GitHub repositiory:
Pie Chart
Example using only plotly package:
# import packages
import plotly.express as px
# create data
x = [20,25,15,40]
# plot
fig = px.pie(values=x)
fig.show()
Pie Chart with Numpy Data
Display numpy data as a pie chart using plotly:
# import packages
import plotly.express as px
import numpy as np
# create data
x = np.array([43,75,89,74,72])
# plot
fig = px.pie(values=x)
fig.show()
Pie Chart with Pandas Data
Make a pie chart with pandas data using plotly:
# import packages
import plotly.express as px
import pandas as pd
# create data
df = pd.DataFrame({'values': [76,54,45,14,72]})
# plot
fig = px.pie(values = df['values'])
fig.show()
Interactive Pie Chart
Ordinary charts are dull. Let's make an interactive pie chart with plotly and mercury packages. You can decide if legend will be visible using mercury widgets. In this case, we're using Checkbox (opens in a new tab).
# import packages
import plotly.express as px
import mercury as mr# mercury widget
checkbox = mr.Checkbox(label="Legend")# create data
x = [9,7,8,12]
names = ["Apples", "Bananas", "Oranges", "Grapes"] if checkbox.value else None
# plot
fig = px.pie(values=x, names=names)
fig.show()Now, you can easily turn your Jupyter Notebook into a Web App! Check out this video to see how it looks.
Deploying Web App is very easy that you can do it in 3 steps:
Login to Mercury Cloud
If you don't have account, you can create it here: Mercury Cloud (opens in a new tab).
Create new site
Create new or use an existing site.
Upload your notebook
Upload the notebook with code.
Congrats! You just created your own Web App and you can share your Jupyter Notebooks with nontechnical users. If you need more information about deploying the Web App check Mercury Cloud Documentation (opens in a new tab).