I’m struggling setting up pie chart subplots with an appropriate size and spacing. If the size of a pie chart is to small then the data is not visible, if the spacing between subplots is not appropriate then the graph will be crammed up. So the layout of the subplots is the following 3 rows; 2 columns. Please see below snippet from the dataset:
violent_main=pd.DataFrame({'Counts': crimes[crimes['Class Main Cathegory'].notnull()==True].groupby(['Police District Number'])['Class Main Cathegory'].value_counts()}).reset_index()
violent_main
Snippet of the dataset:
I’m using the following code to plot:
#PD_1D
label_PD_1D=violent_main[violent_main[‘Police District Number’]==‘1D’][‘Class Main Cathegory’]
values_PD_1D=violent_main[violent_main[‘Police District Number’]==‘1D’][‘Counts’]
#PD_2D
label_PD_2D=violent_main[violent_main['Police District Number']=='2D']['Class Main Cathegory']
values_PD_2D=violent_main[violent_main['Police District Number']=='2D']['Counts']
#PD_3D
label_PD_3D=violent_main[violent_main['Police District Number']=='3D']['Class Main Cathegory']
values_PD_3D=violent_main[violent_main['Police District Number']=='3D']['Counts']
#PD_4D
label_PD_4D=violent_main[violent_main['Police District Number']=='4D']['Class Main Cathegory']
values_PD_4D=violent_main[violent_main['Police District Number']=='4D']['Counts']
fig = {
"data": [
{
"values": values_PD_1D,
"labels": label_PD_1D,
"domain": {'x': [0.0, 0.35], 'y': [2.22, 2.53]},
"name": "PD_1D",
"hoverinfo":"label+percent+name",
"hole": .4,
"type": "pie"
},
{
"values": values_PD_2D,
"labels": label_PD_2D,
"text":"CO2",
"textposition":"inside",
"domain":{'x': [0.50, 0.85], 'y': [2.22, 2.53]},
"name": "PD_2D",
"hoverinfo":"label+percent+name",
"hole": .4,
"type": "pie"
},
{
"values": values_PD_3D,
"labels": label_PD_3D,
"text":"CO2",
"textposition":"inside",
'domain': {'x': [0.0, 0.35], 'y': [.9, 1.13]},
"name": "CO2 Emissions",
"hoverinfo":"label+percent+name",
"hole": .4,
"type": "pie"
}
],
"layout": {
"title":"Violent Crimes by main cathegory",
"annotations": [
{
"font": {
"size": 20
},
"showarrow": False,
"text": "PD_1D",
"x": 0.12,
"y": 0.5
},
{
"font": {
"size": 20
},
"showarrow": False,
"text": "PD_2D",
"x": 0.73,
"y": 0.5
},
{
"font": {
"size": 20
},
"showarrow": False,
"text": "PD_3D",
"x": 0.20,
"y": 0.25
}
]
}
}
iplot(fig, filename='donut')
Within this code I’m trying to manipulate layout using the “domain”:{x:[],y:[]) However I can’t the layout desired. So for instance plot number 3 is smaller and above plot 1 and plot 2. What I would like is that plot to be the same size as the other plots but below then Please see below plot:
I’m hoping I can figure out the logic so I can plot the pie charts: 3 rows: 2 columns.
Please advise