-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Pep8ify examples #3425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pep8ify examples #3425
Changes from 1 commit
99d3477
1c37e78
d0d9632
75b465c
9c2724c
64dfd4a
1d8d5c5
4a0f5f4
1171a96
dbd543e
ccb8efe
d65f921
9debab4
6636c30
47fbcd5
706f57d
9bcd5d3
f71c40d
a1cda13
23413a8
43c4c50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Signed-off-by: Thomas Hisch <t.hisch@gmail.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,9 @@ | |
# code used by a number of projections with similar characteristics | ||
# (see geo.py). | ||
|
||
|
||
class HammerAxes(Axes): | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uh, definitely don't want space between the class declaration and its docstring |
||
""" | ||
A custom class for the Aitoff-Hammer projection, an equal-area map | ||
projection. | ||
|
@@ -156,16 +158,16 @@ def _set_lim_and_transforms(self): | |
# (1, ymax). The goal of these transforms is to go from that | ||
# space to display space. The tick labels will be offset 4 | ||
# pixels from the edge of the axes ellipse. | ||
yaxis_stretch = Affine2D().scale(np.pi * 2.0, 1.0).translate(-np.pi, 0.0) | ||
yaxis_stretch = Affine2D().scale(2*np.pi, 1.0).translate(-np.pi, 0.0) | ||
yaxis_space = Affine2D().scale(1.0, 1.1) | ||
self._yaxis_transform = \ | ||
yaxis_stretch + \ | ||
self.transData | ||
yaxis_text_base = \ | ||
yaxis_stretch + \ | ||
self.transProjection + \ | ||
(yaxis_space + \ | ||
self.transAffine + \ | ||
(yaxis_space + | ||
self.transAffine + | ||
self.transAxes) | ||
self._yaxis_text1_transform = \ | ||
yaxis_text_base + \ | ||
|
@@ -174,12 +176,12 @@ def _set_lim_and_transforms(self): | |
yaxis_text_base + \ | ||
Affine2D().translate(8.0, 0.0) | ||
|
||
def get_xaxis_transform(self,which='grid'): | ||
def get_xaxis_transform(self, which='grid'): | ||
""" | ||
Override this method to provide a transformation for the | ||
x-axis grid and ticks. | ||
""" | ||
assert which in ['tick1','tick2','grid'] | ||
assert which in ['tick1', 'tick2', 'grid'] | ||
return self._xaxis_transform | ||
|
||
def get_xaxis_text1_transform(self, pixelPad): | ||
|
@@ -200,12 +202,12 @@ def get_xaxis_text2_transform(self, pixelPad): | |
""" | ||
return self._xaxis_text2_transform, 'top', 'center' | ||
|
||
def get_yaxis_transform(self,which='grid'): | ||
def get_yaxis_transform(self, which='grid'): | ||
""" | ||
Override this method to provide a transformation for the | ||
y-axis grid and ticks. | ||
""" | ||
assert which in ['tick1','tick2','grid'] | ||
assert which in ['tick1', 'tick2', 'grid'] | ||
return self._yaxis_transform | ||
|
||
def get_yaxis_text1_transform(self, pixelPad): | ||
|
@@ -238,8 +240,8 @@ def _gen_axes_patch(self): | |
return Circle((0.5, 0.5), 0.5) | ||
|
||
def _gen_axes_spines(self): | ||
return {'custom_hammer':mspines.Spine.circular_spine(self, | ||
(0.5, 0.5), 0.5)} | ||
return {'custom_hammer': mspines.Spine.circular_spine(self, | ||
(0.5, 0.5), 0.5)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still under 80 characters (can't tell with the github viewer)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes: 78 chars There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, the line length of the examples gets checked in the test_coding_standards unit test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, good. |
||
|
||
# Prevent the user from applying scales to one or both of the | ||
# axes. In this particular case, scaling the axes wouldn't make | ||
|
@@ -284,10 +286,12 @@ def format_coord(self, lon, lat): | |
return '%f\u00b0%s, %f\u00b0%s' % (abs(lat), ns, abs(lon), ew) | ||
|
||
class DegreeFormatter(Formatter): | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line between class and its docstring |
||
""" | ||
This is a custom formatter that converts the native unit of | ||
radians into (truncated) degrees and adds a degree symbol. | ||
""" | ||
|
||
def __init__(self, round_to=1.0): | ||
self._round_to = round_to | ||
|
||
|
@@ -369,16 +373,20 @@ def can_zoom(self): | |
Return True if this axes support the zoom box | ||
""" | ||
return False | ||
|
||
def start_pan(self, x, y, button): | ||
pass | ||
|
||
def end_pan(self): | ||
pass | ||
|
||
def drag_pan(self, button, key, x, y): | ||
pass | ||
|
||
# Now, the transforms themselves. | ||
|
||
class HammerTransform(Transform): | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spurious blank line |
||
""" | ||
The base Hammer transform. | ||
""" | ||
|
@@ -394,7 +402,7 @@ def transform_non_affine(self, ll): | |
The input and output are Nx2 numpy arrays. | ||
""" | ||
longitude = ll[:, 0:1] | ||
latitude = ll[:, 1:2] | ||
latitude = ll[:, 1:2] | ||
|
||
# Pre-compute some values | ||
half_long = longitude / 2.0 | ||
|
@@ -417,13 +425,13 @@ def transform_path_non_affine(self, path): | |
ipath = path.interpolated(path._interpolation_steps) | ||
return Path(self.transform(ipath.vertices), ipath.codes) | ||
transform_path_non_affine.__doc__ = \ | ||
Transform.transform_path_non_affine.__doc__ | ||
Transform.transform_path_non_affine.__doc__ | ||
|
||
if matplotlib.__version__ < '1.2': | ||
# Note: For compatibility with matplotlib v1.1 and older, you'll | ||
# need to explicitly implement a ``transform`` method as well. | ||
# Otherwise a ``NotImplementedError`` will be raised. This isn't | ||
# necessary for v1.2 and newer, however. | ||
# necessary for v1.2 and newer, however. | ||
transform = transform_non_affine | ||
|
||
# Similarly, we need to explicitly override ``transform_path`` if | ||
|
@@ -449,12 +457,12 @@ def transform_non_affine(self, xy): | |
quarter_x = 0.25 * x | ||
half_y = 0.5 * y | ||
z = np.sqrt(1.0 - quarter_x*quarter_x - half_y*half_y) | ||
longitude = 2 * np.arctan((z*x) / (2.0 * (2.0*z*z - 1.0))) | ||
longitude = 2*np.arctan((z*x)/(2.0*(2.0*z*z - 1.0))) | ||
latitude = np.arcsin(y*z) | ||
return np.concatenate((longitude, latitude), 1) | ||
transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__ | ||
|
||
# As before, we need to implement the "transform" method for | ||
# As before, we need to implement the "transform" method for | ||
# compatibility with matplotlib v1.1 and older. | ||
if matplotlib.__version__ < '1.2': | ||
transform = transform_non_affine | ||
|
@@ -476,4 +484,3 @@ def inverted(self): | |
plt.grid(True) | ||
|
||
plt.show() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put the
()
back? I think they add clarity here.