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

Skip to content

Commit ae3de41

Browse files
Merge branch 'master' into mpl-17508
2 parents 09f62a4 + 81f0624 commit ae3de41

File tree

15 files changed

+87
-57
lines changed

15 files changed

+87
-57
lines changed

.github/workflows/tests.yml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ jobs:
2222
matrix:
2323
include:
2424
- name-suffix: "(Minimum Versions)"
25-
os: ubuntu-16.04
25+
os: ubuntu-18.04
2626
python-version: 3.7
2727
extra-requirements: '-c requirements/testing/minver.txt'
2828
pyqt5-ver: '==5.8 sip==4.19.7' # oldest versions with a Py3.7 wheel.
2929
delete-font-cache: true
3030
XVFB_RUN: xvfb-run -a
31-
- os: ubuntu-16.04
31+
- os: ubuntu-18.04
3232
python-version: 3.7
3333
extra-requirements: '-r requirements/testing/extra.txt'
3434
XVFB_RUN: xvfb-run -a
3535
CFLAGS: "-fno-lto" # Ensure that disabling LTO works.
36-
- os: ubuntu-16.04
36+
- os: ubuntu-18.04
3737
python-version: 3.8
3838
extra-requirements: '-r requirements/testing/extra.txt'
3939
XVFB_RUN: xvfb-run -a
@@ -128,10 +128,10 @@ jobs:
128128
~/.cache/matplotlib
129129
!~/.cache/matplotlib/tex.cache
130130
!~/.cache/matplotlib/test_cache
131-
key: ${{ runner.os }}-py${{ matrix.python-version }}-mpl-${{ github.ref }}-${{ github.sha }}
131+
key: 1-${{ runner.os }}-py${{ matrix.python-version }}-mpl-${{ github.ref }}-${{ github.sha }}
132132
restore-keys: |
133-
${{ runner.os }}-py${{ matrix.python-version }}-mpl-${{ github.ref }}-
134-
${{ runner.os }}-py${{ matrix.python-version }}-mpl-
133+
1-${{ runner.os }}-py${{ matrix.python-version }}-mpl-${{ github.ref }}-
134+
1-${{ runner.os }}-py${{ matrix.python-version }}-mpl-
135135
136136
- name: Install Python dependencies
137137
run: |
@@ -156,12 +156,8 @@ jobs:
156156
# libraries cannot be loaded at runtime, so an actual import is a
157157
# better check).
158158
if [[ "${{ runner.os }}" != 'macOS' ]]; then
159-
# PyGObject, pycairo, and cariocffi do not install on OSX 10.12;
160-
# pycairo 1.20+ requires a new version of Cairo, unavailable on
161-
# Ubuntu 16.04, so PyGObject must be installed without build
162-
# isolation in order to pick up the lower pre-installed version.
163-
python -m pip install --upgrade 'pycairo<1.20.0' 'cairocffi>=0.8' &&
164-
python -m pip install --upgrade --no-build-isolation PyGObject &&
159+
# PyGObject, pycairo, and cariocffi do not install on OSX 10.12.
160+
python -m pip install --upgrade pycairo 'cairocffi>=0.8' PyGObject &&
165161
python -c 'import gi; gi.require_version("Gtk", "3.0"); from gi.repository import Gtk' &&
166162
echo 'PyGObject is available' ||
167163
echo 'PyGObject is not available'
@@ -180,7 +176,7 @@ jobs:
180176
echo 'PySide2 is not available'
181177
fi
182178
python -m pip install --upgrade \
183-
-f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-16.04 \
179+
-f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04 \
184180
wxPython &&
185181
python -c 'import wx' &&
186182
echo 'wxPython is available' ||
@@ -226,3 +222,9 @@ jobs:
226222
if: ${{ runner.os != 'macOS' }}
227223
- name: Upload code coverage
228224
uses: codecov/codecov-action@v1
225+
226+
- uses: actions/upload-artifact@v2
227+
if: failure()
228+
with:
229+
name: "${{ matrix.python-version }} ${{ matrix.os }} ${{ matrix.name-suffix }} result images"
230+
path: ./result_images

azure-pipelines.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
strategy:
77
matrix:
88
Linux_py37:
9-
vmImage: 'ubuntu-16.04'
9+
vmImage: 'ubuntu-18.04'
1010
python.version: '3.7'
1111
Linux_py38:
12-
vmImage: 'ubuntu-16.04'
12+
vmImage: 'ubuntu-18.04'
1313
python.version: '3.8'
1414
Linux_py39:
15-
vmImage: 'ubuntu-16.04'
15+
vmImage: 'ubuntu-18.04'
1616
python.version: '3.9'
1717
macOS_py37:
1818
vmImage: 'macOS-10.15'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``cbook.report_memory``
2+
~~~~~~~~~~~~~~~~~~~~~~~
3+
... is deprecated. Use ``psutil.virtual_memory`` instead.

examples/axes_grid1/simple_axes_divider1.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
=====================
33
Simple Axes Divider 1
44
=====================
5+
6+
See also :doc:`/tutorials/toolkits/axes_grid`.
57
"""
68

79
from mpl_toolkits.axes_grid1 import Size, Divider
@@ -16,51 +18,48 @@ def label_axes(ax, text):
1618
left=False, labelleft=False)
1719

1820

19-
##############################################################################
20-
# Fixed axes sizes; fixed paddings.
21+
fig = plt.figure(figsize=(12, 6))
22+
sfs = fig.subfigures(1, 2)
2123

22-
fig = plt.figure(figsize=(6, 6))
23-
fig.suptitle("Fixed axes sizes, fixed paddings")
2424

25+
sfs[0].suptitle("Fixed axes sizes, fixed paddings")
2526
# Sizes are in inches.
2627
horiz = [Size.Fixed(1.), Size.Fixed(.5), Size.Fixed(1.5), Size.Fixed(.5)]
2728
vert = [Size.Fixed(1.5), Size.Fixed(.5), Size.Fixed(1.)]
2829

2930
rect = (0.1, 0.1, 0.8, 0.8)
3031
# Divide the axes rectangle into a grid with sizes specified by horiz * vert.
31-
divider = Divider(fig, rect, horiz, vert, aspect=False)
32+
div = Divider(sfs[0], rect, horiz, vert, aspect=False)
3233

3334
# The rect parameter will actually be ignored and overridden by axes_locator.
34-
ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0))
35+
ax1 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=0))
3536
label_axes(ax1, "nx=0, ny=0")
36-
ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
37+
ax2 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=2))
3738
label_axes(ax2, "nx=0, ny=2")
38-
ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
39+
ax3 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=2, ny=2))
3940
label_axes(ax3, "nx=2, ny=2")
40-
ax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0))
41+
ax4 = sfs[0].add_axes(rect, axes_locator=div.new_locator(nx=2, nx1=4, ny=0))
4142
label_axes(ax4, "nx=2, nx1=4, ny=0")
4243

43-
##############################################################################
44-
# Axes sizes that scale with the figure size; fixed paddings.
45-
46-
fig = plt.figure(figsize=(6, 6))
47-
fig.suptitle("Scalable axes sizes, fixed paddings")
4844

45+
sfs[1].suptitle("Scalable axes sizes, fixed paddings")
46+
# Fixed sizes are in inches, scaled sizes are relative.
4947
horiz = [Size.Scaled(1.5), Size.Fixed(.5), Size.Scaled(1.), Size.Scaled(.5)]
5048
vert = [Size.Scaled(1.), Size.Fixed(.5), Size.Scaled(1.5)]
5149

5250
rect = (0.1, 0.1, 0.8, 0.8)
5351
# Divide the axes rectangle into a grid with sizes specified by horiz * vert.
54-
divider = Divider(fig, rect, horiz, vert, aspect=False)
52+
div = Divider(sfs[1], rect, horiz, vert, aspect=False)
5553

5654
# The rect parameter will actually be ignored and overridden by axes_locator.
57-
ax1 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=0))
55+
ax1 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=0))
5856
label_axes(ax1, "nx=0, ny=0")
59-
ax2 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=0, ny=2))
57+
ax2 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=0, ny=2))
6058
label_axes(ax2, "nx=0, ny=2")
61-
ax3 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, ny=2))
59+
ax3 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=2, ny=2))
6260
label_axes(ax3, "nx=2, ny=2")
63-
ax4 = fig.add_axes(rect, axes_locator=divider.new_locator(nx=2, nx1=4, ny=0))
61+
ax4 = sfs[1].add_axes(rect, axes_locator=div.new_locator(nx=2, nx1=4, ny=0))
6462
label_axes(ax4, "nx=2, nx1=4, ny=0")
6563

64+
6665
plt.show()

examples/axes_grid1/simple_axes_divider3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
Simple Axes Divider 3
44
=====================
55
6+
See also :doc:`/tutorials/toolkits/axes_grid`.
67
"""
8+
79
import mpl_toolkits.axes_grid1.axes_size as Size
810
from mpl_toolkits.axes_grid1 import Divider
911
import matplotlib.pyplot as plt

lib/matplotlib/backends/backend_pgf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,9 @@ def __init__(self, filename, *, keep_empty=True, metadata=None):
948948
'Creator', 'Producer', 'CreationDate', 'ModDate', and
949949
'Trapped'. Values have been predefined for 'Creator', 'Producer'
950950
and 'CreationDate'. They can be removed by setting them to `None`.
951+
952+
Note that some versions of LaTeX engines may ignore the 'Producer'
953+
key and set it to themselves.
951954
"""
952955
self._output_name = filename
953956
self._n_figures = 0

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ def remove(self, o):
628628
self.push(elem)
629629

630630

631+
@_api.deprecated("3.5", alternative="psutil.virtual_memory")
631632
def report_memory(i=0): # argument may go away
632633
"""Return the memory consumed by the process."""
633634
def call(command, os_name):

lib/matplotlib/cm.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,11 @@ def to_rgba(self, x, alpha=None, bytes=False, norm=True):
361361

362362
def set_array(self, A):
363363
"""
364-
Set the image array from numpy array *A*.
364+
Set the image array from array-like *A*.
365365
366366
Parameters
367367
----------
368-
A : ndarray or None
368+
A : array-like or None
369369
"""
370370
if A is None:
371371
self._A = None
@@ -386,6 +386,12 @@ def set_array(self, A):
386386
'Dimensions of A %s are incompatible with '
387387
'X (%d) and/or Y (%d)' %
388388
(A.shape, width, height))
389+
390+
A = cbook.safe_masked_invalid(A, copy=True)
391+
if not np.can_cast(A.dtype, float, "same_kind"):
392+
raise TypeError(f"Image data of dtype {A.dtype} cannot be "
393+
"converted to float")
394+
389395
self._A = A
390396

391397
def get_array(self):

lib/matplotlib/image.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,8 +1346,7 @@ def make_image(self, renderer, magnification=1.0, unsampled=False):
13461346

13471347
def set_data(self, A):
13481348
"""Set the image array."""
1349-
cm.ScalarMappable.set_array(self,
1350-
cbook.safe_masked_invalid(A, copy=True))
1349+
cm.ScalarMappable.set_array(self, A)
13511350
self.stale = True
13521351

13531352

lib/matplotlib/legend.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -460,16 +460,11 @@ def __init__(self, parent, handles, labels,
460460
if not self.isaxes and loc in [0, 'best']:
461461
loc = 'upper right'
462462
if isinstance(loc, str):
463-
if loc not in self.codes:
464-
raise ValueError(
465-
"Unrecognized location {!r}. Valid locations are\n\t{}\n"
466-
.format(loc, '\n\t'.join(self.codes)))
467-
else:
468-
loc = self.codes[loc]
463+
loc = _api.check_getitem(self.codes, loc=loc)
469464
if not self.isaxes and loc == 0:
470465
raise ValueError(
471466
"Automatic legend placement (loc='best') not implemented for "
472-
"figure legend.")
467+
"figure legend")
473468

474469
self._mode = mode
475470
self.set_bbox_to_anchor(bbox_to_anchor, bbox_transform)
Binary file not shown.

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,17 @@ def test_pdf_pages_metadata_check(monkeypatch, system):
257257
if '/PTEX.Fullbanner' in info:
258258
del info['/PTEX.Fullbanner']
259259

260+
# Some LaTeX engines ignore this setting, and state themselves as producer.
261+
producer = info.pop('/Producer')
262+
assert producer == f'Matplotlib pgf backend v{mpl.__version__}' or (
263+
system == 'lualatex' and 'LuaTeX' in producer)
264+
260265
assert info == {
261266
'/Author': 'me',
262267
'/CreationDate': 'D:19700101000000Z',
263268
'/Creator': f'Matplotlib v{mpl.__version__}, https://matplotlib.org',
264269
'/Keywords': 'test,pdf,multipage',
265270
'/ModDate': 'D:19680801000000Z',
266-
'/Producer': f'Matplotlib pgf backend v{mpl.__version__}',
267271
'/Subject': 'Test page',
268272
'/Title': 'Multipage PDF with pgf',
269273
'/Trapped': '/True',

lib/matplotlib/tests/test_collections.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,22 @@ def test_collection_set_verts_array():
678678
assert np.array_equal(ap._codes, atp._codes)
679679

680680

681+
def test_collection_set_array():
682+
vals = [*range(10)]
683+
684+
# Test set_array with list
685+
c = Collection()
686+
c.set_array(vals)
687+
688+
# Test set_array with wrong dtype
689+
with pytest.raises(TypeError, match="^Image data of dtype"):
690+
c.set_array("wrong_input")
691+
692+
# Test if array kwarg is copied
693+
vals[5] = 45
694+
assert np.not_equal(vals, c.get_array()).any()
695+
696+
681697
def test_blended_collection_autolim():
682698
a = [1, 2, 4]
683699
height = .2

lib/mpl_toolkits/axes_grid1/axes_divider.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,21 @@ def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
188188
renderer
189189
"""
190190

191-
figW, figH = self._fig.get_size_inches()
191+
fig_w, fig_h = self._fig.bbox.size / self._fig.dpi
192192
x, y, w, h = self.get_position_runtime(axes, renderer)
193193

194194
hsizes = self.get_horizontal_sizes(renderer)
195195
vsizes = self.get_vertical_sizes(renderer)
196-
k_h = self._calc_k(hsizes, figW*w)
197-
k_v = self._calc_k(vsizes, figH*h)
196+
k_h = self._calc_k(hsizes, fig_w * w)
197+
k_v = self._calc_k(vsizes, fig_h * h)
198198

199199
if self.get_aspect():
200200
k = min(k_h, k_v)
201201
ox = self._calc_offsets(hsizes, k)
202202
oy = self._calc_offsets(vsizes, k)
203203

204-
ww = (ox[-1] - ox[0]) / figW
205-
hh = (oy[-1] - oy[0]) / figH
204+
ww = (ox[-1] - ox[0]) / fig_w
205+
hh = (oy[-1] - oy[0]) / fig_h
206206
pb = mtransforms.Bbox.from_bounds(x, y, w, h)
207207
pb1 = mtransforms.Bbox.from_bounds(x, y, ww, hh)
208208
pb1_anchored = pb1.anchored(self.get_anchor(), pb)
@@ -218,8 +218,8 @@ def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
218218
if ny1 is None:
219219
ny1 = ny + 1
220220

221-
x1, w1 = x0 + ox[nx] / figW, (ox[nx1] - ox[nx]) / figW
222-
y1, h1 = y0 + oy[ny] / figH, (oy[ny1] - oy[ny]) / figH
221+
x1, w1 = x0 + ox[nx] / fig_w, (ox[nx1] - ox[nx]) / fig_w
222+
y1, h1 = y0 + oy[ny] / fig_h, (oy[ny1] - oy[ny]) / fig_h
223223

224224
return mtransforms.Bbox.from_bounds(x1, y1, w1, h1)
225225

@@ -649,7 +649,7 @@ def new_locator(self, nx, nx1=None):
649649

650650
def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
651651
# docstring inherited
652-
fig_w, fig_h = self._fig.get_size_inches()
652+
fig_w, fig_h = self._fig.bbox.size / self._fig.dpi
653653
x, y, w, h = self.get_position_runtime(axes, renderer)
654654
summed_ws = self.get_horizontal_sizes(renderer)
655655
equal_hs = self.get_vertical_sizes(renderer)
@@ -684,7 +684,7 @@ def new_locator(self, ny, ny1=None):
684684

685685
def locate(self, nx, ny, nx1=None, ny1=None, axes=None, renderer=None):
686686
# docstring inherited
687-
fig_w, fig_h = self._fig.get_size_inches()
687+
fig_w, fig_h = self._fig.bbox.size / self._fig.dpi
688688
x, y, w, h = self.get_position_runtime(axes, renderer)
689689
summed_hs = self.get_vertical_sizes(renderer)
690690
equal_ws = self.get_horizontal_sizes(renderer)

tutorials/toolkits/axes_grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@
331331
332332
See the example,
333333
334-
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axes_divider1_002.png
334+
.. figure:: ../../gallery/axes_grid1/images/sphx_glr_simple_axes_divider1_001.png
335335
:target: ../../gallery/axes_grid1/simple_axes_divider1.html
336336
:align: center
337337
:scale: 50

0 commit comments

Comments
 (0)