fig,ax=plt.subplots()df.plot(kind='scatter',x='GDP_per_capita',y='life_expectancy',ax=ax)# Turn on the gridax.grid()
Customize the grid
fig,ax=plt.subplots()df.plot(kind='scatter',x='GDP_per_capita',y='life_expectancy',ax=ax)# Don't allow the axis to be on top of your dataax.set_axisbelow(True)# Customize the gridax.grid(linestyle='-',linewidth='0.5',color='red')
Render with a larger grid (major grid) and a smaller grid (minor grid)
fig,ax=plt.subplots()df.plot(kind='scatter',x='GDP_per_capita',y='life_expectancy',ax=ax)# Don't allow the axis to be on top of your dataax.set_axisbelow(True)# Turn on the minor TICKS, which are required for the minor GRIDax.minorticks_on()# Customize the major gridax.grid(which='major',linestyle='-',linewidth='0.5',color='red')# Customize the minor gridax.grid(which='minor',linestyle=':',linewidth='0.5',color='black')
Turn on the grid but turn off ticks
fig,ax=plt.subplots()df.plot(kind='scatter',x='GDP_per_capita',y='life_expectancy',ax=ax)# Don't allow the axis to be on top of your dataax.set_axisbelow(True)# Turn on the minor TICKS, which are required for the minor GRIDax.minorticks_on()# Customize the major gridax.grid(which='major',linestyle='-',linewidth='0.5',color='red')# Customize the minor gridax.grid(which='minor',linestyle=':',linewidth='0.5',color='black')# Turn off the display of all ticks.ax.tick_params(which='both',# Options for both major and minor tickstop='off',# turn off top ticksleft='off',# turn off left ticksright='off',# turn off right ticksbottom='off')# turn off bottom ticks
Want to hear when I release new things? My infrequent and sporadic newsletter can help with that.