4

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

Yuca
  • 6,010
  • 3
  • 22
  • 42

1 Answers1

11

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)
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • used the last option and it work perfectly, thank you very much :) – Yuca Sep 11 '18 at 11:43
  • 3
    one thing to notice is that using `ax[1, 1].tick_params(which="both", bottom=True)` alone wont work. The way I make it work is by keeping `ax[1, 1].xaxis.set_minor_locator(minorLocator)` – Yuca Sep 11 '18 at 12:11
  • 1
    Sure, those lines are meant to be *added* to the code in the question. Which is also the reason why having a consistent runnable code in the question is useful. – ImportanceOfBeingErnest Sep 11 '18 at 12:14
  • I'm just clarifying since at least one other person was interested in the solution and your original post doesn't make clear if that alone fixes it or not, but thanks for mentioning in the comments! – Yuca Sep 11 '18 at 12:46