Reputation: 3009
Using the following code, the first contour plot has grid lines. For the second plot, I have imported seaborn, but the grid lines don't show up. What do I need to add to make the grid lines show on the second plot.
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as 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 as 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()
Upvotes: 4
Views: 6774
Reputation: 49002
You either need to change either the axes.axisbelow
rc parameter or the zorder of the contourf plot. So you could do
sns.set(context="notebook", style="whitegrid",
rc={"axes.axisbelow": False})
When you set up the style or
plt.contourf(x, y, Z, levels=levels, zorder=0)
When you draw the plot.
Upvotes: 3