Permalink
Browse files

Add spines back to axes factory function. Change num_s_ticks to max_s…

…ticks.
  • Loading branch information...
Leif Johnson
Leif Johnson committed Jan 29, 2014
1 parent bd0b633 commit 6d2002cbe0fbbc63dc0eff44bf4906b92f0cb53a
Showing with 21 additions and 14 deletions.
  1. +19 −12 lmj/plot.py
  2. +2 −2 scripts/lmj-plot
View
@@ -7,6 +7,7 @@
clf = plt.clf
gcf = plt.gcf
plot = plt.plot
+legend = plt.legend
savefig = plt.savefig
scatter = plt.scatter
show = plt.show
@@ -30,7 +31,7 @@
matplotlib.rcParams['axes.color_cycle'] = ', '.join(COLOR11)
-def axes(subplot=111, shape=None, log='', num_x_ticks=None, num_y_ticks=None, **kwargs):
+def axes(subplot=111, shape=None, log='', max_xticks=5, max_yticks=4, spines=None, **kwargs):
'''Create an axes object to hold a plot.
Arguments
@@ -43,10 +44,12 @@ def axes(subplot=111, shape=None, log='', num_x_ticks=None, num_y_ticks=None, **
log : str
A string, containing 'x' and/or 'y', indicating the axes that should
have log scales.
- num_x_ticks : int
- The number of ticks to position on the x-axis, if any.
- num_y_ticks : int
- The number of ticks to position on the y-axis, if any.
+ max_xticks : int, optional
+ The maximum number of ticks to position on the x-axis, if any.
+ max_yticks : int, optional
+ The maximum number of ticks to position on the y-axis, if any.
+ spines : optional
+ If given, this argument will be passed to `set_spines`.
Remaining keyword arguments will be passed to `axes()` (if `shape` is not
None) or `subplot()` (otherwise).
@@ -70,10 +73,13 @@ def axes(subplot=111, shape=None, log='', num_x_ticks=None, num_y_ticks=None, **
if 'y' in log:
ax.set_yscale('log')
- if num_x_ticks:
- plt.locator_params(axis='x', nbins=num_x_ticks)
- if num_y_ticks:
- plt.locator_params(axis='y', nbins=num_y_ticks)
+ if max_xticks > 0:
+ plt.locator_params(axis='x', nbins=max_xticks - 1)
+ if max_yticks > 0:
+ plt.locator_params(axis='y', nbins=max_yticks - 1)
+
+ if spines is not None:
+ set_spines(ax, spines)
return ax
@@ -111,11 +117,12 @@ def set_spines(ax, spines=True, offset=6):
'''
if spines is True:
spines = 'bottom left'
- elif isinstance(spines, (int, float, long)):
+ if spines is False:
+ spines = ''
+
+ if isinstance(spines, (int, float, long)):
offset = spines
spines = 'top right bottom left'
- elif not spines:
- spines = {}
if isinstance(spines, str):
spines = spines.split()
View
@@ -321,8 +321,8 @@ def set_limits(limits, x, y):
def main(args):
ax = lmj.plot.axes(log=args.log,
- num_x_ticks=args.num_x_ticks,
- num_y_ticks=args.num_y_ticks)
+ max_xticks=args.num_x_ticks,
+ max_yticks=args.num_y_ticks)
lmj.plot.set_spines(ax)
colors = itertools.cycle(args.colors)

0 comments on commit 6d2002c

Please sign in to comment.