|
6 | 6 | from types import SimpleNamespace
|
7 | 7 | import warnings
|
8 | 8 |
|
| 9 | +import numpy as np |
| 10 | +import pytest |
| 11 | +from PIL import Image |
| 12 | + |
9 | 13 | import matplotlib as mpl
|
10 | 14 | from matplotlib import cbook, rcParams
|
11 | 15 | from matplotlib._api.deprecation import MatplotlibDeprecationWarning
|
|
16 | 20 | import matplotlib.pyplot as plt
|
17 | 21 | import matplotlib.dates as mdates
|
18 | 22 | import matplotlib.gridspec as gridspec
|
19 |
| -import numpy as np |
20 |
| -import pytest |
21 | 23 |
|
22 | 24 |
|
23 | 25 | @image_comparison(['figure_align_labels'], extensions=['png', 'svg'],
|
@@ -496,6 +498,24 @@ def test_savefig_backend():
|
496 | 498 | fig.savefig("test.png", backend="pdf")
|
497 | 499 |
|
498 | 500 |
|
| 501 | +@pytest.mark.parametrize('backend', ['Agg', 'Cairo']) |
| 502 | +def test_savefig_pixel_ratio(backend): |
| 503 | + plt.switch_backend(backend) |
| 504 | + |
| 505 | + fig = plt.figure() |
| 506 | + with io.BytesIO() as buf: |
| 507 | + fig.savefig(buf, format='png') |
| 508 | + ratio1 = Image.open(buf) |
| 509 | + |
| 510 | + fig = plt.figure() |
| 511 | + fig.canvas._set_device_pixel_ratio(2) |
| 512 | + with io.BytesIO() as buf: |
| 513 | + fig.savefig(buf, format='png') |
| 514 | + ratio2 = Image.open(buf) |
| 515 | + |
| 516 | + assert ratio1.size == ratio2.size |
| 517 | + |
| 518 | + |
499 | 519 | def test_figure_repr():
|
500 | 520 | fig = plt.figure(figsize=(10, 20), dpi=10)
|
501 | 521 | assert repr(fig) == "<Figure size 100x200 with 0 Axes>"
|
|
0 commit comments