Skip to content

Instantly share code, notes, and snippets.

@aniruddha27
Created March 12, 2020 17:52
Show Gist options
  • Save aniruddha27/bf7cadb77ee0eedc529621b44270ff1a to your computer and use it in GitHub Desktop.
Save aniruddha27/bf7cadb77ee0eedc529621b44270ff1a to your computer and use it in GitHub Desktop.
center_type_name = ['TYPE_A','TYPE_B','TYPE_C']
#relation between op area and number of orders
op_table=pd.pivot_table(df,index='op_area',values='num_orders',aggfunc=np.sum)
#relation between center type and op area
c_type = {}
for i in center_type_name:
c_type[i] = df[df['center_type']==i].op_area
#relation between center type and num of orders
center_table=pd.pivot_table(df,index='center_type',values='num_orders',aggfunc=np.sum)
#subplots
fig,ax = plt.subplots(nrows=3,ncols=1,figsize=(8,12))
#scatter plots
ax[0].scatter(op_table.index,op_table['num_orders'],color='pink')
ax[0].set_xlabel('Operation area')
ax[0].set_ylabel('Number of orders')
ax[0].set_title('Does operation area affect num of orders?')
ax[0].annotate('optimum operation area of 4 km^2',xy=(4.2,1.1*10**7),xytext=(7,1.1*10**7),arrowprops=dict(facecolor='black', shrink=0.05),fontsize=12)
#boxplot
ax[1].boxplot([x for x in c_type.values()], labels=[x for x in c_type.keys()])
ax[1].set_xlabel('Center type')
ax[1].set_ylabel('Operation area')
ax[1].set_title('Which center type had the optimum operation area?')
#bar graph
ax[2].bar(center_table.index,center_table['num_orders'],alpha=0.7,color='orange',width=0.5)
ax[2].set_xlabel('Center type')
ax[2].set_ylabel('Number of orders')
ax[2].set_title('Orders per center type')
#show figure
plt.tight_layout()
plt.savefig('C:\\Users\\Dell\\Desktop\\AV Plotting images\\matplotlib_plotting_12.png',dpi=300,bbox_inches='tight')
plt.show();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment