Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ca6991d

Browse filesBrowse files
author
Travis CI
committed
Merge branch 'master' of https://github.com/matplotlib/matplotlib into issue-8236-dev
2 parents 0e8d476 + f254b3b commit ca6991d
Copy full SHA for ca6991d

File tree

Expand file treeCollapse file tree

4 files changed

+87
-21
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+87
-21
lines changed

‎.travis.yml

Copy file name to clipboardExpand all lines: .travis.yml
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,16 @@ install:
131131
codecov \
132132
coverage \
133133
$CYCLER \
134+
$DATEUTIL \
134135
$NOSE \
135136
$NUMPY \
136137
$PANDAS \
137138
codecov \
138139
coverage \
139140
pillow \
140141
$PYPARSING \
141-
$DATEUTIL \
142-
$SPHINX
142+
$SPHINX \
143+
tornado
143144
# GUI toolkits are pip-installable only for some versions of Python so
144145
# don't fail if we can't install them. Make it easier to check whether the
145146
# install was successful by trying to import the toolkit (sometimes, the

‎lib/matplotlib/backends/backend_cairo.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_cairo.py
+31-2Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,26 @@
4747
from matplotlib.font_manager import ttfFontProperty
4848

4949

50+
def _premultiplied_argb32_to_unmultiplied_rgba8888(buf):
51+
"""
52+
Convert a premultiplied ARGB32 buffer to an unmultiplied RGBA8888 buffer.
53+
54+
Cairo uses the former format, Matplotlib the latter.
55+
"""
56+
rgba = np.take( # .take() ensures C-contiguity of the result.
57+
buf,
58+
[2, 1, 0, 3] if sys.byteorder == "little" else [1, 2, 3, 0], axis=2)
59+
rgb = rgba[..., :-1]
60+
alpha = rgba[..., -1]
61+
# Un-premultiply alpha. The formula is the same as in cairo-png.c.
62+
mask = alpha != 0
63+
for channel in np.rollaxis(rgb, -1):
64+
channel[mask] = (
65+
(channel[mask].astype(int) * 255 + alpha[mask] // 2)
66+
// alpha[mask])
67+
return rgba
68+
69+
5070
class ArrayWrapper:
5171
"""Thin wrapper around numpy ndarray to expose the interface
5272
expected by cairocffi. Basically replicates the
@@ -436,15 +456,24 @@ class FigureCanvasCairo(FigureCanvasBase):
436456
supports_blit = False
437457

438458
def print_png(self, fobj, *args, **kwargs):
459+
self._get_printed_image_surface().write_to_png(fobj)
460+
461+
def print_rgba(self, fobj, *args, **kwargs):
439462
width, height = self.get_width_height()
463+
buf = self._get_printed_image_surface().get_data()
464+
fobj.write(_premultiplied_argb32_to_unmultiplied_rgba8888(
465+
np.asarray(buf).reshape((width, height, 4))))
466+
467+
print_raw = print_rgba
440468

469+
def _get_printed_image_surface(self):
470+
width, height = self.get_width_height()
441471
renderer = RendererCairo(self.figure.dpi)
442472
renderer.set_width_height(width, height)
443473
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
444474
renderer.set_ctx_from_surface(surface)
445-
446475
self.figure.draw(renderer)
447-
surface.write_to_png(fobj)
476+
return surface
448477

449478
def print_pdf(self, fobj, *args, **kwargs):
450479
return self._save(fobj, 'pdf', *args, **kwargs)

‎lib/matplotlib/tests/test_backends_interactive.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backends_interactive.py
+41-8Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import importlib
22
import os
3-
from subprocess import Popen
3+
import signal
4+
import subprocess
45
import sys
6+
import time
7+
import urllib.request
58

69
import pytest
710

11+
import matplotlib as mpl
12+
813

914
# Minimal smoke-testing of the backends for which the dependencies are
1015
# PyPI-installable on Travis. They are not available for all tested Python
@@ -17,6 +22,7 @@ def _get_testable_interactive_backends():
1722
(["PyQt5"], "qt5agg"),
1823
(["cairocffi", "PyQt5"], "qt5cairo"),
1924
(["tkinter"], "tkagg"),
25+
(["wx"], "wx"),
2026
(["wx"], "wxagg")]:
2127
reason = None
2228
if not os.environ.get("DISPLAY"):
@@ -30,20 +36,47 @@ def _get_testable_interactive_backends():
3036

3137
_test_script = """\
3238
import sys
33-
from matplotlib import pyplot as plt
39+
from matplotlib import pyplot as plt, rcParams
40+
rcParams.update({
41+
"webagg.open_in_browser": False,
42+
"webagg.port_retries": 1,
43+
})
3444
3545
fig = plt.figure()
3646
ax = fig.add_subplot(111)
37-
ax.plot([1,2,3], [1,3,1])
47+
ax.plot([1, 2], [2, 3])
3848
fig.canvas.mpl_connect("draw_event", lambda event: sys.exit())
3949
plt.show()
4050
"""
51+
_test_timeout = 10 # Empirically, 1s is not enough on Travis.
4152

4253

4354
@pytest.mark.parametrize("backend", _get_testable_interactive_backends())
4455
@pytest.mark.flaky(reruns=3)
45-
def test_backend(backend):
46-
proc = Popen([sys.executable, "-c", _test_script],
47-
env={**os.environ, "MPLBACKEND": backend})
48-
# Empirically, 1s is not enough on Travis.
49-
assert proc.wait(timeout=10) == 0
56+
def test_interactive_backend(backend):
57+
subprocess.run([sys.executable, "-c", _test_script],
58+
env={**os.environ, "MPLBACKEND": backend},
59+
check=True, # Throw on failure.
60+
timeout=_test_timeout)
61+
62+
63+
@pytest.mark.skipif(os.name == "nt", reason="Cannot send SIGINT on Windows.")
64+
def test_webagg():
65+
pytest.importorskip("tornado")
66+
proc = subprocess.Popen([sys.executable, "-c", _test_script],
67+
env={**os.environ, "MPLBACKEND": "webagg"})
68+
url = "http://{}:{}".format(
69+
mpl.rcParams["webagg.address"], mpl.rcParams["webagg.port"])
70+
timeout = time.perf_counter() + _test_timeout
71+
while True:
72+
try:
73+
conn = urllib.request.urlopen(url)
74+
break
75+
except urllib.error.URLError:
76+
if time.perf_counter() > timeout:
77+
pytest.fail("Failed to connect to the webagg server.")
78+
else:
79+
continue
80+
conn.close()
81+
proc.send_signal(signal.SIGINT)
82+
assert proc.wait(timeout=_test_timeout) == 0

‎tutorials/colors/colorbar_only.py

Copy file name to clipboardExpand all lines: tutorials/colors/colorbar_only.py
+12-9Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
1111
:class:`~matplotlib.colorbar.ColorbarBase` derives from
1212
:mod:`~matplotlib.cm.ScalarMappable` and puts a colorbar in a specified axes,
13-
so it has everything needed for a standalone colorbar. It can be used as is to
14-
make a colorbar for a given colormap and does not need a mappable object like
13+
so it has everything needed for a standalone colorbar. It can be used as-is to
14+
make a colorbar for a given colormap; it does not need a mappable object like
1515
an image. In this tutorial we will explore what can be done with standalone
1616
colorbar.
1717
@@ -22,14 +22,15 @@
2222
will be used. Then create the colorbar by calling
2323
:class:`~matplotlib.colorbar.ColorbarBase` and specify axis, colormap, norm
2424
and orientation as parameters. Here we create a basic continuous colorbar
25-
with ticks and labels. More information on colorbar api can be found
26-
`here <https://matplotlib.org/api/colorbar_api.html>`.
25+
with ticks and labels. More information on the colorbar API can be found
26+
`here <https://matplotlib.org/api/colorbar_api.html>`_.
2727
"""
2828

2929
import matplotlib.pyplot as plt
3030
import matplotlib as mpl
3131

32-
fig, ax = plt.subplots()
32+
fig, ax = plt.subplots(figsize=(6, 1))
33+
fig.subplots_adjust(bottom=0.5)
3334

3435
cmap = mpl.cm.cool
3536
norm = mpl.colors.Normalize(vmin=5, vmax=10)
@@ -62,7 +63,8 @@
6263
# *extend*, you must specify two extra boundaries. Finally spacing argument
6364
# ensures that intervals are shown on colorbar proportionally.
6465

65-
fig, ax = plt.subplots()
66+
fig, ax = plt.subplots(figsize=(6, 1))
67+
fig.subplots_adjust(bottom=0.5)
6668

6769
cmap = mpl.colors.ListedColormap(['red', 'green', 'blue', 'cyan'])
6870
cmap.set_over('0.25')
@@ -85,10 +87,11 @@
8587
# --------------------------------------
8688
#
8789
# Here we illustrate the use of custom length colorbar extensions, used on a
88-
# colorbar with discrete intervals. To make the length of each extension same
89-
# as the length of the interior colors, use ``extendfrac='auto'``.
90+
# colorbar with discrete intervals. To make the length of each extension the
91+
# same as the length of the interior colors, use ``extendfrac='auto'``.
9092

91-
fig, ax = plt.subplots()
93+
fig, ax = plt.subplots(figsize=(6, 1))
94+
fig.subplots_adjust(bottom=0.5)
9295

9396
cmap = mpl.colors.ListedColormap(['royalblue', 'cyan',
9497
'yellow', 'orange'])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.