%matplotlib inline
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
matplotlib.__version__
'1.4.3'
matplotlib
<module 'matplotlib' from '/nuwa_cluster/home/jackyu/locally_installed_python_pacakges/anaconda3/lib/python3.4/site-packages/matplotlib/__init__.py'>
# Say there are the following 1d arrays
x = np.array([ 3.12199990e-04, 2.90415010e-03, 1.57711500e-02,
8.56452990e-02, 4.65100010e-01, 2.52570000e+00,
1.37158500e+01, 7.38875010e+01, 1.92762500e+02,
3.11637500e+02, 4.30512500e+02, 5.49387510e+02,
6.68262510e+02, 7.87137510e+02, 9.06012510e+02])
y = np.array([ -2.43725140e-05, -2.54052210e-05, -2.66895420e-05,
-3.07354470e-05, -9.19818190e-06, 9.97550570e-06,
-1.53637560e-04, -8.40315400e-04, -1.99370040e-03,
-2.19048730e-03, -1.26747160e-03, 6.09407900e-04,
3.31778190e-03, 6.78078280e-03, 1.02557620e-02])
# Plot y against x
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(5, 5))
ax.plot(x, y, 'x')
[<matplotlib.lines.Line2D at 0x2aab4fa252b0>]
# Say I wanted to zoom in on the y values for the first x values
# but keeping the x-axis the same as before
ax.set_ylim(bottom=y[range(10)].min(), top=y[range(10)].max())
fig
# Now create some margin at the top and bottom so the markers are
# not partially obstructed by the top and bottom frames
ax.set_ylim(bottom=y[range(10)].min(), top=y[range(10)].max())
ax.margins(x=.2, y=.2)
fig
# it appears that ax.margins only now works for the x-axis
# and not the y-axis