Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Corrupt/invalid PDF and EPS files when saving a logscaled plot made with negative values #1799

Merged
merged 1 commit into from

3 participants

@andrewcollette

This is with matplotlib 1.1.0, via the Pylab interface (I'm using a version supplied with PythonXY):

import pylab as p
import numpy as np

x = np.arange(10)
y = np.arange(10)-1

p.scatter(x,y)
p.xscale('log')
p.yscale('log')

Saving the plot as an EPS or PDF produces an invalid file; when opening the PDF, Adobe Reader says "Path lacks initial MOVETO". PNG output looks fine.

Granted, negative values can't be plotted on a log scale, but creating a bad output file seems like a bug. As a workaround, I now filter my data for negative values before plotting.

@WeatherGod
Collaborator
@andrewcollette

Just tried it with matplotlib 1.2.0 (new install via pip on Linux). When saving a PDF, I get a popup saying "Can only output finite numbers in PDF". When saving EPS, the save completes but the file can't be opened in any EPS viewer I tried.

@mdboom
Owner

Good catch. This seems to be specific to path collections, which is rare on a log plot, so we haven't caught it. Expect a fix shortly.

@mdboom
Owner

@andrewcollette: Would you mind testing the attached patch to confirm that it addresses your issue?

@mdboom mdboom merged commit ff749cb into matplotlib:v1.2.x

1 check passed

Details default The Travis build passed
@HubertHolin HubertHolin referenced this pull request from a commit in HubertHolin/matplotlib
@mdboom mdboom Fix #1799: path collections with NaNs in the path cause exceptions in…
… vector backends.
cd205e0
@mdboom mdboom deleted the mdboom:issue1799 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 7, 2013
  1. @mdboom
This page is out of date. Refresh to see the latest.
View
2  lib/matplotlib/backend_bases.py
@@ -372,6 +372,8 @@ def _iter_collection(self, gc, master_transform, all_transforms,
xp, yp = transform.transform_point((0, 0))
xo = -(xp - xo)
yo = -(yp - yo)
+ if not (np.isfinite(xo) and np.isfinite(yo)):
+ continue
if Nfacecolors:
rgbFace = facecolors[i % Nfacecolors]
if Nedgecolors:
View
28 lib/matplotlib/tests/test_scale.py
@@ -1,12 +1,34 @@
from __future__ import print_function
-from matplotlib.testing.decorators import image_comparison
+from matplotlib.testing.decorators import image_comparison, cleanup
import matplotlib.pyplot as plt
+import numpy as np
+import io
@image_comparison(baseline_images=['log_scales'], remove_text=True)
def test_log_scales():
ax = plt.subplot(122, yscale='log', xscale='symlog')
-
+
ax.axvline(24.1)
- ax.axhline(24.1)
+ ax.axhline(24.1)
+
+
+@cleanup
+def test_log_scatter():
+ """Issue #1799"""
+ fig, ax = plt.subplots(1)
+
+ x = np.arange(10)
+ y = np.arange(10) - 1
+
+ ax.scatter(x, y)
+
+ buf = io.BytesIO()
+ fig.savefig(buf, format='pdf')
+
+ buf = io.BytesIO()
+ fig.savefig(buf, format='eps')
+
+ buf = io.BytesIO()
+ fig.savefig(buf, format='svg')
Something went wrong with that request. Please try again.