-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
DPI-connected bug of imshow when using multiple masked arrays #3057
Comments
This is probably related to several other issues (see bugs connected with #3054). Try setting the dpi of your viewer to 72 or writing a |
@tacaswell how do I set the dpi of my viewer to 72? |
You have to make sure you use |
No problem. Yeah, I call |
I don't really understand what is going on here, but
I suspect that there is beating going on between the pixelated data and the rasterization. Some times adjacent pixels in the saved image fall in the same pixel of the input data, but most of the time each saved pixel gets it's own data pixel (see https://en.wikipedia.org/wiki/Moiré_pattern). I am not sure I understand the diagonal issue, but I think the above explains the non-square pattern. I am inclined to close this as not a bug. Things are behaving correctly and the best they can under the given input parameters. |
@tacaswell Yeah, thank you for such a thorough explanation. I agree it might be happening because of such effects and that even it might not be a bug (though I don't really think so - plotting image of the same resolution with the same dpi, but from a single matrix doesn't cause such weird things), but in that case I would really like to know how to plot such data with imshow in matplotlib. Maybe there is a way to calculate the required dpi or smth else. |
@phyla, is the intention to have an svg file with 9,000,000 pixels in it? With no loss of information, so that when you zoom in, you see each pixel? It will be a big file. When not zoomed in, it will be up to the renderer to decide how to handle its inability to show all the pixels. |
@efiring Yes, that is the intention. And it works fine with single image without any fancy dpi calculations, and the file is not too big after that. |
Aha! Superimposing images triggers a compositing operation in the draw method, which is defeating the 'none' interpolation by doing its own calculation of the grid. It is not immediately clear to me whether this can be fixed reasonably easily; if so, it would presumably be only in the special case like yours where the images are identical in grid and extents. |
What do you mean by compositing in a numpy array? To combine images in a single array? The thing is they might need a different scale of a colormap, so that they are both drawn with the same colour interval, and I would prefer not to change their values, so that it is possible to see the original signal intensity... |
Yes, combine in a single array. If they need to be scaled differently, then use a suitable scaling transformation for each chunk before combining them. You could use a Normalize instance to do this, one instance per chunk, so it would be the same operation as occurs when you call imshow twice. You can get exactly the same result, very easily and efficiently. Check out the colors.Normalize class. |
Thank you for the idea with Normalize, I didn't know about that nice function, should be useful! I will try it out. |
re-milestoned to 1.4.x as there is something subtle going on at the bottom of the rendering stack, this is a corner case, and there is an acceptable work-around. |
Sorry to come so late to the discussion -- you can set the rcParam |
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:See the whole working example:
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.
The text was updated successfully, but these errors were encountered: