-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Conversation
…to the ones used for color images in (e)ps export when using xpdf distillation.
Thanks, seems reasonable to me. Not sure what we can do in the way of testing on this one. |
I can try to provide a minimum example that displays the behavior, don't know if this counts as testing though ;). |
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. |
@mdboom Who can review this? |
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). |
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. |
I would think so. |
@jaschau Can you provide an example that this fixes? I would like to at least see before/after before merging it. |
@tacaswell: See the example at jaschau/gist:5028a44864d916ea5caa. This script should result in a example.eps file with compression artifacts. |
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... |
FIX: compression of grayscale rasterized artists in (e)ps distilled with xpdf.
@jaschau Thank you! |
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.