Styling my subplots - “I am so close I can smell the roses”
Hi All,
This is my first time trying to get subplots working and of course, I want pie charts as my subplots so goodbye Plotly Express hello Graphic Objects.
I am pulling in data from a couple of excel sheets into pandas and I can create standard Pie charts in px fine
This has the information I require and a legend that is displayed as I like it. (I would love to know how to get rid of the percentages on this pie though)
When I create the subplots using go I get the following
I have three issues with this that I cant figure out. After reading copious amounts of posts I’m still baffled.
My three issues are
- How do I get the year to display under the chart? I tried annotations but that just borked on me?
- I would like physical number instead of percentages on the subplot?
- How do I not chart items that have zero value?
I am guessing the legend will sort itself out when I get data selection correct?
The dataframes df15 and df16 contain the following (I am just showing df15 but 16 is similar, just different values)
business_unit
Company Secretariat 0
Data Privacy 1
Financial Risk 0
GmbH 3
IT Development 0
Information Security 23
below is my code I use to create my subplots.
y2020group = y2020raca.groupby('business_unit')
y2021group = y2021raca.groupby('business_unit')
df15 = y2020group.apply(lambda x: x['action_id'].count())
df16 = y2021group.apply(lambda x: x['action_id'].count())
fig = make_subplots(
rows=1, cols=2,
specs=[[{"type": "domain"}, {"type": "domain"}]],
subplot_titles=("<b>2020<b>","<b>2021<b>")
)
fig.add_trace(go.Pie(values = df15),
row=1, col=1)
fig.add_trace(go.Pie(values = df16),
row=1, col=2)
fig.update_layout(title_text="<b>Number of Action Items by Business Unit<b>",
height=600,
showlegend=True
)
fig.show()
Thanks in advance for your help.
Tom