Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

PEP8 fixes on the line module #1577

Merged
merged 5 commits into from

3 participants

@NelleV
Collaborator

Here is a pep8 fix on the lines module.

Cheers,
N

@NelleV
Collaborator

@dmcdougall Maybe you can have a look at this PR?

@dmcdougall
Collaborator

This is one PR where travis has been extremely unhelpful. All of those failures look like duds to me. I'll look through this and try and provide feedback for you. I'll also trigger a travis rebuild for you and hopefully that can illuminate any possible corner cases.

lib/matplotlib/lines.py
((7 lines not shown))
# Convert points to pixels
- path, affine = self._get_transformed_path().get_transformed_path_and_affine()
+ path, affine = \
@dmcdougall Collaborator

Is there a way to do this without the trailing backslash? Maybe with a temporary variable?

@NelleV Collaborator
NelleV added a note

This is the way it is done elsewhere (for 80char). I can add a temporary variable but I'm not sure it is worth it.

@dmcdougall Collaborator

I thought we were getting rid of trailing backslashes. See, for example, this PR.

@NelleV Collaborator
NelleV added a note

I was thinking of PR I reviewed that weren't specifically pep8 patches: I don't mind either of them. I think if I was coding (and not just pep8-ising the code) I would avoid having backslashes such as this one, but I've also introduced bugs when pep8-ising code and adding temporary variables.

@efiring Owner
efiring added a note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/matplotlib/lines.py
@@ -542,7 +561,8 @@ def draw(self, renderer):
gc.set_linewidth(self._markeredgewidth)
gc.set_alpha(self._alpha)
marker = self._marker
- tpath, affine = transformed_path.get_transformed_points_and_affine()
+ tpath, affine = \
@dmcdougall Collaborator

'Nother trailer here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dmcdougall dmcdougall commented on the diff
lib/matplotlib/lines.py
((16 lines not shown))
from matplotlib.markers import MarkerStyle
# Imported here for backward compatibility, even though they don't
# really belong.
-from matplotlib.markers import TICKLEFT, TICKRIGHT, TICKUP, TICKDOWN, \
- CARETLEFT, CARETRIGHT, CARETUP, CARETDOWN
@dmcdougall Collaborator

This is causing problems with the fancy_arrow test:

File "/home/travis/virtualenv/python2.6/lib/python2.6/site-packages/matplotlib/axis.py", line 332, in apply_tickdir
self._tickmarkers = (mlines.TICKUP, mlines.TICKDOWN)
AttributeError: 'module' object has no attribute 'TICKUP'

Maybe add these back in and add a comment? These (or the tests) should probably be refactored.

@dmcdougall Collaborator

RE Refactoring: That should not hold up this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@NelleV
Collaborator

I've replaced the trailing backslash with a temporary variable.

lib/matplotlib/lines.py
@@ -545,7 +566,8 @@ def draw(self, renderer):
gc.set_linewidth(self._markeredgewidth)
marker = self._marker
- tpath, affine = transformed_path.get_transformed_points_and_affine()
+ tpath, affine = \
@dmcdougall Collaborator

PEP8: There's another trailing backslash here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@NelleV
Collaborator

I think this is ready to be merged. I can rebase if necessary.

@dmcdougall dmcdougall merged commit 293293f into matplotlib:master
@NelleV NelleV deleted the NelleV:pep8_lines branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 187 additions and 175 deletions.
  1. +187 −175 lib/matplotlib/lines.py
View
362 lib/matplotlib/lines.py
@@ -13,21 +13,20 @@
from matplotlib import verbose
import artist
from artist import Artist
-from cbook import iterable, is_string_like, is_numlike, ls_mapper, dedent,\
-flatten, is_math_text
+from cbook import iterable, is_string_like, is_numlike, ls_mapper
from colors import colorConverter
from path import Path
-from transforms import Affine2D, Bbox, TransformedPath, IdentityTransform
+from transforms import Bbox, TransformedPath, IdentityTransform
from matplotlib import rcParams
from artist import allow_rasterization
from matplotlib import docstring
-from matplotlib.font_manager import FontProperties
from matplotlib.markers import MarkerStyle
# Imported here for backward compatibility, even though they don't
# really belong.
-from matplotlib.markers import TICKLEFT, TICKRIGHT, TICKUP, TICKDOWN, \
- CARETLEFT, CARETRIGHT, CARETUP, CARETDOWN
@dmcdougall Collaborator

This is causing problems with the fancy_arrow test:

File "/home/travis/virtualenv/python2.6/lib/python2.6/site-packages/matplotlib/axis.py", line 332, in apply_tickdir
self._tickmarkers = (mlines.TICKUP, mlines.TICKDOWN)
AttributeError: 'module' object has no attribute 'TICKUP'

Maybe add these back in and add a comment? These (or the tests) should probably be refactored.

@dmcdougall Collaborator

RE Refactoring: That should not hold up this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+from matplotlib.markers import TICKLEFT, TICKRIGHT, TICKUP, TICKDOWN
+from matplotlib.markers import CARETLEFT, CARETRIGHT, CARETUP, CARETDOWN
+
def segment_hits(cx, cy, x, y, radius):
"""
@@ -37,38 +36,39 @@ def segment_hits(cx, cy, x, y, radius):
"""
# Process single points specially
if len(x) < 2:
- res, = np.nonzero( (cx - x)**2 + (cy - y)**2 <= radius**2 )
+ res, = np.nonzero((cx - x) ** 2 + (cy - y) ** 2 <= radius ** 2)
return res
# We need to lop the last element off a lot.
- xr,yr = x[:-1],y[:-1]
+ xr, yr = x[:-1], y[:-1]
# Only look at line segments whose nearest point to C on the line
# lies within the segment.
- dx,dy = x[1:]-xr, y[1:]-yr
- Lnorm_sq = dx**2+dy**2 # Possibly want to eliminate Lnorm==0
- u = ( (cx-xr)*dx + (cy-yr)*dy )/Lnorm_sq
- candidates = (u>=0) & (u<=1)
+ dx, dy = x[1:] - xr, y[1:] - yr
+ Lnorm_sq = dx ** 2 + dy ** 2 # Possibly want to eliminate Lnorm==0
+ u = ((cx - xr) * dx + (cy - yr) * dy) / Lnorm_sq
+ candidates = (u >= 0) & (u <= 1)
#if any(candidates): print "candidates",xr[candidates]
# Note that there is a little area near one side of each point
# which will be near neither segment, and another which will
# be near both, depending on the angle of the lines. The
# following radius test eliminates these ambiguities.
- point_hits = (cx - x)**2 + (cy - y)**2 <= radius**2
+ point_hits = (cx - x) ** 2 + (cy - y) ** 2 <= radius ** 2
#if any(point_hits): print "points",xr[candidates]
candidates = candidates & ~(point_hits[:-1] | point_hits[1:])
# For those candidates which remain, determine how far they lie away
# from the line.
- px,py = xr+u*dx,yr+u*dy
- line_hits = (cx-px)**2 + (cy-py)**2 <= radius**2
+ px, py = xr + u * dx, yr + u * dy
+ line_hits = (cx - px) ** 2 + (cy - py) ** 2 <= radius ** 2
#if any(line_hits): print "lines",xr[candidates]
line_hits = line_hits & candidates
points, = point_hits.ravel().nonzero()
lines, = line_hits.ravel().nonzero()
#print points,lines
- return np.concatenate((points,lines))
+ return np.concatenate((points, lines))
+
class Line2D(Artist):
"""
@@ -79,26 +79,27 @@ class Line2D(Artist):
"""
- lineStyles = _lineStyles = { # hidden names deprecated
- '-' : '_draw_solid',
- '--' : '_draw_dashed',
- '-.' : '_draw_dash_dot',
- ':' : '_draw_dotted',
- 'None' : '_draw_nothing',
- ' ' : '_draw_nothing',
- '' : '_draw_nothing',
+ lineStyles = _lineStyles = { # hidden names deprecated
+ '-': '_draw_solid',
+ '--': '_draw_dashed',
+ '-.': '_draw_dash_dot',
+ ':': '_draw_dotted',
+ 'None': '_draw_nothing',
+ ' ': '_draw_nothing',
+ '': '_draw_nothing',
}
_drawStyles_l = {
- 'default' : '_draw_lines',
- 'steps-mid' : '_draw_steps_mid',
- 'steps-pre' : '_draw_steps_pre',
- 'steps-post' : '_draw_steps_post',
+ 'default': '_draw_lines',
+ 'steps-mid': '_draw_steps_mid',
+ 'steps-pre': '_draw_steps_pre',
+ 'steps-post': '_draw_steps_post',
}
_drawStyles_s = {
- 'steps' : '_draw_steps_pre',
+ 'steps': '_draw_steps_pre',
}
+
drawStyles = {}
drawStyles.update(_drawStyles_l)
drawStyles.update(_drawStyles_s)
@@ -113,39 +114,41 @@ class Line2D(Artist):
zorder = 2
validCap = ('butt', 'round', 'projecting')
- validJoin = ('miter', 'round', 'bevel')
+ validJoin = ('miter', 'round', 'bevel')
def __str__(self):
if self._label != "":
- return "Line2D(%s)"%(self._label)
+ return "Line2D(%s)" % (self._label)
elif hasattr(self, '_x') and len(self._x) > 3:
return "Line2D((%g,%g),(%g,%g),...,(%g,%g))"\
- %(self._x[0],self._y[0],self._x[0],self._y[0],self._x[-1],self._y[-1])
+ % (self._x[0], self._y[0], self._x[0],
+ self._y[0], self._x[-1], self._y[-1])
elif hasattr(self, '_x'):
return "Line2D(%s)"\
- %(",".join(["(%g,%g)"%(x,y) for x,y in zip(self._x,self._y)]))
+ % (",".join(["(%g,%g)" % (x, y) for x, y
+ in zip(self._x, self._y)]))
else:
return "Line2D()"
def __init__(self, xdata, ydata,
- linewidth = None, # all Nones default to rc
- linestyle = None,
- color = None,
- marker = None,
- markersize = None,
- markeredgewidth = None,
- markeredgecolor = None,
- markerfacecolor = None,
- markerfacecoloralt = 'none',
- fillstyle = 'full',
- antialiased = None,
- dash_capstyle = None,
- solid_capstyle = None,
- dash_joinstyle = None,
- solid_joinstyle = None,
- pickradius = 5,
- drawstyle = None,
- markevery = None,
+ linewidth=None, # all Nones default to rc
+ linestyle=None,
+ color=None,
+ marker=None,
+ markersize=None,
+ markeredgewidth=None,
+ markeredgecolor=None,
+ markerfacecolor=None,
+ markerfacecoloralt='none',
+ fillstyle='full',
+ antialiased=None,
+ dash_capstyle=None,
+ solid_capstyle=None,
+ dash_joinstyle=None,
+ solid_joinstyle=None,
+ pickradius=5,
+ drawstyle=None,
+ markevery=None,
**kwargs
):
"""
@@ -169,27 +172,37 @@ def __init__(self, xdata, ydata,
if not iterable(ydata):
raise RuntimeError('ydata must be a sequence')
- if linewidth is None : linewidth=rcParams['lines.linewidth']
-
- if linestyle is None : linestyle=rcParams['lines.linestyle']
- if marker is None : marker=rcParams['lines.marker']
- if color is None : color=rcParams['lines.color']
-
- if markersize is None : markersize=rcParams['lines.markersize']
- if antialiased is None : antialiased=rcParams['lines.antialiased']
- if dash_capstyle is None : dash_capstyle=rcParams['lines.dash_capstyle']
- if dash_joinstyle is None : dash_joinstyle=rcParams['lines.dash_joinstyle']
- if solid_capstyle is None : solid_capstyle=rcParams['lines.solid_capstyle']
- if solid_joinstyle is None : solid_joinstyle=rcParams['lines.solid_joinstyle']
-
- if drawstyle is None : drawstyle='default'
+ if linewidth is None:
+ linewidth = rcParams['lines.linewidth']
+
+ if linestyle is None:
+ linestyle = rcParams['lines.linestyle']
+ if marker is None:
+ marker = rcParams['lines.marker']
+ if color is None:
+ color = rcParams['lines.color']
+
+ if markersize is None:
+ markersize = rcParams['lines.markersize']
+ if antialiased is None:
+ antialiased = rcParams['lines.antialiased']
+ if dash_capstyle is None:
+ dash_capstyle = rcParams['lines.dash_capstyle']
+ if dash_joinstyle is None:
+ dash_joinstyle = rcParams['lines.dash_joinstyle']
+ if solid_capstyle is None:
+ solid_capstyle = rcParams['lines.solid_capstyle']
+ if solid_joinstyle is None:
+ solid_joinstyle = rcParams['lines.solid_joinstyle']
+
+ if drawstyle is None:
+ drawstyle = 'default'
self.set_dash_capstyle(dash_capstyle)
self.set_dash_joinstyle(dash_joinstyle)
self.set_solid_capstyle(solid_capstyle)
self.set_solid_joinstyle(solid_joinstyle)
-
self.set_linestyle(linestyle)
self.set_drawstyle(drawstyle)
self.set_linewidth(linewidth)
@@ -201,7 +214,6 @@ def __init__(self, xdata, ydata,
self.set_markersize(markersize)
self._dashSeq = None
-
self.set_markerfacecolor(markerfacecolor)
self.set_markerfacecoloralt(markerfacecoloralt)
self.set_markeredgecolor(markeredgecolor)
@@ -240,7 +252,7 @@ def contains(self, mouseevent):
TODO: sort returned indices by distance
"""
if callable(self._contains):
- return self._contains(self,mouseevent)
+ return self._contains(self, mouseevent)
if not is_numlike(self.pickradius):
raise ValueError("pick radius should be a distance")
@@ -248,10 +260,12 @@ def contains(self, mouseevent):
# Make sure we have data to plot
if self._invalidy or self._invalidx:
self.recache()
- if len(self._xy)==0: return False,{}
+ if len(self._xy) == 0:
+ return False, {}
# Convert points to pixels
- path, affine = self._get_transformed_path().get_transformed_path_and_affine()
+ transformed_path = self._get_transformed_path()
+ path, affine = transformed_path.get_transformed_path_and_affine()
path = affine.transform_path(path)
xy = path.vertices
xt = xy[:, 0]
@@ -262,22 +276,23 @@ def contains(self, mouseevent):
warnings.warn('no figure set when check if mouse is on line')
pixels = self.pickradius
else:
- pixels = self.figure.dpi/72. * self.pickradius
+ pixels = self.figure.dpi / 72. * self.pickradius
- # the math involved in checking for containment (here and inside of segment_hits) assumes
- # that it is OK to overflow. In case the application has set the error flags such that
- # an exception is raised on overflow, we temporarily set the appropriate error flags here
- # and set them back when we are finished.
+ # the math involved in checking for containment (here and inside of
+ # segment_hits) assumes that it is OK to overflow. In case the
+ # application has set the error flags such that an exception is raised
+ # on overflow, we temporarily set the appropriate error flags here and
+ # set them back when we are finished.
olderrflags = np.seterr(all='ignore')
try:
# Check for collision
- if self._linestyle in ['None',None]:
+ if self._linestyle in ['None', None]:
# If no line, return the nearby point(s)
- d = (xt-mouseevent.x)**2 + (yt-mouseevent.y)**2
- ind, = np.nonzero(np.less_equal(d, pixels**2))
+ d = (xt - mouseevent.x) ** 2 + (yt - mouseevent.y) ** 2
+ ind, = np.nonzero(np.less_equal(d, pixels ** 2))
else:
# If line, return the nearby segment(s)
- ind = segment_hits(mouseevent.x,mouseevent.y,xt,yt,pixels)
+ ind = segment_hits(mouseevent.x, mouseevent.y, xt, yt, pixels)
finally:
np.seterr(**olderrflags)
@@ -285,20 +300,21 @@ def contains(self, mouseevent):
# Debugging message
if False and self._label != '':
- print("Checking line",self._label,"at",mouseevent.x,mouseevent.y)
+ print("Checking line", self._label,
+ "at", mouseevent.x, mouseevent.y)
print('xt', xt)
print('yt', yt)
#print 'dx,dy', (xt-mouseevent.x)**2., (yt-mouseevent.y)**2.
- print('ind',ind)
+ print('ind', ind)
# Return the point(s) within radius
- return len(ind)>0,dict(ind=ind)
+ return len(ind) > 0, dict(ind=ind)
def get_pickradius(self):
- 'return the pick radius used for containment tests'
+ """return the pick radius used for containment tests"""
return self.pickradius
- def set_pickradius(self,d):
+ def set_pickradius(self, d):
"""Sets the pick radius used for containment tests
ACCEPTS: float distance in points
@@ -333,8 +349,8 @@ def set_markevery(self, every):
Every N-th marker will be plotted starting with marker 0
A length-2 tuple of integers
- every=(start, N) will start at point start and plot every N-th marker
-
+ every=(start, N) will start at point start and plot every N-th
+ marker
ACCEPTS: None | integer | (startind, stride)
@@ -342,10 +358,10 @@ def set_markevery(self, every):
self._markevery = every
def get_markevery(self):
- 'return the markevery setting'
+ """return the markevery setting"""
return self._markevery
- def set_picker(self,p):
+ def set_picker(self, p):
"""Sets the event picker details for the line.
ACCEPTS: float distance in points or callable pick function
@@ -359,8 +375,9 @@ def set_picker(self,p):
def get_window_extent(self, renderer):
bbox = Bbox.unit()
- bbox.update_from_data_xy(self.get_transform().transform(self.get_xydata()),
- ignore=True)
+ bbox.update_from_data_xy(
+ self.get_transform().transform(self.get_xydata()),
+ ignore=True)
# correct for marker size, if any
if self._marker:
ms = (self._markersize / 72.0 * self.figure.dpi) * 0.5
@@ -370,9 +387,11 @@ def get_window_extent(self, renderer):
def set_axes(self, ax):
Artist.set_axes(self, ax)
if ax.xaxis is not None:
- self._xcid = ax.xaxis.callbacks.connect('units', self.recache_always)
+ self._xcid = ax.xaxis.callbacks.connect('units',
+ self.recache_always)
if ax.yaxis is not None:
- self._ycid = ax.yaxis.callbacks.connect('units', self.recache_always)
+ self._ycid = ax.yaxis.callbacks.connect('units',
+ self.recache_always)
set_axes.__doc__ = Artist.set_axes.__doc__
def set_data(self, *args):
@@ -381,7 +400,7 @@ def set_data(self, *args):
ACCEPTS: 2D array (rows are x, y) or two 1D arrays
"""
- if len(args)==1:
+ if len(args) == 1:
x, y = args[0]
else:
x, y = args
@@ -412,9 +431,9 @@ def recache(self, always=False):
else:
y = self._y
- if len(x)==1 and len(y)>1:
+ if len(x) == 1 and len(y) > 1:
x = x * np.ones(y.shape, np.float_)
- if len(y)==1 and len(x)>1:
+ if len(y) == 1 and len(x) > 1:
y = y * np.ones(x.shape, np.float_)
if len(x) != len(y):
@@ -427,8 +446,8 @@ def recache(self, always=False):
self._xy = ma.concatenate((x, y), 1)
else:
self._xy = np.concatenate((x, y), 1)
- self._x = self._xy[:, 0] # just a view
- self._y = self._xy[:, 1] # just a view
+ self._x = self._xy[:, 0] # just a view
+ self._y = self._xy[:, 1] # just a view
self._subslice = False
if (self.axes and len(x) > 100 and self._is_sorted(x) and
@@ -453,7 +472,7 @@ def _transform_path(self, subslice=None):
"""
# Masked arrays are now handled by the Path class itself
if subslice is not None:
- _path = Path(self._xy[subslice,:])
+ _path = Path(self._xy[subslice, :])
else:
_path = self._path
self._transformed_path = TransformedPath(_path, self.get_transform())
@@ -478,14 +497,16 @@ def set_transform(self, t):
self._invalidy = True
def _is_sorted(self, x):
- "return true if x is sorted"
- if len(x)<2: return 1
- return np.alltrue(x[1:]-x[0:-1]>=0)
+ """return true if x is sorted"""
+ if len(x) < 2:
+ return 1
+ return np.alltrue(x[1:] - x[0:-1] >= 0)
@allow_rasterization
def draw(self, renderer):
"""draw the Line with `renderer` unless visiblity is False"""
- if not self.get_visible(): return
+ if not self.get_visible():
+ return
if self._invalidy or self._invalidx:
self.recache()
@@ -499,7 +520,7 @@ def draw(self, renderer):
self.ind_offset = subslice.start
self._transform_path(subslice)
- transformed_path = self._get_transformed_path()
+ transf_path = self._get_transformed_path()
renderer.open_group('line2d', self.get_gid())
gc = renderer.new_gc()
@@ -524,7 +545,7 @@ def draw(self, renderer):
funcname = self._lineStyles.get(self._linestyle, '_draw_nothing')
if funcname != '_draw_nothing':
- tpath, affine = transformed_path.get_transformed_path_and_affine()
+ tpath, affine = transf_path.get_transformed_path_and_affine()
if len(tpath.vertices):
self._lineFunc = getattr(self, funcname)
funcname = self.drawStyles.get(self._drawstyle, '_draw_lines')
@@ -545,7 +566,7 @@ def draw(self, renderer):
gc.set_linewidth(self._markeredgewidth)
marker = self._marker
- tpath, affine = transformed_path.get_transformed_points_and_affine()
+ tpath, affine = transf_path.get_transformed_points_and_affine()
if len(tpath.vertices):
# subsample the markers if markevery is not None
markevery = self.get_markevery()
@@ -597,13 +618,23 @@ def draw(self, renderer):
gc.restore()
renderer.close_group('line2d')
- def get_antialiased(self): return self._antialiased
- def get_color(self): return self._color
- def get_drawstyle(self): return self._drawstyle
- def get_linestyle(self): return self._linestyle
+ def get_antialiased(self):
+ return self._antialiased
- def get_linewidth(self): return self._linewidth
- def get_marker(self): return self._marker.get_marker()
+ def get_color(self):
+ return self._color
+
+ def get_drawstyle(self):
+ return self._drawstyle
+
+ def get_linestyle(self):
+ return self._linestyle
+
+ def get_linewidth(self):
+ return self._linewidth
+
+ def get_marker(self):
+ return self._marker.get_marker()
def get_markeredgecolor(self):
mec = self._markeredgecolor
@@ -617,7 +648,8 @@ def get_markeredgecolor(self):
else:
return mec
- def get_markeredgewidth(self): return self._markeredgewidth
+ def get_markeredgewidth(self):
+ return self._markeredgewidth
def _get_markerfacecolor(self, alt=False):
if alt:
@@ -639,7 +671,8 @@ def get_markerfacecolor(self):
def get_markerfacecoloralt(self):
return self._get_markerfacecolor(alt=True)
- def get_markersize(self): return self._markersize
+ def get_markersize(self):
+ return self._markersize
def get_data(self, orig=True):
"""
@@ -649,7 +682,6 @@ def get_data(self, orig=True):
"""
return self.get_xdata(orig=orig), self.get_ydata(orig=orig)
-
def get_xdata(self, orig=True):
"""
Return the xdata.
@@ -717,7 +749,8 @@ def set_drawstyle(self, drawstyle):
produce step-plots. 'steps' is equivalent to 'steps-pre' and
is maintained for backward-compatibility.
- ACCEPTS: [ 'default' | 'steps' | 'steps-pre' | 'steps-mid' | 'steps-post' ]
+ ACCEPTS: ['default' | 'steps' | 'steps-pre' | 'steps-mid' |
+ 'steps-post']
"""
self._drawstyle = drawstyle
@@ -754,7 +787,8 @@ def set_linestyle(self, linestyle):
:meth:`set_drawstyle`
To set the drawing style (stepping) of the plot.
- ACCEPTS: [ ``'-'`` | ``'--'`` | ``'-.'`` | ``':'`` | ``'None'`` | ``' '`` | ``''`` ]
+ ACCEPTS: [``'-'`` | ``'--'`` | ``'-.'`` | ``':'`` | ``'None'`` |
+ ``' '`` | ``''``]
and any drawstyle in combination with a linestyle, e.g. ``'steps--'``.
"""
@@ -772,8 +806,8 @@ def set_linestyle(self, linestyle):
linestyle = ls_mapper[linestyle]
else:
verbose.report('Unrecognized line style %s, %s' %
- (linestyle, type(linestyle)))
- if linestyle in [' ','']:
+ (linestyle, type(linestyle)))
+ if linestyle in [' ', '']:
linestyle = 'None'
self._linestyle = linestyle
@@ -794,7 +828,7 @@ def set_markeredgecolor(self, ec):
ACCEPTS: any matplotlib color
"""
- if ec is None :
+ if ec is None:
ec = 'auto'
self._markeredgecolor = ec
@@ -804,7 +838,7 @@ def set_markeredgewidth(self, ew):
ACCEPTS: float value in points
"""
- if ew is None :
+ if ew is None:
ew = rcParams['lines.markeredgewidth']
self._markeredgewidth = ew
@@ -864,20 +898,18 @@ def set_dashes(self, seq):
ACCEPTS: sequence of on/off ink in points
"""
- if seq == (None, None) or len(seq)==0:
+ if seq == (None, None) or len(seq) == 0:
self.set_linestyle('-')
else:
self.set_linestyle('--')
self._dashSeq = seq # TODO: offset ignored for now
-
def _draw_lines(self, renderer, gc, path, trans):
self._lineFunc(renderer, gc, path, trans)
-
def _draw_steps_pre(self, renderer, gc, path, trans):
vertices = self._xy
- steps = ma.zeros((2*len(vertices)-1, 2), np.float_)
+ steps = ma.zeros((2 * len(vertices) - 1, 2), np.float_)
steps[0::2, 0], steps[1::2, 0] = vertices[:, 0], vertices[:-1, 0]
steps[0::2, 1], steps[1:-1:2, 1] = vertices[:, 1], vertices[1:, 1]
@@ -886,10 +918,9 @@ def _draw_steps_pre(self, renderer, gc, path, trans):
path = path.transformed(self.get_transform())
self._lineFunc(renderer, gc, path, IdentityTransform())
-
def _draw_steps_post(self, renderer, gc, path, trans):
vertices = self._xy
- steps = ma.zeros((2*len(vertices)-1, 2), np.float_)
+ steps = ma.zeros((2 * len(vertices) - 1, 2), np.float_)
steps[::2, 0], steps[1:-1:2, 0] = vertices[:, 0], vertices[1:, 0]
steps[0::2, 1], steps[1::2, 1] = vertices[:, 1], vertices[:-1, 1]
@@ -898,10 +929,9 @@ def _draw_steps_post(self, renderer, gc, path, trans):
path = path.transformed(self.get_transform())
self._lineFunc(renderer, gc, path, IdentityTransform())
-
def _draw_steps_mid(self, renderer, gc, path, trans):
vertices = self._xy
- steps = ma.zeros((2*len(vertices), 2), np.float_)
+ steps = ma.zeros((2 * len(vertices), 2), np.float_)
steps[1:-1:2, 0] = 0.5 * (vertices[:-1, 0] + vertices[1:, 0])
steps[2::2, 0] = 0.5 * (vertices[:-1, 0] + vertices[1:, 0])
@@ -913,12 +943,10 @@ def _draw_steps_mid(self, renderer, gc, path, trans):
path = path.transformed(self.get_transform())
self._lineFunc(renderer, gc, path, IdentityTransform())
-
def _draw_solid(self, renderer, gc, path, trans):
gc.set_linestyle('solid')
renderer.draw_path(gc, path, trans)
-
def _draw_dashed(self, renderer, gc, path, trans):
gc.set_linestyle('dashed')
if self._dashSeq is not None:
@@ -926,19 +954,16 @@ def _draw_dashed(self, renderer, gc, path, trans):
renderer.draw_path(gc, path, trans)
-
def _draw_dash_dot(self, renderer, gc, path, trans):
gc.set_linestyle('dashdot')
renderer.draw_path(gc, path, trans)
-
def _draw_dotted(self, renderer, gc, path, trans):
gc.set_linestyle('dotted')
renderer.draw_path(gc, path, trans)
-
def update_from(self, other):
- 'copy properties from other to self'
+ """copy properties from other to self"""
Artist.update_from(self, other)
self._linestyle = other._linestyle
self._linewidth = other._linewidth
@@ -992,78 +1017,68 @@ def set_c(self, val):
'alias for set_color'
self.set_color(val)
-
def set_ls(self, val):
- 'alias for set_linestyle'
+ """alias for set_linestyle"""
self.set_linestyle(val)
-
def set_lw(self, val):
- 'alias for set_linewidth'
+ """alias for set_linewidth"""
self.set_linewidth(val)
-
def set_mec(self, val):
- 'alias for set_markeredgecolor'
+ """alias for set_markeredgecolor"""
self.set_markeredgecolor(val)
-
def set_mew(self, val):
- 'alias for set_markeredgewidth'
+ """alias for set_markeredgewidth"""
self.set_markeredgewidth(val)
-
def set_mfc(self, val):
- 'alias for set_markerfacecolor'
+ """alias for set_markerfacecolor"""
self.set_markerfacecolor(val)
def set_mfcalt(self, val):
- 'alias for set_markerfacecoloralt'
+ """alias for set_markerfacecoloralt"""
self.set_markerfacecoloralt(val)
def set_ms(self, val):
- 'alias for set_markersize'
+ """alias for set_markersize"""
self.set_markersize(val)
def get_aa(self):
- 'alias for get_antialiased'
+ """alias for get_antialiased"""
return self.get_antialiased()
def get_c(self):
- 'alias for get_color'
+ """alias for get_color"""
return self.get_color()
-
def get_ls(self):
- 'alias for get_linestyle'
+ """alias for get_linestyle"""
return self.get_linestyle()
-
def get_lw(self):
- 'alias for get_linewidth'
+ """alias for get_linewidth"""
return self.get_linewidth()
-
def get_mec(self):
- 'alias for get_markeredgecolor'
+ """alias for get_markeredgecolor"""
return self.get_markeredgecolor()
-
def get_mew(self):
- 'alias for get_markeredgewidth'
+ """alias for get_markeredgewidth"""
return self.get_markeredgewidth()
-
def get_mfc(self):
- 'alias for get_markerfacecolor'
+ """alias for get_markerfacecolor"""
return self.get_markerfacecolor()
def get_mfcalt(self, alt=False):
- 'alias for get_markerfacecoloralt'
+ """alias for get_markerfacecoloralt"""
return self.get_markerfacecoloralt()
def get_ms(self):
- 'alias for get_markersize'
+ """alias for get_markersize"""
return self.get_markersize()
def set_dash_joinstyle(self, s):
@@ -1074,7 +1089,7 @@ def set_dash_joinstyle(self, s):
s = s.lower()
if s not in self.validJoin:
raise ValueError('set_dash_joinstyle passed "%s";\n' % (s,)
- + 'valid joinstyles are %s' % (self.validJoin,))
+ + 'valid joinstyles are %s' % (self.validJoin,))
self._dashjoinstyle = s
def set_solid_joinstyle(self, s):
@@ -1085,10 +1100,9 @@ def set_solid_joinstyle(self, s):
s = s.lower()
if s not in self.validJoin:
raise ValueError('set_solid_joinstyle passed "%s";\n' % (s,)
- + 'valid joinstyles are %s' % (self.validJoin,))
+ + 'valid joinstyles are %s' % (self.validJoin,))
self._solidjoinstyle = s
-
def get_dash_joinstyle(self):
"""
Get the join style for dashed linestyles
@@ -1110,11 +1124,10 @@ def set_dash_capstyle(self, s):
s = s.lower()
if s not in self.validCap:
raise ValueError('set_dash_capstyle passed "%s";\n' % (s,)
- + 'valid capstyles are %s' % (self.validCap,))
+ + 'valid capstyles are %s' % (self.validCap,))
self._dashcapstyle = s
-
def set_solid_capstyle(self, s):
"""
Set the cap style for solid linestyles
@@ -1124,29 +1137,27 @@ def set_solid_capstyle(self, s):
s = s.lower()
if s not in self.validCap:
raise ValueError('set_solid_capstyle passed "%s";\n' % (s,)
- + 'valid capstyles are %s' % (self.validCap,))
+ + 'valid capstyles are %s' % (self.validCap,))
self._solidcapstyle = s
-
def get_dash_capstyle(self):
"""
Get the cap style for dashed linestyles
"""
return self._dashcapstyle
-
def get_solid_capstyle(self):
"""
Get the cap style for solid linestyles
"""
return self._solidcapstyle
-
def is_dashed(self):
'return True if line is dashstyle'
return self._linestyle in ('--', '-.', ':')
+
class VertexSelector:
"""
Manage the callbacks to maintain a list of selected vertices for
@@ -1190,7 +1201,8 @@ def __init__(self, line):
raise RuntimeError('You must first add the line to the Axes')
if line.get_picker() is None:
- raise RuntimeError('You must first set the picker property of the line')
+ raise RuntimeError('You must first set the picker property '
+ 'of the line')
self.axes = line.axes
self.line = line
@@ -1199,7 +1211,6 @@ def __init__(self, line):
self.ind = set()
-
def process_selected(self, ind, xs, ys):
"""
Default "do nothing" implementation of the
@@ -1211,8 +1222,9 @@ def process_selected(self, ind, xs, ys):
pass
def onpick(self, event):
- 'When the line is picked, update the set of selected indicies.'
- if event.artist is not self.line: return
+ """When the line is picked, update the set of selected indicies."""
+ if event.artist is not self.line:
+ return
for i in event.ind:
if i in self.ind:
@@ -1220,18 +1232,18 @@ def onpick(self, event):
else:
self.ind.add(i)
-
ind = list(self.ind)
ind.sort()
xdata, ydata = self.line.get_data()
self.process_selected(ind, xdata[ind], ydata[ind])
+
lineStyles = Line2D._lineStyles
lineMarkers = MarkerStyle.markers
drawStyles = Line2D.drawStyles
fillStyles = MarkerStyle.fillstyles
-docstring.interpd.update(Line2D = artist.kwdoc(Line2D))
+docstring.interpd.update(Line2D=artist.kwdoc(Line2D))
# You can not set the docstring of an instancemethod,
# but you can on the underlying function. Go figure.
Something went wrong with that request. Please try again.