Using nautical and contour, how can I build meshes?

Using the following code, the first contour plot has grid lines. For the second plot, I imported the seabed, but no grid lines appear. What do I need to add in order for the grid lines to appear on the second graph.

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()

      

First picture

Second Picture

+3


source to share


1 answer


You either need to change either the axes.axisbelow

rc parameter or the zorder of the outline plot. So you could do

sns.set(context="notebook", style="whitegrid",
        rc={"axes.axisbelow": False})

      

When setting a style or



plt.contourf(x, y, Z, levels=levels, zorder=0)

      

When you draw a graph.

+2


source







All Articles