From f278a7c754933cd362e7e16018f706b039b4c533 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Mon, 28 May 2012 16:17:07 +0100 Subject: [PATCH] Whitespace fixes. --- lib/matplotlib/axis.py | 49 ++++-------- lib/matplotlib/backend_bases.py | 22 ++---- lib/matplotlib/ticker.py | 127 +++++++++++++++++--------------- 3 files changed, 88 insertions(+), 110 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 43db8b9b7f9f..ac1da7056f71 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -17,8 +17,10 @@ import matplotlib.units as munits import numpy as np + GRIDLINE_INTERPOLATION_STEPS = 180 + class Tick(artist.Artist): """ Abstract base class for the axis ticks, grid lines and labels @@ -159,7 +161,6 @@ def apply_tickdir(self, tickdir): """ pass - def get_children(self): children = [self.tick1line, self.tick2line, self.gridline, self.label1, self.label2] return children @@ -216,7 +217,6 @@ def _get_gridline(self): 'Get the default grid Line2d instance for this tick' pass - def get_loc(self): 'Return the tick location (data coords) as a scalar' return self._loc @@ -308,7 +308,6 @@ def _apply_params(self, **kw): setattr(self, '_'+k, v) - class XTick(Tick): """ Contains all the Artists needed to make an x tick - the tick line, @@ -358,7 +357,6 @@ def _get_text1(self): def _get_text2(self): - 'Get the default Text 2 instance' # x in data coords, y in axes coords #t = mtext.Text( @@ -479,7 +477,6 @@ def apply_tickdir(self, tickdir): self._tickmarkers = (mlines.TICKLEFT, mlines.TICKRIGHT) self._pad = self._base_pad + self._size - # how far from the y axis line the right of the ticklabel are def _get_text1(self): 'Get the default Text instance' @@ -557,7 +554,6 @@ def _get_gridline(self): self._set_artist_props(l) return l - def update_position(self, loc): 'Set the location of tick in data coords with scalar loc' y = loc @@ -584,7 +580,6 @@ def update_position(self, loc): self._loc = loc - def get_view_interval(self): 'return the Interval instance for this axis view limits' return self.axes.viewLim.intervaly @@ -595,9 +590,7 @@ class Ticker: formatter = None - class Axis(artist.Artist): - """ Public attributes @@ -632,12 +625,6 @@ def __init__(self, axes, pickradius=15): self.minor = Ticker() self.callbacks = cbook.CallbackRegistry() - #class dummy: - # locator = None - # formatter = None - #self.major = dummy() - #self.minor = dummy() - self._autolabelpos = True self._smart_bounds = False @@ -655,7 +642,6 @@ def __init__(self, axes, pickradius=15): self.cla() self.set_scale('linear') - def set_label_coords(self, x, y, transform=None): """ Set the coordinates of the label. By default, the x @@ -706,7 +692,7 @@ def get_children(self): return children def cla(self): - 'clear the current axis' + """Clear the current axis""" self.set_major_locator(mticker.AutoLocator()) self.set_major_formatter(mticker.ScalarFormatter()) self.set_minor_locator(mticker.NullLocator()) @@ -773,10 +759,10 @@ def set_tick_params(self, which='major', reset=False, **kw): self.reset_ticks() else: if which == 'major' or which == 'both': - for tick in self.majorTicks: + for tick in self.majorTicks: tick._apply_params(**self._major_tick_kw) if which == 'minor' or which == 'both': - for tick in self.minorTicks: + for tick in self.minorTicks: tick._apply_params(**self._minor_tick_kw) @staticmethod @@ -1018,7 +1004,6 @@ def get_tightbbox(self, renderer): self._update_offset_text_position(ticklabelBoxes, ticklabelBoxes2) self.offsetText.set_text( self.major.formatter.get_offset() ) - bb = [] for a in [self.label, self.offsetText]: @@ -1036,10 +1021,9 @@ def get_tightbbox(self, renderer): else: return None - @allow_rasterization def draw(self, renderer, *args, **kwargs): - 'Draw the axis lines, grid lines, tick lines and labels' + """Draw the axis lines, grid lines, tick lines and labels""" if not self.get_visible(): return renderer.open_group(__name__) @@ -1063,10 +1047,10 @@ def draw(self, renderer, *args, **kwargs): self.offsetText.set_text( self.major.formatter.get_offset() ) self.offsetText.draw(renderer) - if 0: # draw the bounding boxes around the text for debug - for tick in majorTicks: + if False: # draw the bounding boxes around the text for debug + for tick in ticks_to_draw: label = tick.label1 - mpatches.bbox_artist(label, renderer) + mpatches.bbox_artist(label, renderer, fill=False) mpatches.bbox_artist(self.label, renderer) renderer.close_group(__name__) @@ -1213,7 +1197,6 @@ def get_major_ticks(self, numticks=None): return ticks - def get_minor_ticks(self, numticks=None): 'get the minor tick instances; grow as necessary' if numticks is None: @@ -1237,7 +1220,6 @@ def get_minor_ticks(self, numticks=None): return ticks - def grid(self, b=None, which='major', **kwargs): """ Set the axis grid on or off; b is a boolean. Use *which* = @@ -1343,7 +1325,7 @@ def convert_units(self, x): def set_units(self, u): """ - set the units for axis + Set the units for axis ACCEPTS: a units tag """ @@ -1366,7 +1348,8 @@ def get_units(self): return self.units def set_label_text(self, label, fontdict = None, **kwargs): - """ Sets the text value of the axis label + """ + Sets the text value of the axis label ACCEPTS: A string value for the label """ @@ -1386,7 +1369,6 @@ def set_major_formatter(self, formatter): self.major.formatter = formatter formatter.set_axis(self) - def set_minor_formatter(self, formatter): """ Set the formatter of the minor ticker @@ -1408,7 +1390,6 @@ def set_major_locator(self, locator): self.major.locator = locator locator.set_axis(self) - def set_minor_locator(self, locator): """ Set the locator of the minor ticker @@ -1427,7 +1408,6 @@ def set_pickradius(self, pickradius): """ self.pickradius = pickradius - def set_ticklabels(self, ticklabels, *args, **kwargs): """ Set the text values of the tick labels. Return a list of Text @@ -1511,7 +1491,6 @@ def zoom(self, direction): "Zoom in/out on axis; if *direction* is >0 zoom in, else zoom out" self.major.locator.zoom(direction) - def axis_date(self, tz=None): """ Sets up x-axis ticks and labels that treat the x data as dates. @@ -1526,7 +1505,7 @@ def axis_date(self, tz=None): if isinstance(tz, (str, unicode)): import pytz tz = pytz.timezone(tz) - self.update_units(datetime.datetime(2009,1,1,0,0,0,0,tz)) + self.update_units(datetime.datetime(2009, 1, 1, 0, 0, 0, 0, tz)) class XAxis(Axis): @@ -1786,7 +1765,6 @@ def set_default_intervals(self): self.axes.viewLim.intervalx = xmin, xmax - class YAxis(Axis): __name__ = 'yaxis' axis_name = 'y' @@ -1818,7 +1796,6 @@ def _get_tick(self, major): tick_kw = self._minor_tick_kw return YTick(self.axes, 0, '', major=major, **tick_kw) - def _get_label(self): # x in display coords (updated by _update_label_position) # y in axes coords diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index b31dfab9fef9..0aa8ff337623 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -111,7 +111,6 @@ def mainloop(self): pass - class RendererBase: """An abstract base class to handle drawing/rendering operations. @@ -518,7 +517,6 @@ def _get_text_path_transform(self, x, y, s, prop, angle, ismath): return path, transform - def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath): """ draw the text by converting them to paths using textpath module. @@ -542,7 +540,6 @@ def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath): gc.set_linewidth(0.0) self.draw_path(gc, path, transform, rgbFace=color) - def get_text_width_height_descent(self, s, prop, ismath): """ get the width and height, and the offset from the bottom to the @@ -1132,6 +1129,7 @@ def __init__(self, name, canvas,guiEvent=None): self.canvas = canvas self.guiEvent = guiEvent + class IdleEvent(Event): """ An event triggered by the GUI backend when it is idle -- useful @@ -1139,6 +1137,7 @@ class IdleEvent(Event): """ pass + class DrawEvent(Event): """ An event triggered by a draw operation on the canvas @@ -1153,6 +1152,7 @@ def __init__(self, name, canvas, renderer): Event.__init__(self, name, canvas) self.renderer = renderer + class ResizeEvent(Event): """ An event triggered by a canvas resize @@ -1170,6 +1170,7 @@ def __init__(self, name, canvas): Event.__init__(self, name, canvas) self.width, self.height = canvas.get_width_height() + class CloseEvent(Event): """ An event triggered by a figure being closed @@ -1179,6 +1180,7 @@ class CloseEvent(Event): def __init__(self, name, canvas, guiEvent=None): Event.__init__(self, name, canvas, guiEvent) + class LocationEvent(Event): """ An event that has a screen location @@ -1222,8 +1224,6 @@ def __init__(self, name, canvas, x, y,guiEvent=None): self.x = x self.y = y - - if x is None or y is None: # cannot check if event was in axes if no x,y info self.inaxes = None @@ -1284,9 +1284,6 @@ def _update_enter_leave(self): LocationEvent.lastevent = self - - - class MouseEvent(LocationEvent): """ A mouse event ('button_press_event', 'button_release_event', 'scroll_event', @@ -1338,6 +1335,7 @@ def __str__(self): return "MPL MouseEvent: xy=(%d,%d) xydata=(%s,%s) button=%d dblclick=%s inaxes=%s"%\ (self.x,self.y,str(self.xdata),str(self.ydata),self.button,self.dblclick,self.inaxes) + class PickEvent(Event): """ a pick event, fired when the user picks a location on the canvas @@ -1408,7 +1406,6 @@ def __init__(self, name, canvas, key, x=0, y=0, guiEvent=None): self.key = key - class FigureCanvasBase(object): """ The canvas the figure renders into. @@ -1437,7 +1434,6 @@ class FigureCanvasBase(object): 'close_event' ] - def __init__(self, figure): figure.set_canvas(self) self.figure = figure @@ -1633,7 +1629,6 @@ def scroll_event(self, x, y, step, guiEvent=None): step=step, guiEvent=guiEvent) self.callbacks.process(s, mouseevent) - def button_press_event(self, x, y, button, dblclick=False, guiEvent=None): """ Backend derived classes should call this function on any mouse @@ -1895,7 +1890,6 @@ def get_supported_filetypes_grouped(self): groupings[name].sort() return groupings - def _get_print_method(self, format): method_name = 'print_%s' % format @@ -1921,7 +1915,6 @@ def _print_method(*args, **kwargs): return getattr(self, method_name) - def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w', orientation='portrait', format=None, **kwargs): """ @@ -2063,9 +2056,6 @@ def print_figure(self, filename, dpi=None, facecolor='w', edgecolor='w', #self.figure.canvas.draw() ## seems superfluous return result - - - def get_default_filetype(self): raise NotImplementedError diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 72f9d3b0067c..ce766529186f 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -188,7 +188,7 @@ def format_data(self,value): return self.__call__(value) def format_data_short(self,value): - 'return a short string version' + """return a short string version""" return self.format_data(value) def get_offset(self): @@ -214,9 +214,10 @@ def fix_minus(self, s): """ return s + class IndexFormatter(Formatter): """ - format the position x to the nearest i-th label where i=int(x+0.5) + Format the position x to the nearest i-th label where i=int(x+0.5) """ def __init__(self, labels): self.labels = labels @@ -234,13 +235,14 @@ def __call__(self, x, pos=None): class NullFormatter(Formatter): - 'Always return the empty string' + """Always return the empty string""" def __call__(self, x, pos=None): - 'Return the format for tick val *x* at position *pos*' + """Return the format for tick val *x* at position *pos*""" return '' + class FixedFormatter(Formatter): - 'Return fixed strings for tick labels' + """Return fixed strings for tick labels""" def __init__(self, seq): """ *seq* is a sequence of strings. For positions ``i < len(seq)`` return @@ -250,7 +252,7 @@ def __init__(self, seq): self.offset_string = '' def __call__(self, x, pos=None): - 'Return the format for tick val *x* at position *pos*' + """Return the format for tick val *x* at position *pos*""" if pos is None or pos>=len(self.seq): return '' else: return self.seq[pos] @@ -260,6 +262,7 @@ def get_offset(self): def set_offset_string(self, ofs): self.offset_string = ofs + class FuncFormatter(Formatter): """ User defined function for formatting @@ -268,7 +271,7 @@ def __init__(self, func): self.func = func def __call__(self, x, pos=None): - 'Return the format for tick val *x* at position *pos*' + """Return the format for tick val *x* at position *pos*""" return self.func(x, pos) @@ -280,16 +283,17 @@ def __init__(self, fmt): self.fmt = fmt def __call__(self, x, pos=None): - 'Return the format for tick val *x* at position *pos*' + """Return the format for tick val *x* at position *pos*""" return self.fmt % x + class OldScalarFormatter(Formatter): """ Tick location is a plain old number. """ def __call__(self, x, pos=None): - 'Return the format for tick val *x* at position *pos*' + """Return the format for tick val *x* at position *pos*""" xmin, xmax = self.axis.get_view_interval() d = abs(xmax - xmin) @@ -371,12 +375,12 @@ def set_useLocale(self, val): useLocale = property(fget=get_useLocale, fset=set_useLocale) def fix_minus(self, s): - 'use a unicode minus rather than hyphen' + """Use a unicode minus rather than hyphen""" if rcParams['text.usetex'] or not rcParams['axes.unicode_minus']: return s else: return s.replace('-', u'\u2212') def __call__(self, x, pos=None): - 'Return the format for tick val *x* at position *pos*' + """Return the format for tick val *x* at position *pos*""" if len(self.locs)==0: return '' else: @@ -384,32 +388,32 @@ def __call__(self, x, pos=None): return self.fix_minus(s) def set_scientific(self, b): - '''True or False to turn scientific notation on or off + """True or False to turn scientific notation on or off see also :meth:`set_powerlimits` - ''' + """ self._scientific = bool(b) def set_powerlimits(self, lims): - ''' + """ Sets size thresholds for scientific notation. e.g. ``formatter.set_powerlimits((-3, 4))`` sets the pre-2007 default in which scientific notation is used for numbers less than 1e-3 or greater than 1e4. See also :meth:`set_scientific`. - ''' + """ assert len(lims) == 2, "argument must be a sequence of length 2" self._powerlimits = lims def format_data_short(self,value): - 'return a short formatted string representation of a number' + """Return a short formatted string representation of a number""" if self._useLocale: return locale.format_string('%-12g', (value,)) else: return '%-12g'%value def format_data(self,value): - 'return a formatted string representation of a number' + """Return a formatted string representation of a number""" if self._useLocale: s = locale.format_string('%1.10e', (value,)) else: @@ -417,7 +421,6 @@ def format_data(self,value): s = self._formatSciNotation(s) return self.fix_minus(s) - def get_offset(self): """Return scientific notation, plus offset""" if len(self.locs)==0: return '' @@ -476,7 +479,7 @@ def _set_offset(self, range): self.offset = math.floor(np.min(locs)/10**(range_oom))*10**(range_oom) else: self.offset = 0 - def _set_orderOfMagnitude(self,range): + def _set_orderOfMagnitude(self, range): # if scientific notation is to be used, find the appropriate exponent # if using an numerical offset, find the exponent after applying the offset if not self._scientific: @@ -537,7 +540,7 @@ def _formatSciNotation(self, s): # transform 1e+004 into 1e4, for example if self._useLocale: decimal_point = locale.localeconv()['decimal_point'] - positive = locale.localeconv()['positive_sign'] + positive_sign = locale.localeconv()['positive_sign'] else: decimal_point = '.' positive_sign = '+' @@ -580,16 +583,21 @@ def __init__(self, base=10.0, labelOnlyBase = True): self.decadeOnly = True def base(self, base): - 'change the *base* for labeling - warning: should always match the base used for :class:`LogLocator`' + """ + Change the *base* for labelling + + .. warning:: should always match the base used for :class:`LogLocator` + + """ self._base = base def label_minor(self, labelOnlyBase): - 'switch on/off minor ticks labeling' + """switch on/off minor ticks labeling""" self.labelOnlyBase = labelOnlyBase def __call__(self, x, pos=None): - 'Return the format for tick val *x* at position *pos*' + """Return the format for tick val *x* at position *pos*""" vmin, vmax = self.axis.get_view_interval() d = abs(vmax - vmin) b = self._base @@ -616,7 +624,7 @@ def format_data(self, value): return value def format_data_short(self,value): - 'return a short formatted string representation of a number' + """Return a short formatted string representation of a number""" return '%-12g'%value def pprint_val(self, x, d): @@ -642,6 +650,7 @@ def pprint_val(self, x, d): s = s.rstrip('0').rstrip('.') return s + class LogFormatterExponent(LogFormatter): """ Format values for log axis; using ``exponent = log_base(value)`` @@ -714,6 +723,7 @@ def __call__(self, x, pos=None): return s + class EngFormatter(Formatter): """ Formats axis values using engineering prefixes to represent powers of 1000, @@ -800,6 +810,7 @@ def format_eng(self, num): return formatted.strip() + class Locator(TickHelper): """ Determine the tick locations; @@ -817,14 +828,17 @@ class Locator(TickHelper): # many ticks are generated MAXTICKS = 1000 def __call__(self): - 'Return the locations of the ticks' + """Return the locations of the ticks""" raise NotImplementedError('Derived must override') def raise_if_exceeds(self, locs): - 'raise a RuntimeError if Locator attempts to create more than MAXTICKS locs' + """ + Raise a RuntimeError if Locator attempts to create > MAXTICKS locs + """ if len(locs)>=self.MAXTICKS: - raise RuntimeError('Locator attempting to generate %d ticks from %s to %s: exceeds Locator.MAXTICKS'%(len(locs), locs[0], locs[-1])) - + err_str = ('Locator attempting to generate %d ticks from ' + + '%s to %s: exceeds Locator.MAXTICKS') + raise RuntimeError(err_str % (len(locs), locs[0], locs[-1])) return locs def view_limits(self, vmin, vmax): @@ -836,11 +850,11 @@ def view_limits(self, vmin, vmax): return mtransforms.nonsingular(vmin, vmax) def autoscale(self): - 'autoscale the view limits' + """Autoscale the view limits""" return self.view_limits(*self.axis.get_view_interval()) def pan(self, numsteps): - 'Pan numticks (can be positive or negative)' + """Pan numticks (can be positive or negative)""" ticks = self() numticks = len(ticks) @@ -856,9 +870,8 @@ def pan(self, numsteps): vmax += step self.axis.set_view_interval(vmin, vmax, ignore=True) - def zoom(self, direction): - "Zoom in/out on axis; if direction is >0 zoom in, else zoom out" + """Zoom in/out on axis; if direction is >0 zoom in, else zoom out""" vmin, vmax = self.axis.get_view_interval() vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05) @@ -867,7 +880,7 @@ def zoom(self, direction): self.axis.set_view_interval(vmin + step, vmax - step, ignore=True) def refresh(self): - 'refresh internal information based on current lim' + """Refresh internal information based on current lim""" pass @@ -879,12 +892,12 @@ class IndexLocator(Locator): useful for x ticks. """ def __init__(self, base, offset): - 'place ticks on the i-th data points where (i-offset)%base==0' + """Place ticks on the i-th data points where (i-offset) % base == 0""" self._base = base self.offset = offset def __call__(self): - 'Return the locations of the ticks' + """Return the locations of the ticks""" dmin, dmax = self.axis.get_data_interval() return self.raise_if_exceeds( np.arange(dmin + self.offset, dmax+1, self._base)) @@ -908,7 +921,7 @@ def __init__(self, locs, nbins=None): self.nbins = max(self.nbins, 2) def __call__(self): - 'Return the locations of the ticks' + """Return the locations of the ticks""" if self.nbins is None: return self.locs step = max(int(0.99 + len(self.locs) / float(self.nbins)), 1) @@ -920,17 +933,16 @@ def __call__(self): return self.raise_if_exceeds(ticks) - - class NullLocator(Locator): """ No ticks """ def __call__(self): - 'Return the locations of the ticks' + """Return the locations of the ticks""" return [] + class LinearLocator(Locator): """ Determine the tick locations @@ -953,7 +965,7 @@ def __init__(self, numticks = None, presets=None): self.presets = presets def __call__(self): - 'Return the locations of the ticks' + """Return the locations of the ticks""" vmin, vmax = self.axis.get_view_interval() vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander = 0.05) @@ -978,7 +990,7 @@ def _set_numticks(self): self.numticks = 11 # todo; be smart here; this is just for dev def view_limits(self, vmin, vmax): - 'Try to choose the view limits intelligently' + """Try to choose the view limits intelligently""" if vmax0) self._base = base def lt(self, x): - 'return the largest multiple of base < x' + """Return the largest multiple of base < x""" d,m = divmod(x, self._base) if closeto(m,0) and not closeto(m/self._base,1): return (d-1)*self._base return d*self._base def le(self, x): - 'return the largest multiple of base <= x' + """Return the largest multiple of base <= x""" d,m = divmod(x, self._base) if closeto(m/self._base,1): # was closeto(m, self._base) #looks like floating point error @@ -1024,7 +1036,7 @@ def le(self, x): return d*self._base def gt(self, x): - 'return the smallest multiple of base > x' + """Return the smallest multiple of base > x""" d,m = divmod(x, self._base) if closeto(m/self._base,1): #looks like floating point error @@ -1032,7 +1044,7 @@ def gt(self, x): return (d+1)*self._base def ge(self, x): - 'return the smallest multiple of base >= x' + """Return the smallest multiple of base >= x""" d,m = divmod(x, self._base) if closeto(m,0) and not closeto(m/self._base,1): return d*self._base @@ -1074,6 +1086,7 @@ def view_limits(self, dmin, dmax): return mtransforms.nonsingular(vmin, vmax) + def scale_range(vmin, vmax, n = 1, threshold=100): dv = abs(vmax - vmin) maxabsv = max(abs(vmin), abs(vmax)) @@ -1093,7 +1106,6 @@ def scale_range(vmin, vmax, n = 1, threshold=100): return scale, offset - class MaxNLocator(Locator): """ Select no more than N intervals at nice locations. @@ -1223,14 +1235,14 @@ def view_limits(self, dmin, dmax): def decade_down(x, base=10): - 'floor x to the nearest lower decade' + """floor x to the nearest lower decade""" if x == 0.0: return -base lx = np.floor(np.log(x)/np.log(base)) return base**lx def decade_up(x, base=10): - 'ceil x to the nearest higher decade' + """ceil x to the nearest higher decade""" if x == 0.0: return base lx = np.ceil(np.log(x)/np.log(base)) @@ -1284,7 +1296,7 @@ def subs(self,subs): self._subs = np.asarray(subs)+0.0 def __call__(self): - 'Return the locations of the ticks' + """Return the locations of the ticks""" b=self._base vmin, vmax = self.axis.get_view_interval() @@ -1339,7 +1351,7 @@ def __call__(self): return self.raise_if_exceeds(np.asarray(ticklocs)) def view_limits(self, vmin, vmax): - 'Try to choose the view limits intelligently' + """Try to choose the view limits intelligently""" b = self._base if vmax