%load_ext watermark

%watermark -u -v -d -p matplotlib,numpy

"""
Explanation: Sebastian Raschka
back to the matplotlib-gallery at https://github.com/rasbt/matplotlib-gallery
End of explanation
"""


%matplotlib inline

"""
Explanation: <font size="1.5em">More info about the %watermark extension</font>
End of explanation
"""


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()

"""
Explanation: <br>
<br>
Matplotlib Formatting II: gridlines
Sections

Generating-some-sample-data
Default grid
Vertical and horizontal grids
Vertical grid
Horizontal grid


Controlling the gridline style
Changing the tick frequency
Changing the tick color and linestyle



<br>
<br>
Generating some sample data
[back to top]
End of explanation
"""


plt.hist(data, bins=bins, alpha=0.5)
plt.grid()

plt.show()

"""
Explanation: <br>
<br>
Default grid
[back to top]
End of explanation
"""


plt.hist(data, bins=bins, alpha=0.5)
ax = plt.gca()
ax.grid(True)

plt.show()

"""
Explanation: Or alternatively:
End of explanation
"""


plt.hist(data, bins=bins, alpha=0.5)
ax = plt.gca()
ax.xaxis.grid(True)

plt.show()

"""
Explanation: <br>
<br>
Vertical and horizontal grids
[back to top]
Vertical grid
[back to top]
End of explanation
"""


plt.hist(data, bins=bins, alpha=0.5)
ax = plt.gca()
ax.yaxis.grid(True)

plt.show()

"""
Explanation: Horizontal grid
[back to top]
End of explanation
"""


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()

"""
Explanation: <br>
<br>
Controlling the gridline style
[back to top]
Changing the tick frequency
[back to top]
End of explanation
"""


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()

"""
Explanation: Changing the tick color and linestyle
[back to top]
End of explanation
"""


