-
Notifications
You must be signed in to change notification settings - Fork 22
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
workaround for low dpi when rasterizing (pcolormesh saved as pdf) #19
Comments
Are you running into this issue for a real use case? |
here is a MWE to reproduce the issue I am facing. import numpy as np
import matplotlib.pyplot as plt
data = np.arange(25).reshape(5, 5)
for backend in ['pdf', 'module://mplcairo.base']:
plt.switch_backend(backend)
fig, ax = plt.subplots(figsize=(3, 2.5), constrained_layout=True)
im = ax.pcolormesh(data)
cbar = fig.colorbar(im)
im.set_rasterized(True)
cbar.solids.set_rasterized(True)
fig.savefig(f'backend_{backend.split("//")[-1]}_dpi300.pdf', dpi=300)
fig.savefig(f'backend_{backend.split("//")[-1]}_dpi72.pdf', dpi=72) backend_pdf_dpi72.pdf Looks like mplcairo is always going for 72 dpi (and also causing issue with the rasterized image overflowing the boundaries of axes and colorbar). I forgot to add that I am using mplcairo v0.2 installed from pypi, matplotlib v3.1.2 (conda-forge) |
I think that the following line is causing the issue. I have created a PR to fix it. (My apologies in advance if I am trivializing the issue but this just feels like an inadvertent oversight). Line 245 in a54ace5
def _print_method(self, renderer_factory,
path_or_stream, *, metadata=None, dpi=72, **kwargs):
_check_print_extra_kwargs(**kwargs)
self.figure.set_dpi(72) # This should be self.figure.set_dpi(dpi) |
No need to apologize when you're proposing a fix :) (though it does look like the PR CI is failing -- let's continue the discussion there) |
matplotlib/matplotlib#16268 (comment) may be related. |
https://github.com/matplotlib/mplcairo/blob/master/ISSUES.rst mentions that there is an issue with "Invalid dpi manipulations in vector output". Is there an easy workaround for this?
Also, thanks for developing this backend! I don't understand all the details of how fonts are handled internally but mplcairo seems to be giving me better looking text!
The text was updated successfully, but these errors were encountered: