Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1391e1

Browse files
committed
Trivial fixes.
1 parent 31d2c2f commit b1391e1

File tree

8 files changed

+52
-85
lines changed

8 files changed

+52
-85
lines changed

examples/statistics/histogram_features.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
Demo of the histogram (hist) function with a few features
44
=========================================================
55
6-
In addition to the basic histogram, this demo shows a few optional
7-
features:
6+
In addition to the basic histogram, this demo shows a few optional features:
87
9-
* Setting the number of data bins
10-
* The ``normed`` flag, which normalizes bin heights so that the
11-
integral of the histogram is 1. The resulting histogram is an
12-
approximation of the probability density function.
13-
* Setting the face color of the bars
14-
* Setting the opacity (alpha value).
8+
* Setting the number of data bins.
9+
* The ``normed`` flag, which normalizes bin heights so that the integral of
10+
the histogram is 1. The resulting histogram is an approximation of the
11+
probability density function.
12+
* Setting the face color of the bars.
13+
* Setting the opacity (alpha value).
1514
16-
Selecting different bin counts and sizes can significantly affect the
17-
shape of a histogram. The Astropy docs have a great section on how to
18-
select these parameters:
19-
http://docs.astropy.org/en/stable/visualization/histogram.html
15+
Selecting different bin counts and sizes can significantly affect the shape
16+
of a histogram. The Astropy docs have a great section_ on how to select these
17+
parameters.
18+
19+
.. _section: http://docs.astropy.org/en/stable/visualization/histogram.html
2020
"""
2121

2222
import matplotlib

lib/matplotlib/colors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,7 @@ def __call__(self, X, alpha=None, bytes=False):
515515
lut = self._lut.copy() # Don't let alpha modify original _lut.
516516

517517
if alpha is not None:
518-
alpha = min(alpha, 1.0) # alpha must be between 0 and 1
519-
alpha = max(alpha, 0.0)
518+
alpha = np.clip(alpha, 0, 1)
520519
if bytes:
521520
alpha = int(alpha * 255)
522521
if (lut[-1] == 0).all():

lib/matplotlib/patches.py

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import math
22
from numbers import Number
3+
import textwrap
34
import warnings
45

56
import numpy as np
@@ -1797,41 +1798,23 @@ def draw_bbox(bbox, renderer, color='k', trans=None):
17971798
r.draw(renderer)
17981799

17991800

1800-
def _pprint_table(_table, leadingspace=2):
1801+
def _pprint_table(table, leadingspace=2):
18011802
"""
18021803
Given the list of list of strings, return a string of REST table format.
18031804
"""
1804-
if leadingspace:
1805-
pad = ' ' * leadingspace
1806-
else:
1807-
pad = ''
1808-
1809-
columns = [[] for cell in _table[0]]
1810-
1811-
for row in _table:
1812-
for column, cell in zip(columns, row):
1813-
column.append(cell)
1814-
1815-
col_len = [max(len(cell) for cell in column) for column in columns]
1816-
1817-
lines = []
1818-
table_formatstr = pad + ' '.join([('=' * cl) for cl in col_len])
1819-
1820-
lines.append('')
1821-
lines.append(table_formatstr)
1822-
lines.append(pad + ' '.join([cell.ljust(cl)
1823-
for cell, cl
1824-
in zip(_table[0], col_len)]))
1825-
lines.append(table_formatstr)
1826-
1827-
lines.extend([(pad + ' '.join([cell.ljust(cl)
1828-
for cell, cl
1829-
in zip(row, col_len)]))
1830-
for row in _table[1:]])
1831-
1832-
lines.append(table_formatstr)
1833-
lines.append('')
1834-
return "\n".join(lines)
1805+
col_len = [max(len(cell) for cell in column) for column in zip(*table)]
1806+
table_formatstr = ' '.join('=' * cl for cl in col_len)
1807+
lines = [
1808+
'',
1809+
table_formatstr,
1810+
' '.join(cell.ljust(cl) for cell, cl in zip(table[0], col_len)),
1811+
table_formatstr,
1812+
*[' '.join(cell.ljust(cl) for cell, cl in zip(row, col_len))
1813+
for row in table[1:]],
1814+
table_formatstr,
1815+
'',
1816+
]
1817+
return textwrap.indent('\n'.join(lines), ' ' * leadingspace)
18351818

18361819

18371820
def _pprint_styles(_styles):

lib/matplotlib/path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def __init__(self, vertices, codes=None, _interpolation_steps=1,
125125
and codes as read-only arrays.
126126
"""
127127
vertices = _to_unmasked_float_array(vertices)
128-
if (vertices.ndim != 2) or (vertices.shape[1] != 2):
128+
if vertices.ndim != 2 or vertices.shape[1] != 2:
129129
raise ValueError(
130130
"'vertices' must be a 2D list or array with shape Nx2")
131131

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,12 +779,10 @@ def run(arguments, content, options, state_machine, state, lineno):
779779
for j, (code_piece, images) in enumerate(results):
780780
if options['include-source']:
781781
if is_doctest:
782-
lines = ['']
783-
lines += [row.rstrip() for row in code_piece.split('\n')]
782+
lines = ['', *code_piece.splitlines()]
784783
else:
785-
lines = ['.. code-block:: python', '']
786-
lines += [' %s' % row.rstrip()
787-
for row in code_piece.split('\n')]
784+
lines = ['.. code-block:: python', '',
785+
*textwrap.indent(code_piece, ' ').splitlines()]
788786
source_code = "\n".join(lines)
789787
else:
790788
source_code = ""

lib/matplotlib/ticker.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,9 +1529,7 @@ class FixedLocator(Locator):
15291529

15301530
def __init__(self, locs, nbins=None):
15311531
self.locs = np.asarray(locs)
1532-
self.nbins = nbins
1533-
if self.nbins is not None:
1534-
self.nbins = max(self.nbins, 2)
1532+
self.nbins = max(nbins, 2) if nbins is not None else None
15351533

15361534
def set_params(self, nbins=None):
15371535
"""Set parameters within this locator."""

pytest.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ markers =
1010
pep8ignore =
1111
* E111 E114 E115 E116 E121 E122 E123 E124 E125 E126 E127 E128 E129 E131 E226 E240 E241 E242 E243 E244 E245 E246 E247 E248 E249 E265 E266 E704 W503
1212

13-
tools/boilerplate.py E501
1413
setup.py E402
1514
setupext.py E301 E302 E501
1615
setup_external_compile.py E302 E711

tools/boilerplate.py

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,31 @@
88
itself, whereas the generatable content must be edited via templates in
99
this file.
1010
"""
11-
# We did try to do the wrapping the smart way,
12-
# with callable functions and new.function, but could never get the
13-
# docstrings right for python2.2. See
14-
# http://groups.google.com/group/comp.lang.python/browse_frm/thread/dcd63ec13096a0f6/1b14640f3a4ad3dc?#1b14640f3a4ad3dc
15-
# For some later history, see
16-
# http://thread.gmane.org/gmane.comp.python.matplotlib.devel/7068
11+
12+
# Although it is possible to dynamically generate the pyplot functions at
13+
# runtime with the proper signatures, a static pyplot.py is simpler for static
14+
# analysis tools to parse.
1715

1816
import inspect
1917
from inspect import Signature, Parameter
20-
import os
21-
import random
18+
from pathlib import Path
2219
import textwrap
2320

24-
# this line imports the installed copy of matplotlib, and not the local copy
21+
# This line imports the installed copy of matplotlib, and not the local copy.
2522
import numpy as np
2623
from matplotlib import mlab
2724
from matplotlib.axes import Axes
2825

2926

30-
# this is the magic line that must exist in pyplot, after which the boilerplate content will be
31-
# appended
32-
PYPLOT_MAGIC_HEADER = '################# REMAINING CONTENT GENERATED BY boilerplate.py ##############\n'
33-
34-
PYPLOT_PATH = os.path.join(os.path.dirname(__file__), 'lib', 'matplotlib',
35-
'pyplot.py')
36-
27+
# This is the magic line that must exist in pyplot, after which the boilerplate
28+
# content will be appended.
29+
PYPLOT_MAGIC_HEADER = (
30+
"################# REMAINING CONTENT GENERATED BY boilerplate.py "
31+
"##############\n")
3732

3833
AUTOGEN_MSG = """
3934
# Autogenerated by boilerplate.py. Do not edit as changes will be lost."""
4035

41-
4236
CMAPPABLE_TEMPLATE = AUTOGEN_MSG + """
4337
@_autogen_docstring(Axes.%(real_name)s)
4438
def %(func)s%(sig)s:
@@ -47,7 +41,6 @@ def %(func)s%(sig)s:
4741
return __ret
4842
"""
4943

50-
5144
NON_CMAPPABLE_TEMPLATE = AUTOGEN_MSG + """
5245
@docstring.copy_dedent(Axes.%(real_name)s)
5346
def %(func)s%(sig)s:
@@ -269,25 +262,22 @@ def __repr__(self):
269262

270263

271264
def build_pyplot():
272-
pyplot_path = os.path.join(os.path.dirname(__file__), "..", 'lib',
273-
'matplotlib', 'pyplot.py')
274-
275-
pyplot_orig = open(pyplot_path, 'r').readlines()
265+
pyplot_path = Path(__file__).parent / "../lib/matplotlib/pyplot.py"
276266

267+
pyplot_orig = pyplot_path.read_text().splitlines(keepends=True)
277268
try:
278269
pyplot_orig = pyplot_orig[:pyplot_orig.index(PYPLOT_MAGIC_HEADER) + 1]
279270
except IndexError:
280271
raise ValueError('The pyplot.py file *must* have the exact line: %s'
281272
% PYPLOT_MAGIC_HEADER)
282273

283-
pyplot = open(pyplot_path, 'w')
284-
pyplot.writelines(pyplot_orig)
285-
pyplot.write('\n')
286-
287-
pyplot.writelines(boilerplate_gen())
288-
pyplot.write('\n')
274+
with pyplot_path.open('w') as pyplot:
275+
pyplot.writelines(pyplot_orig)
276+
pyplot.write('\n')
277+
pyplot.writelines(boilerplate_gen())
278+
pyplot.write('\n')
289279

290280

291281
if __name__ == '__main__':
292-
# Write the matplotlib.pyplot file
282+
# Write the matplotlib.pyplot file.
293283
build_pyplot()

0 commit comments

Comments
 (0)