1

I'd like to add white 'breaks' to the bars of my histograms in matplotlib, so the grid lines appear to continue through the plot without being intrusive or busy in the background. I'd like to to look something like the following:

What I want - https://i.stack.imgur.com/rzbEz.jpg

Here is a test histogram to work with:

vals = np.random.randn(1000)
f = plt.figure(figsize=[4,4])
ax = f.add_subplot(111)
ax.hist(vals, bins=20, normed=True)
Tim
  • 2,756
  • 1
  • 15
  • 31
  • Looks like you want to [add grid lines](https://stackoverflow.com/a/9149619/198633) – inspectorG4dget Sep 12 '17 at 17:53
  • @inspectorG4dget I don't want the full gridlines, though - I just want small visual breaks in the bars of the histogram where the gridlines would be. I find full background grids too visually busy. – Tim Sep 12 '17 at 18:50

1 Answers1

1

If you make the grid lines the same color as the background and manage the horizontal and vertical independently, then you can get the "visual breaks" you want.

import numpy as np
from matplotlib import pyplot as plt
vals = np.random.randn(1000)
f = plt.figure(figsize=\[4,4\])
ax = f.add_subplot(111)
ax.hist(vals, bins=20, normed=True, 
        )
ax.yaxis.grid(which="major", color='white', linestyle='-', linewidth=0.5)
ax.xaxis.grid(which="major", color='white', linestyle='-', linewidth=4)

plt.show()]

enter image description here

PabTorre
  • 2,878
  • 21
  • 30