10000 More style fixes. by anntzer · Pull Request #11870 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

More style fixes. #11870

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

Merged
merged 1 commit into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,12 @@ per-file-ignores =
matplotlib/backends/windowing.py: E301, E302
matplotlib/font_manager.py: E203, E221, E251, E261, E262, E302, E501
matplotlib/fontconfig_pattern.py: E201, E203, E221, E222, E225, E302
matplotlib/legend_handler.py: E201, E501
matplotlib/mathtext.py: E201, E202, E203, E211, E221, E222, E225, E251, E301, E402
matplotlib/patheffects.py: E231
matplotlib/projections/geo.py: E203, E221, E231, E261, E502
matplotlib/pylab.py: E501
matplotlib/pyplot.py: E201, E202, E221, E222, E225, E231, E251, E261, E302, E501, E701
matplotlib/rcsetup.py: E203, E225, E261, E302, E501
matplotlib/sphinxext/mathmpl.py: E302
matplotlib/sphinxext/only_directives.py: E302
matplotlib/sphinxext/plot_directive.py: E261, E302, E402
matplotlib/sphinxext/plot_directive.py: E402
matplotlib/tests/test_image.py: E231
matplotlib/tests/test_mathtext.py: E501
matplotlib/transforms.py: E201, E202, E203, E501
Expand Down
17 changes: 9 additions & 8 deletions lib/matplotlib/legend_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ def patch_func(legend=legend, orig_handle=orig_handle,
xdescent=xdescent, ydescent=ydescent,
width=width, height=height, fontsize=fontsize)

Subsequently the created artist will have its ``update_prop`` method
called and the appropriate transform will be applied.
Subsequently the created artist will have its ``update_prop``
method called and the appropriate transform will be applied.

Notes
-----
Expand Down Expand Up @@ -374,7 +374,7 @@ def update_prop(self, legend_handle, orig_handle, legend):
self._update_prop(legend_handle, orig_handle)

legend_handle.set_figure(legend.figure)
#legend._set_artist_props(legend_handle)
# legend._set_artist_props(legend_handle)
legend_handle.set_clip_box(None)
legend_handle.set_clip_path(None)

Expand Down Expand Up @@ -499,8 +499,8 @@ def create_artists(self, legend, orig_handle,
handle_caplines = []

if orig_handle.has_xerr:
verts = [ ((x - xerr_size, y), (x + xerr_size, y))
for x, y in zip(xdata_marker, ydata_marker)]
verts = [((x - xerr_size, y), (x + xerr_size, y))
for x, y in zip(xdata_marker, ydata_marker)]
coll = mcoll.LineCollection(verts)
self.update_prop(coll, barlinecols[0], legend)
handle_barlinecols.append(coll)
Expand All @@ -517,8 +517,8 @@ def create_artists(self, legend, orig_handle,
handle_caplines.append(capline_right)

if orig_handle.has_yerr:
verts = [ ((x, y - yerr_size), (x, y + yerr_size))
for x, y in zip(xdata_marker, ydata_marker)]
verts = [((x, y - yerr_size), (x, y + yerr_size))
for x, y in zip(xdata_marker, ydata_marker)]
coll = mcoll.LineCollection(verts)
self.update_prop(coll, barlinecols[0], legend)
handle_barlinecols.append(coll)
Expand Down Expand Up @@ -686,7 +686,8 @@ def create_artists(self, legend, orig_handle,

class HandlerPolyCollection(HandlerBase):
"""
Handler for `.PolyCollection` used in `~.Axes.fill_between` and `~.Axes.stackplot`.
Handler for `.PolyCollection` used in `~.Axes.fill_between` and
`~.Axes.stackplot`.
"""
def _update_prop(self, legend_handle, orig_handle):
def first_color(colors):
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/patheffects.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def draw_path(self, gc, tpath, affine, rgbFace=None):
path_effect.draw_path(self._renderer, gc, tpath, affine,
rgbFace)

def draw_markers(self, gc, marker_path, marker_trans, path, *args,
**kwargs):
def draw_markers(
self, gc, marker_path, marker_trans, path, *args, **kwargs):
# We do a little shimmy so that all markers are drawn for each path
# effect in turn. Essentially, we induce recursion (depth 1) which is
# terminated once we have just a single path effect to work with.
Expand Down Expand Up @@ -263,7 +263,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
gc0.copy_properties(gc)

if self._shadow_rgbFace is None:
r,g,b = (rgbFace or (1., 1., 1.))[:3]
r, g, b = (rgbFace or (1., 1., 1.))[:3]
# Scale the colors by a factor to improve the shadow effect.
shadow_rgbFace = (r * self._rho, g * self._rho, b * self._rho)
else:
Expand Down Expand Up @@ -291,7 +291,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):

class SimpleLineShadow(AbstractPathEffect):
"""A simple shadow via a line."""
def __init__(self, offset=(2,-2),
def __init__(self, offset=(2, -2),
shadow_color='k', alpha=0.3, rho=0.3, **kwargs):
"""
Parameters
Expand Down Expand Up @@ -340,7 +340,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
gc0.copy_properties(gc)

if self._shadow_color is None:
r,g,b = (gc0.get_foreground() or (1., 1., 1.))[:3]
r, g, b = (gc0.get_foreground() or (1., 1., 1.))[:3]
# Scale the colors by a factor to improve the shadow effect.
shadow_rgbFace = (r * self._rho, g * self._rho, b * self._rho)
else:
Expand Down
11 changes: 10 additions & 1 deletion lib/matplotlib/sphinxext/mathmpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
rcParams['mathtext.fontset'] = 'cm'
mathtext_parser = MathTextParser("Bitmap")


# Define LaTeX math node:
class latex_math(nodes.General, nodes.Element):
pass


def fontset_choice(arg):
return directives.choice(arg, ['cm', 'stix', 'stixsans'])


options_spec = {'fontset': fontset_choice}


def math_role(role, rawtext, text, lineno, inliner,
options={}, content=[]):
i = rawtext.find('`')
Expand All @@ -28,8 +32,11 @@ def math_role(role, rawtext, text, lineno, inliner,
node['latex'] = latex
node['fontset'] = options.get('fontset', 'cm')
return [node], []


math_role.options = options_spec


def math_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
latex = ''.join(content)
Expand All @@ -38,6 +45,7 @@ def math_directive(name, arguments, options, content, lineno,
node['fontset'] = options.get('fontset', 'cm')
return [node]


# This uses mathtext to render the expression
def latex2png(latex, filename, fontset='cm'):
latex = "$%s$" % latex
Expand All @@ -48,7 +56,7 @@ def latex2png(latex, filename, fontset='cm'):
else:
try:
depth = mathtext_parser.to_png(filename, latex, dpi=100)
except:
except Exception:
warnings.warn("Could not render math expression %s" % latex,
Warning, stacklevel=2)
depth = 0
Expand All @@ -57,6 +65,7 @@ def latex2png(latex, filename, fontset='cm'):
sys.stdout.flush()
return depth


# LaTeX to HTML translation stuff:
def latex2html(node, source):
inline = isinstance(node.parent, nodes.TextElement)
Expand Down
31 changes: 15 additions & 16 deletions lib/matplotlib/sphinxext/plot_directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,11 @@

__version__ = 2

#------------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# Registration hook
#------------------------------------------------------------------------------
# -----------------------------------------------------------------------------


def plot_directive(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
Expand Down Expand Up @@ -275,9 +277,11 @@ def setup(app):
metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
return metadata

#------------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# Doctest handling
#------------------------------------------------------------------------------
# -----------------------------------------------------------------------------


def contains_doctest(text):
try:
Expand All @@ -295,7 +299,6 @@ def unescape_doctest(text):
"""
Extract code from a piece of text, which contains either Python code
or doctests.

"""
if not contains_doctest(text):
return text
Expand All @@ -313,11 +316,7 @@ def unescape_doctest(text):


def split_code_at_show(text):
"""
Split code at plt.show()

"""

"""Split code at plt.show()."""
parts = []
is_doctest = contains_doctest(text)

Expand All @@ -336,16 +335,15 @@ def split_code_at_show(text):


def remove_coding(text):
r"""
Remove the coding comment, which six.exec\_ doesn't like.
"""
r"""Remove the coding comment, which six.exec\_ doesn't like."""
cbook.warn_deprecated('3.0', name='remove_coding', removal='3.1')
sub_re = re.compile(r"^#\s*-\*-\s*coding:\s*.*-\*-$", flags=re.MULTILINE)
return sub_re.sub("", text)

#------------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# Template
#------------------------------------------------------------------------------
# -----------------------------------------------------------------------------


TEMPLATE = """
Expand Down Expand Up @@ -425,6 +423,7 @@ def remove_coding(text):
# :context: option
plot_context = dict()


class ImageFile(object):
def __init__(self, basename, dirname):
self.basename = basename
Expand Down Expand Up @@ -711,7 +710,7 @@ def run(arguments, content, options, state_machine, state, lineno):
dest_dir = os.path.abspath(os.path.join(setup.app.builder.outdir,
source_rel_dir))
if not os.path.exists(dest_dir):
os.makedirs(dest_dir) # no problem here for me, but just use built-ins
os.makedirs(dest_dir) # no problem here for me, but just use built-ins

# how to link to files from the RST file
dest_dir_link = os.path.join(relpath(setup.confdir, rst_dir),
Expand Down
0