Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add minor gridlines to matplotlib plot using seaborn

I'm a fan of the Seaborn package for making nice-looking plots using Matplotlib. But I can't seem to figure out how to show minor gridlines in my plots.

import numpy as np import matplotlib.pyplot as plt import seaborn as sbn  x = np.linspace(0, 2 * np.pi, 100) y = np.sin(x)  fig, ax = plt.subplots(1, 1) ax.scatter(x, y)  ax.grid(b=True, which='major') ax.grid(b=True, which='minor') 

gives:

enter image description here

Any thoughts here? Also any thoughts on how to adjust the style of the Seaborn gridlines that do show up...in particular, I'd love to make them narrower.

like image 465
8one6 Avatar asked Feb 21 '14 01:02

8one6


People also ask

What is the seaborn Despine () function used for?

despine. Remove the top and right spines from plot(s). Figure to despine all axes of, defaults to the current figure.


1 Answers

Wound up combining CT Zhu's answer with tcaswell's hint:

import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import seaborn as sbn  x = np.linspace(0, 2 * np.pi, 100) y = np.sin(x)  fig, ax = plt.subplots(1, 1)  ax.scatter(x, y) ax.get_xaxis().set_minor_locator(mpl.ticker.AutoMinorLocator()) ax.get_yaxis().set_minor_locator(mpl.ticker.AutoMinorLocator()) ax.grid(b=True, which='major', color='w', linewidth=1.0) ax.grid(b=True, which='minor', color='w', linewidth=0.5) 

enter image description here

like image 113
8one6 Avatar answered Sep 21 '22 07:09

8one6