python - Using seaborn and contourf, how can I plot gridlines? -
using following code, first contour plot has grid lines. second plot, have imported seaborn, grid lines don't show up. need add make grid lines show on second plot.
import numpy np import matplotlib mpl import matplotlib.pyplot plt dx=0.05 x=np.arange(0,5+dx,dx) y=x x,y = np.meshgrid(x,y) z = np.sin(x)**10+np.cos(10+y*y)*np.cos(x) nbins=10 levels=mpl.ticker.maxnlocator(nbins=nbins).tick_values(z.min(),z.max()) plt.figure() plt.contourf(x,y,z,levels=levels) plt.colorbar() plt.grid('on') import seaborn sns sns.set_context("notebook") sns.set_style("whitegrid") plt.figure() plt.contourf(x,y,z,levels=levels) plt.colorbar() plt.grid('on') plt.show()
you either need change either axes.axisbelow
rc parameter or zorder of contourf plot. do
sns.set(context="notebook", style="whitegrid", rc={"axes.axisbelow": false})
when set style or
plt.contourf(x, y, z, levels=levels, zorder=0)
when draw plot.
Comments
Post a Comment