Skip to content

Commit

Permalink
Merge remote-tracking branch 'matplotlib/v2.x'
Browse files Browse the repository at this point in the history
Conflicts:
	lib/matplotlib/units.py
	   Restored six import on master
  • Loading branch information
tacaswell committed Aug 29, 2016
2 parents 6e43e72 + aeed94b commit 0e46a9d
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ script:
fi
else
cd doc
python make.py html
python make.py html -n 2
# We don't build the LaTeX docs here, so linkchecker will complain
touch build/html/Matplotlib.pdf
# Linkchecker only works with python 2.7 for the time being
Expand Down
11 changes: 9 additions & 2 deletions doc/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def html(buildername='html'):
options = ''
if warnings_as_errors:
options = options + ' -W'
if os.system('sphinx-build %s -b %s -d build/doctrees . build/%s' % (options, buildername, buildername)):
if os.system('sphinx-build -j %d %s -b %s -d build/doctrees . build/%s' % (
n_proc, options, buildername, buildername)):
raise SystemExit("Building HTML failed.")

# Clean out PDF files from the _images directory
Expand All @@ -67,7 +68,7 @@ def htmlhelp():
with open('build/htmlhelp/index.html', 'r+') as fh:
content = fh.read()
fh.seek(0)
content = re.sub(r'<script>.*?</script>', '', content,
content = re.sub(r'<script>.*?</script>', '', content,
flags=re.MULTILINE| re.DOTALL)
fh.write(content)
fh.truncate()
Expand Down Expand Up @@ -146,6 +147,7 @@ def all():

small_docs = False
warnings_as_errors = True
n_proc = 1

# Change directory to the one containing this file
current_dir = os.getcwd()
Expand Down Expand Up @@ -195,11 +197,16 @@ def all():
parser.add_argument("--allowsphinxwarnings",
help="Don't turn Sphinx warnings into errors",
action="store_true")
parser.add_argument("-n",
help="Number of parallel workers to use")

args = parser.parse_args()
if args.small:
small_docs = True
if args.allowsphinxwarnings:
warnings_as_errors = False
if args.n is not None:
n_proc = int(args.n)

if args.cmd:
for command in args.cmd:
Expand Down
3 changes: 3 additions & 0 deletions doc/sphinxext/gen_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,6 @@ def setup(app):
app.add_config_value('mpl_example_sections', [], True)
except sphinx.errors.ExtensionError:
pass # mpl_example_sections already defined

metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
return metadata
3 changes: 3 additions & 0 deletions doc/sphinxext/gen_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,6 @@ def setup(app):
app.add_config_value('mpl_example_sections', [], True)
except sphinx.errors.ExtensionError:
pass # mpl_example_sections already defined

metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
return metadata
6 changes: 4 additions & 2 deletions doc/sphinxext/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def ghcommit_role(name, rawtext, text, lineno, inliner, options={}, content=[]):

def setup(app):
"""Install the plugin.
:param app: Sphinx application context.
"""
app.info('Initializing GitHub plugin')
Expand All @@ -152,4 +152,6 @@ def setup(app):
app.add_role('ghuser', ghuser_role)
app.add_role('ghcommit', ghcommit_role)
app.add_config_value('github_project_url', None, 'env')
return

metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
return metadata
3 changes: 3 additions & 0 deletions doc/sphinxext/math_symbol_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def setup(app):
'math_symbol_table', math_symbol_table_directive,
False, (0, 1, 0))

metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
return metadata

if __name__ == "__main__":
# Do some verification of the tables
from matplotlib import _mathtext_data
Expand Down
28 changes: 28 additions & 0 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,44 @@ def get_renderer(self, cleared=False):
return self.renderer

def tostring_rgb(self):
'''Get the image as an RGB byte string
`draw` must be called at least once before this function will work and
to update the renderer for any subsequent changes to the Figure.
Returns
-------
bytes
'''
if __debug__: verbose.report('FigureCanvasAgg.tostring_rgb',
'debug-annoying')
return self.renderer.tostring_rgb()

def tostring_argb(self):
'''Get the image as an ARGB byte string
`draw` must be called at least once before this function will work and
to update the renderer for any subsequent changes to the Figure.
Returns
-------
bytes
'''
if __debug__: verbose.report('FigureCanvasAgg.tostring_argb',
'debug-annoying')
return self.renderer.tostring_argb()

def buffer_rgba(self):
'''Get the image as an RGBA byte string
`draw` must be called at least once before this function will work and
to update the renderer for any subsequent changes to the Figure.
Returns
-------
bytes
'''
if __debug__: verbose.report('FigureCanvasAgg.buffer_rgba',
'debug-annoying')
return self.renderer.buffer_rgba()
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2486,6 +2486,15 @@ def index_of(y):

def safe_first_element(obj):
if isinstance(obj, collections.Iterator):
# needed to accept `array.flat` as input.
# np.flatiter reports as an instance of collections.Iterator
# but can still be indexed via [].
# This has the side effect of re-setting the iterator, but
# that is acceptable.
try:
return obj[0]
except TypeError:
pass
raise RuntimeError("matplotlib does not support generators "
"as input")
return next(iter(obj))
Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/sphinxext/mathmpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,6 @@ def depart_latex_math_latex(self, node):
app.add_role('math', math_role)
app.add_directive('math', math_directive,
True, (0, 0, 0), **options_spec)

metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
return metadata
13 changes: 7 additions & 6 deletions lib/matplotlib/sphinxext/only_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ def visit_ignore(self, node):
def depart_ignore(self, node):
node.children = []

app.add_node(html_only,
html=(visit_perform, depart_perform),
latex=(visit_ignore, depart_ignore))
app.add_node(latex_only,
latex=(visit_perform, depart_perform),
html=(visit_ignore, depart_ignore))
app.add_node(html_only, html=(visit_perform, depart_perform))
app.add_node(html_only, latex=(visit_ignore, depart_ignore))
app.add_node(latex_only, latex=(visit_perform, depart_perform))
app.add_node(latex_only, html=(visit_ignore, depart_ignore))

metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
return metadata
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,3 +511,15 @@ class dummy():
base_set = mapping[ref(objs[0])]
for o in objs[1:]:
assert mapping[ref(o)] is base_set


def test_flatiter():
x = np.arange(5)
it = x.flat
assert 0 == next(it)
assert 1 == next(it)
ret = cbook.safe_first_element(it)
assert ret == 0

assert 0 == next(it)
assert 1 == next(it)
2 changes: 2 additions & 0 deletions lib/matplotlib/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def default_units(x, axis):
from __future__ import (absolute_import, division, print_function,
unicode_literals)


import six
from matplotlib.cbook import iterable, is_numlike, safe_first_element
import numpy as np

Expand Down
6 changes: 3 additions & 3 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2449,9 +2449,9 @@ def bar3d(self, x, y, z, dx, dy, dz, color=None,

facecolors = []
if color is None:
# no color specified
facecolors = [None] * len(x)
elif len(color) == len(x):
color = [self._get_lines.get_next_color()]

if len(color) == len(x):
# bar colors specified, need to expand to number of faces
for c in color:
facecolors.extend([c] * 6)
Expand Down
13 changes: 13 additions & 0 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ def test_bar3d():
ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8)


@cleanup
def test_bar3d_dflt_smoke():
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = np.arange(4)
y = np.arange(5)
x2d, y2d = np.meshgrid(x, y)
x2d, y2d = x2d.ravel(), y2d.ravel()
z = x2d + y2d
ax.bar3d(x2d, y2d, x2d * 0, 1, 1, z)
fig.canvas.draw()


@image_comparison(baseline_images=['contour3d'], remove_text=True)
def test_contour3d():
fig = plt.figure()
Expand Down

0 comments on commit 0e46a9d

Please sign in to comment.