You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Non-accurate placing of images from plt.imshow in PDF output #2935
I have some problems with non-accurate placing of images created by imshow. Output to PNG works fine, but the squares are rectangular and misaligned with the grid when plotting small squares to PDF (order of magnitude around 1-2 inches for the whole plot). I didn't inspect the contents of PDF, but I suspect that coordinates might be written with too low precision.
Here's a small example (maybe not the minimal possible, but hopefully short enough):
import numpy as np
import matplotlib.pyplot as plt
plt.gcf().set_size_inches([1,1])
a=np.random.rand(20,20)
im = plt.imshow(a, interpolation='nearest', origin='lower', extent=[-2,2,-2,2])
plt.gca().set_xticks(np.arange(-2,2,0.2))
plt.gca().set_yticks(np.arange(-2,2,0.2))
plt.gca().xaxis.set_ticklabels([])
plt.gca().yaxis.set_ticklabels([])
plt.grid(ls=':',lw=0.1,color='white')
plt.savefig('test.pdf')
I don't know enough to be able to judge if the issues cited above are the same, but they certainly seem related or equal.
I'm glad if you find the test useful, but if taken to the "test suite", I would suggest polishing it a bit (remove border and ticks, avoid hardcoding numbers at multiple places, use a well defined 2D function instead of a random number generator, ...)
I think this is fixed in master by #9204 (or maybe other fixes since then). There is still a 1-pixel offset, due to the rasterizing, but I think this is pretty accurate. I'll take the liberty of closing, but feel free to re-open.
Activity
tacaswell commentedon Mar 28, 2014
I strongly suspect that this is the same underlying issue as #2831 and a duplicate of #1441.
WeatherGod commentedon Mar 28, 2014
May I say that I think this is a fantastic test, and when we nail down the
fix, that this code gets added as a test.
mojca commentedon Mar 28, 2014
I don't know enough to be able to judge if the issues cited above are the same, but they certainly seem related or equal.
I'm glad if you find the test useful, but if taken to the "test suite", I would suggest polishing it a bit (remove border and ticks, avoid hardcoding numbers at multiple places, use a well defined 2D function instead of a random number generator, ...)
jklymak commentedon Sep 25, 2017
I think this is fixed in master by #9204 (or maybe other fixes since then). There is still a 1-pixel offset, due to the rasterizing, but I think this is pretty accurate. I'll take the liberty of closing, but feel free to re-open.