Hi guys
I’m kinda new to this forum and I don’t how should I write questions and stuff like this. At any case if please let me know if something is not clear.
I need some advise on setting up titles for subplot pie charts. For a project that I’m doing I need to show the crime distribution(violent/non-violent) for a given Police District. End end goal should be a plot comprised of multiple subplots where each Subplot should have a title. Currently I don’t know how to set the subtitles.Ex of a title would be ‘Violent Crime Distribution Police District1’.
Example of dataframe showing violent/-non violent crime distribution for Police District 1 pd_1D:
labels values
0 Non-Violent 2097
1 Violent 1362
This is the sample of the plotly code used to plot the pie charts subplots:
fig= {
‘data’:[{
‘labels’:pd_1D[‘labels’],
‘values’:pd_1D[‘values’],
‘type’:‘pie’,
‘name’:‘PD 1D’,
‘domain’: {‘x’: [0, .20],
‘y’: [0, .49]},
‘textinfo’:‘blahcjakjsa’
},
{
‘labels’:pd_2D[‘labels’],
‘values’:pd_2D[‘values’],
‘type’:‘pie’,
‘name’:‘PD 2’,
‘domain’: {‘x’: [.35, .55],
‘y’: [0, .49]},
‘textinfo’:‘PD 2D’
}
],
‘layout’: {‘title’: ‘Violent/Non-Violent crime distribution/Police District Number’}
}
iplot(fig, filename=‘pie_chart_subplots’))
This is the reference from ploty official site:
https://plot.ly/python/pie-charts/
However I can’t seem to find a way to add a title for each individual subplots. Please see below print screen with the subplots
I’m able to achive this in matplotlib. Please see attached
This is a snipped of the code used with mathplotlib
ax1, ax2, ax3, ax4, ax5 , ax6 = fig.axes
ax1.pie(pd_1D_values, labels=pd_1D_labels,explode=explode, autopct=’%1.1f%%’, shadow=True)
Equal aspect ratio ensures that pie is drawn as a circle.
ax1.axis(‘equal’)
ax1.set_title(‘PD 1D’)
plt.suptitle(‘title_string’, x=1.1,y=3.1, fontsize=25)
plt.subplots_adjust(left = 0.12,right = 2.3,bottom = 0.9,top = 2.9,wspace = 1 ,hspace = 0.2 )
plt.show()
Please advise.
Mihai