Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib set minor ticks under Seaborn

I have the following code to plot a series of subplots:

minorLocator = AutoMinorLocator()
fig, ax = plt.subplots(4, 2, figsize=(8, 12))

data = np.random.rand(20,5)
ax[1, 1].plot(data, alpha=0.5)
ax[1, 1].set_title('Simulation')    
ax[1, 1].xaxis.set_minor_locator(minorLocator)

However, this fails to include the minor tick 'markers' on the plot. I also tried

ax[1, 1].plot(data, alpha=0.5)
ax[1, 1].xaxis.set_minor_locator(minorLocator)
ax[1, 1].xaxis.set_minor_formatter(NullFormatter())

but it also fails. Since I'm working with seaborn styles, I suspect there's a need to override a Seaborn parameter but I'm not sure how. this is my Seaborn implementation

import seatborn as sns
sns.set()

How can I add the 'daily' marker to my x axis? These are examples of my plots:

enter image description here

like image 216
Yuca Avatar asked Jan 27 '23 11:01

Yuca


1 Answers

Seaborn .set() turns the ticks off by default. It uses it's darkgrid style, which modifies the matplotlib rc parameters and sets the xtick.bottom and ytick.left parameters to False (source).

A solution is to either set them to True globally,

sns.set(rc={"xtick.bottom" : True, "ytick.left" : True})

or

sns.set()
plt.rcParams.update({"xtick.bottom" : True, "ytick.left" : True})

or, alternatively, to turn them on for the axes in question

ax[1, 1].tick_params(which="both", bottom=True)
like image 113
ImportanceOfBeingErnest Avatar answered Mar 23 '23 17:03

ImportanceOfBeingErnest