Skip to content

Commit

Permalink
Merge remote-tracking branch 'matplotlib/v2.1.x'
Browse files Browse the repository at this point in the history
Conflicts:
	examples/subplots_axes_and_figures/subplots_adjust.py
	  - both adjusted docstring
	.appveyor.yml
	  - application of python patch showed up twice, kept only one copy
	lib/matplotlib/pyplot.py
	  - moved imports around
  • Loading branch information
tacaswell committed Oct 28, 2017
2 parents 8989a6f + e9fcb97 commit b0a0a8e
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 34 deletions.
10 changes: 5 additions & 5 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ def _check_deps():
autodoc_default_flags = ['members', 'undoc-members']

intersphinx_mapping = {
'python': ('https://docs.python.org/', None),
'numpy': ('https://docs.scipy.org/doc/numpy/', None),
'scipy': ('https://docs.scipy.org/doc/scipy/reference/', None),
'pandas': ('http://pandas.pydata.org/pandas-docs/stable', None)
}
'python': ('https://docs.python.org/3', None),
'numpy': ('https://docs.scipy.org/doc/numpy/', None),
'scipy': ('https://docs.scipy.org/doc/scipy/reference/', None),
'pandas': ('https://pandas.pydata.org/pandas-docs/stable', None)
}

explicit_order_folders = [
'../examples/api',
Expand Down
8 changes: 4 additions & 4 deletions doc/users/event_handling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ Here are the events that you can connect to, the class instances that
are sent back to you when the event occurs, and the event descriptions


======================= ======================================================================================
======================= =============================================================================================
Event name Class and description
======================= ======================================================================================
======================= =============================================================================================
'button_press_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse button is pressed
'button_release_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse button is released
'draw_event' :class:`~matplotlib.backend_bases.DrawEvent` - canvas draw
'draw_event' :class:`~matplotlib.backend_bases.DrawEvent` - canvas draw (but before screen update)
'key_press_event' :class:`~matplotlib.backend_bases.KeyEvent` - key is pressed
'key_release_event' :class:`~matplotlib.backend_bases.KeyEvent` - key is released
'motion_notify_event' :class:`~matplotlib.backend_bases.MouseEvent` - mouse motion
Expand All @@ -73,7 +73,7 @@ Event name Class and description
'figure_leave_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse leaves a figure
'axes_enter_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse enters a new axes
'axes_leave_event' :class:`~matplotlib.backend_bases.LocationEvent` - mouse leaves an axes
======================= ======================================================================================
======================= =============================================================================================

.. _event-attributes:

Expand Down
2 changes: 1 addition & 1 deletion examples/subplots_axes_and_figures/subplots_adjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
===============
Adjusting the spacing of margins and subplots using
`~matplotlib.pyplot.subplots_adjust`.
:func:`~matplotlib.pyplot.subplots_adjust`.
"""
import matplotlib.pyplot as plt
import numpy as np
Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,16 @@ class DrawEvent(Event):
"""
An event triggered by a draw operation on the canvas
In most backends callbacks subscribed to this callback will be
fired after the rendering is complete but before the screen is
updated. Any extra artists drawn to the canvas's renderer will
be reflected without an explicit call to ``blit``.
.. warning ::
Calling ``canvas.draw`` and ``canvas.blit`` in these callbacks may
not be safe with all backends and may cause infinite recursion.
In addition to the :class:`Event` attributes, the following event
attributes are defined:
Expand Down
10 changes: 7 additions & 3 deletions lib/matplotlib/backends/backend_qt5agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,22 @@ def draw_idle(self):
QtCore.QTimer.singleShot(0, self.__draw_idle_agg)

def __draw_idle_agg(self, *args):
# if nothing to do, bail
if not self._agg_draw_pending:
return
# we have now tried this function at least once, do not run
# again until re-armed. Doing this here rather than after
# protects against recursive calls triggered through self.draw
self._agg_draw_pending = False
# if negative size, bail
if self.height() < 0 or self.width() < 0:
self._agg_draw_pending = False
return
try:
# actually do the drawing
self.draw()
except Exception:
# Uncaught exceptions are fatal for PyQt5, so catch them instead.
traceback.print_exc()
finally:
self._agg_draw_pending = False

def blit(self, bbox=None):
"""Blit the region in bbox.
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,10 @@ def get_cursor_data(self, event):
array_extent = Bbox([[0, 0], arr.shape[:2]])
trans = BboxTransform(boxin=data_extent, boxout=array_extent)
y, x = event.ydata, event.xdata
i, j = trans.transform_point([y, x]).astype(int)
point = trans.transform_point([y, x])
if any(np.isnan(point)):
return None
i, j = point.astype(int)
# Clip the coordinates at array bounds
if not (0 <= i < arr.shape[0]) or not (0 <= j < arr.shape[1]):
return None
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/sphinxext/tests/test_tinypages.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def setup_module():
ret = call([sys.executable, '-msphinx', '--help'],
stdout=PIPE, stderr=PIPE)
if ret != 0:
raise RuntimeError(
"'{} -msphinx' does not return 0".format(sys.executable))
pytest.skip("'{} -msphinx' does not return 0".format(sys.executable))


@cbook.deprecated("2.1", alternative="filecmp.cmp")
Expand Down
26 changes: 24 additions & 2 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1734,12 +1734,18 @@ def _as_mpl_axes(self):
ax_via_gca = plt.gca(projection=prj)
assert ax_via_gca is ax
# try getting the axes given a different polar projection
ax_via_gca = plt.gca(projection=prj2)
with pytest.warns(UserWarning) as rec:
ax_via_gca = plt.gca(projection=prj2)
assert len(rec) == 1
assert 'Requested projection is different' in str(rec[0].message)
assert ax_via_gca is not ax
assert ax.get_theta_offset() == 0
assert ax_via_gca.get_theta_offset() == np.pi
# try getting the axes given an == (not is) polar projection
ax_via_gca = plt.gca(projection=prj3)
with pytest.warns(UserWarning):
ax_via_gca = plt.gca(projection=prj3)
assert len(rec) == 1
assert 'Requested projection is different' in str(rec[0].message)
assert ax_via_gca is ax
plt.close()

Expand Down Expand Up @@ -5426,3 +5432,19 @@ def test_patch_deprecations():
assert fig.patch == fig.figurePatch

assert len(w) == 2


def test_polar_gridlines():
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)

# make all major grid lines lighter, only x grid lines set in 2.1.0
ax.grid(alpha=0.2)

# hide y tick labels, no effect in 2.1.0
plt.setp(ax.yaxis.get_ticklabels(), visible=False)

fig.canvas.draw()

assert ax.xaxis.majorTicks[0].gridline.get_alpha() == .2
assert ax.yaxis.majorTicks[0].gridline.get_alpha() == .2
22 changes: 12 additions & 10 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ def test_is_hashable():

def test_restrict_dict():
d = {'foo': 'bar', 1: 2}
d1 = cbook.restrict_dict(d, ['foo', 1])
assert d1 == d
d2 = cbook.restrict_dict(d, ['bar', 2])
assert d2 == {}
d3 = cbook.restrict_dict(d, {'foo': 1})
assert d3 == {'foo': 'bar'}
d4 = cbook.restrict_dict(d, {})
assert d4 == {}
d5 = cbook.restrict_dict(d, {'foo', 2})
assert d5 == {'foo': 'bar'}
with pytest.warns(cbook.deprecation.MatplotlibDeprecationWarning) as rec:
d1 = cbook.restrict_dict(d, ['foo', 1])
assert d1 == d
d2 = cbook.restrict_dict(d, ['bar', 2])
assert d2 == {}
d3 = cbook.restrict_dict(d, {'foo': 1})
assert d3 == {'foo': 'bar'}
d4 = cbook.restrict_dict(d, {})
assert d4 == {}
d5 = cbook.restrict_dict(d, {'foo', 2})
assert d5 == {'foo': 'bar'}
assert len(rec) == 5
# check that d was not modified
assert d == {'foo': 'bar', 1: 2}

Expand Down
10 changes: 9 additions & 1 deletion lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def test_tableau_order():
assert list(mcolors.TABLEAU_COLORS.values()) == dflt_cycle


def test_ndarray_subclass_norm():
def test_ndarray_subclass_norm(recwarn):
# Emulate an ndarray subclass that handles units
# which objects when adding or subtracting with other
# arrays. See #6622 and #8696
Expand All @@ -707,3 +707,11 @@ def __add__(self, other):
mcolors.SymLogNorm(3, vmax=5, linscale=1),
mcolors.PowerNorm(1)]:
assert_array_equal(norm(data.view(MyArray)), norm(data))
if isinstance(norm, mcolors.PowerNorm):
assert len(recwarn) == 1
warn = recwarn.pop(UserWarning)
assert ('Power-law scaling on negative values is ill-defined'
in str(warn.message))
else:
assert len(recwarn) == 0
recwarn.clear()
4 changes: 4 additions & 0 deletions lib/matplotlib/tests/test_compare_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ def addFailure(self, test, err):
assert failures[self.failure_count][1] in str(err[1])
self.failure_count += 1

# Make sure that multiple extensions work, but don't require LaTeX or
# Inkscape to do so.
kwargs.setdefault('extensions', ['png', 'png', 'png'])

func = image_comparison(**kwargs)(func)
loader = nose.loader.TestLoader()
suite = loader.loadTestsFromGenerator(
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ def test_too_many_date_ticks():
tf = datetime.datetime(2000, 1, 20)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.set_xlim((t0, tf), auto=True)
with pytest.warns(UserWarning) as rec:
ax.set_xlim((t0, tf), auto=True)
assert len(rec) == 1
assert 'Attempting to set identical left==right' in str(rec[0].message)
ax.plot([], [])
ax.xaxis.set_major_locator(mdates.DayLocator())
with pytest.raises(RuntimeError):
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,8 @@ def test_load_from_url():

@image_comparison(baseline_images=['log_scale_image'],
remove_text=True)
def test_log_scale_image():
# The recwarn fixture captures a warning in image_comparison.
def test_log_scale_image(recwarn):
Z = np.zeros((10, 10))
Z[::2] = 1

Expand All @@ -619,7 +620,6 @@ def test_log_scale_image():
ax.set_yscale('log')



@image_comparison(baseline_images=['rotate_image'],
remove_text=True)
def test_rotate_image():
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import warnings

from numpy.testing import (assert_allclose, assert_almost_equal,
assert_array_equal)
assert_array_equal, assert_array_almost_equal_nulp)
import numpy.ma.testutils as matest
import numpy as np
import datetime as datetime
Expand Down Expand Up @@ -1985,7 +1985,7 @@ def test_psd_csd_equal(self):
noverlap=self.nover_density,
pad_to=self.pad_to_density,
sides=self.sides)
assert_array_equal(Pxx, Pxy)
assert_array_almost_equal_nulp(Pxx, Pxy)
assert_array_equal(freqsxx, freqsxy)

def test_specgram_auto_default_equal(self):
Expand Down
4 changes: 4 additions & 0 deletions lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,10 @@ def __radd__(self, other):
# override `__eq__`), but some subclasses, such as TransformWrapper &
# AffineBase, override this behavior.

if six.PY2:
def __ne__(self, other):
return not (self == other)

def _iter_break_from_left_to_right(self):
"""
Returns an iterator breaking down this transform stack from left to
Expand Down

0 comments on commit b0a0a8e

Please sign in to comment.