yaxis
Peter Pearson
pkpearson at nowhere.invalid
Tue Dec 29 13:44:36 EST 2015
On Tue, 29 Dec 2015 06:25:49 -0800 (PST), damien.ishacian at gmail.com wrote:
> hello I would only change the scale of the y-axis, how to deal with
> matplotlib.pyplot or another library ?
Here's a function I use. ax is an "axes" object, which you can get
by calling the get-current-axes (gca()) method of some plot object,
for example
from matplotlib import pyplot as plt
<plot a bunch of stuff>
expand_limits(plt.gca(), 0.08)
plt.show()
Anyway, here's the function:
def expand_limits(ax, factor):
"""Expand the limits on a plotting area by the specified factor.
"""
def expand(xmin, xmax):
d = xmax - xmin
return xmin - 0.5*factor*d, xmax + 0.5*factor*d
ax.set_xlim(*expand(*ax.get_xlim()))
ax.set_ylim(*expand(*ax.get_ylim()))
--
To email me, substitute nowhere->runbox, invalid->com.
More information about the Python-list
mailing list