Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compression of grayscale rasterized images when using (e)ps distilled with xpdf. #4208

Merged
merged 1 commit into from
Jun 17, 2015

Conversation

jaschau
Copy link
Contributor

@jaschau jaschau commented Mar 9, 2015

When exporting figures containing rasterized grayscale images to eps, the resulting files show strange compression artifacts when distillation with xpdf is used. In particular, the above problem occurs whenever imshow is used in conjunction with grayscale colormaps. The change below makes matplotlib use the same compression and filter settings for both rasterized grayscale images and color images when using (e)ps distilled with xpdf. See issue description at #4207.

…to the ones used for color images in (e)ps export when using xpdf distillation.
@tacaswell
Copy link
Member

Thanks, seems reasonable to me.

Not sure what we can do in the way of testing on this one.

@jaschau
Copy link
Contributor Author

jaschau commented Mar 10, 2015

I can try to provide a minimum example that displays the behavior, don't know if this counts as testing though ;).

@tacaswell
Copy link
Member

Even if you only provide an example that would be a good start. I am a bit hesitant to merge this with out a clear example of where this has an effect and am worried about unintended side-effects.

@tacaswell
Copy link
Member

@mdboom Who can review this?

@mdboom
Copy link
Member

mdboom commented Apr 13, 2015

I've spent a lot of time spelunking in PostScript, and this seems reasonable to me as well. I'd say merge it. Only possible negative side effect may be when using a GhostScript version that doesn't support those arguments, but it's a little hard to tell how long those have been around (I'd wager to guess a long time).

@tacaswell
Copy link
Member

If the issues is version of ghostscript which don't support this, then shouldn't the color version also barf so this doesn't make anything worse pre-say.

@mdboom
Copy link
Member

mdboom commented Apr 13, 2015

I would think so.

@tacaswell
Copy link
Member

@jaschau Can you provide an example that this fixes? I would like to at least see before/after before merging it.

@jaschau
Copy link
Contributor Author

jaschau commented Apr 16, 2015

@tacaswell: See the example at jaschau/gist:5028a44864d916ea5caa. This script should result in a example.eps file with compression artifacts.

@tacaswell
Copy link
Member

Example code:

import numpy as np
from matplotlib import rcParams
# use tex+xpdf distillation and a greyscale colormap
rcParams.update({'text.usetex': True, 'ps.usedistiller': 'xpdf',
                 'image.cmap': 'Greys'})
import matplotlib.pyplot as plt

# generate some data to display
x = np.linspace(-0.5, 0.5, 100, endpoint=False)
y = np.linspace(0, 5, 100, endpoint=False)

gamma = 0.1

X, Y = np.meshgrid(x, y)
# generates parabolas of the form y = (x+m)**2 with a Lorentzian broadening
# m are integers
Z = sum([gamma**2/((Y - (X+m)**2)**2 + gamma**2) for m in xrange(-4, 4)])
# use of interpolation='none' results in a more pixelated image which leads 
# to stronger compression artifacts
plt.imshow(Z, origin='lower', aspect='auto', interpolation='none',
    extent=[x.min(), x.max(), y.min(), y.max()])
plt.savefig(r'example.eps')

plt.show()

This should probably end up as a test, but we don't have any eps tests...

tacaswell added a commit that referenced this pull request Jun 17, 2015
FIX: compression of grayscale rasterized artists in (e)ps distilled with xpdf.
@tacaswell tacaswell merged commit 0552724 into matplotlib:master Jun 17, 2015
@tacaswell
Copy link
Member

@jaschau Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants