8000 Update backend_pdf.py to handle case where rgb is None · matplotlib/matplotlib@1391712 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1391712

Browse files
Tuantacaswell
authored andcommitted
Update backend_pdf.py to handle case where rgb is None
1 parent 74f8af2 commit 1391712

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,11 +1627,11 @@ def check_gc(self, gc, fillcolor=None):
16271627
orig_alphas = getattr(gc, '_effective_alphas', (1.0, 1.0))
16281628

16291629
if gc._rgb is None:
1630-
if gc.get_linewidth() != 0:
1631-
warnings.warn('if rgb is None, ' +
1632-
'linewidth should also be 0')
1633-
# doesn't matter what color here
1634-
gc._rgb = [1, 0, 0, 1]
1630+
# it should not matter what color here
1631+
# since linewidth should be 0
1632+
# unless affected by global settings in rcParams
1633+
# hence setting zero alpha just incase
1634+
gc._rgb = [0, 0, 0, 0]
16351635

16361636
if gc._forced_alpha:
16371637
gc._effective_alphas = (gc._alpha, gc._alpha)

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,16 @@ def psfont(*args, **kwargs):
195195
fig.savefig(tmpfile, format='pdf')
196196

197197

198-
def test_pdf_savefig_when_color_is_none():
199-
backup_params = mpl.rcParams.copy()
200-
mpl.rcParams.update(mpl.rcParamsDefault)
198+
@pytest.fixture(scope='function')
199+
def test_pdf_savefig_when_color_is_none(tempdir_factory):
200+
rcParams['_internal.classic_mode'] = False
201201
plt.subplot()
202202
plt.axis('off')
203203
plt.plot(np.sin(np.linspace(-5, 5, 100)), 'v', c='none')
204-
try:
205-
plt.savefig("figure.pdf", format='pdf')
206-
except Exception:
207-
pytest.fail("Failed to save pdf")
208-
plt.savefig("figure.eps", format='eps')
209-
result = compare_images('figure.pdf', 'figure.eps', 0)
204+
tmpdir_name = str(np.random.randint(100000, 10000000))
205+
actual_image = tempdir_factory.mktemp(tmpdir_name).join('figure.pdf')
206+
expected_image = tempdir_factory.mktemp(tmpdir_name).join('figure.eps')
207+
plt.savefig(str(actual_image), format='pdf')
208+
plt.savefig(str(expected_image), format='eps')
209+
result = compare_images(str(actual_image), str(expected_image), 0)
210210
assert result is None
211-
from os import remove
212-
remove('figure.eps')
213-
remove('figure.pdf')
214-
mpl.rcParams.update(backup_params)

0 commit comments

Comments
 (0)
0