back to the matplotlib-gallery
at https://github.com/rasbt/matplotlib-gallery
In [1]:
%load_ext watermark
In [2]:
%watermark -u -v -d -p matplotlib,numpy
[More info](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/ipython_magic/watermark.ipynb) about the `%watermark` extension
In [3]:
%matplotlib inline
In [4]:
import numpy as np
import random
from matplotlib import pyplot as plt
data = np.random.normal(0, 20, 1000)
# fixed bin size
bins = np.arange(-100, 100, 5) # fixed bin size
plt.xlim([min(data)-5, max(data)+5])
plt.hist(data, bins=bins, alpha=0.5)
plt.show()
In [5]:
plt.hist(data, bins=bins, alpha=0.5)
plt.grid()
plt.show()
Or alternatively:
In [6]:
plt.hist(data, bins=bins, alpha=0.5)
ax = plt.gca()
ax.grid(True)
plt.show()
In [7]:
plt.hist(data, bins=bins, alpha=0.5)
ax = plt.gca()
ax.xaxis.grid(True)
plt.show()
In [8]:
plt.hist(data, bins=bins, alpha=0.5)
ax = plt.gca()
ax.yaxis.grid(True)
plt.show()
In [9]:
import numpy as np
# major ticks every 10
major_ticks = np.arange(-100, 101, 10)
ax = plt.gca()
ax.yaxis.grid()
ax.set_yticks(major_ticks)
plt.hist(data, bins=bins, alpha=0.5)
plt.show()
In [10]:
from matplotlib import rcParams
rcParams['grid.linestyle'] = '-'
rcParams['grid.color'] = 'blue'
rcParams['grid.linewidth'] = 0.2
plt.grid()
plt.hist(data, bins=bins, alpha=0.5)
plt.show()
In [ ]: