Description
Initial discussion started here: http://stackoverflow.com/questions/23490289/matplotlib-shows-different-figure-than-saves-from-the-show-window
Essentially I need to combine a few arrays to make a whole image I want to produce using imshow. So that the arrays do not overlay each other I use masking (as in the example at StackOverflow) or I set some data to None
, so that it is not plotted; I do this:
cmap = matplotlib.cm.get_cmap()
cmap.set_bad('w', 0.0)
See the whole working example:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
data = np.random.random((3000, 3000))
data[np.tril_indices_from(data, 1)] = None
data2 = np.random.random((3000, 3000))
data2[np.triu_indices_from(data2, -1)] = None
cmap = matplotlib.cm.get_cmap()
cmap.set_bad('w', 0.0)
plt.imshow(data, interpolation='none', cmap=cmap)
plt.imshow(data2, interpolation='none', cmap=cmap)
plt.locator_params(nbins=60)
plt.show()
So the thing is, if I look at such image in an interactive window everything looks perfect (e.g. I zoomed into top-left corner, so that the pixels are visible:
If I save the whole image to a file from the Save-dialog of the window, the image gets screwed, so that the pixels are much bigger, than they should (it is a printscreen of Inkscape with opened SVG-file, where I zoomed to approximately the same coordinates):
Same goes to direct saving the image to disk (SVG):
If I use only data, but not data2, the image looks good:
If I save both of them, but change the dpi (e.g. to 900), the image changes and the so-to-say resolution gets better, but the image gets really messy:
You can probably see, that some pixels are distorted. If not, here is a closer zoom into this image:
At the same time you can see, that the white diagonal no more ends and starts in the very corner of the image.
As far as I understand, this is a bug, or at least undocumented behaviour, because I haven't found any mentioning of possibility of such weird effects anywhere. Using such plots (though not randomly generated) is crucial to my research, I would really like this fixed or being pointed out to a solution for this problem.
Please let me know, if you can reproduce such effects and if you need any further information from me.
I use matplotlib 1.3.1 on Ubuntu 14.04 with Python 2.7.6 and Spyder 2.2.5.