-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
Resolved: Heatmap transposes matrices #205
Comments
Hm, that should be unrelated! I thought on master I made sure, that the values from the axis map to the right pixels... let me check! |
(unrelated, because putting it on a mesh could yet have another messed up mapping -.-) |
This is on master btw |
brightest needs to be |
waitaminute - is Plots heatmap broken then? :-O |
Ah, no @SimonDanisch the x axis is the horizontal one, but you're using y as horizontal in your calculation. it should be |
oh, subtle^^ guess i need to change the orientation yet another time :-D |
I'm not sure but I think it's debatable, whether the x axis should correspond to the rows (Makie) or columns (Plots) of a matrix. Here's the behaviour for a simple matrix in different plotting packages: julia> mat = [1 0; 2 0; 3 0]
3×2 Array{Int64,2}:
1 0
2 0
3 0
julia> heatmap(mat) PlotlyJS matches the Makie behaviour: julia> heatmap(z = mat) Python's Seaborn e.g. looks like this: import numpy as np
import seaborn as sns
mat = np.matrix('1 0; 2 0; 3 0')
sns.heatmap(mat) which is the same as Matplotlib's import matplotlib.pyplot as plt
plt.imshow(mat) I think both, Makie/PlotlyJS and and Matplotlib/Seaborn, make sense in their way:
I'm not sure if there is a "correct" way to do this, but I think the hybrid Plots implementation (match x axis with columns, but avoid y axis flipping) is not as clear and less preferable. What do you say? |
There's definitely something wrong with the Makie example, though, considering the axes tick labels. |
I disagree. The call should be It also would make it much more difficult to e.g. plot scatter plot points / contours on top of a heatmap if the axes were non-traditional here (something I use all the time, e.g. for maps). Also, Plots' implementation is not some hybrid implementation, it's the default in GR, in R and a number of other plotting packages. |
Very good point. |
I agree with you. The Plots implementation does make sense and |
@SimonDanisch , @daschw I still think x must correspond to x and y correspond to y, and values of x and y increase to the right and upwards. But that is also the case in the current Makie / PlotlyJS implementation. It's just a question of how you define the relationship. Looking at Simon's and my example above:
I know this example doesn't prove anything, but just shows that the Makie interpretation is as intuitive as my first one, that Also, I had to go back and check the claims I made about GR and Makie, and they are false. R does the same as PlotlyJS/Makie: While GR lives in a world of it's own: Matlab, FWIW, does what matplotlib does. So, my conclusion is that I've been suffering from Plots' Stockholm syndrome and not thinking this all the way through. And that we should close this issue and keep the Makie implementation as it is. The second question then is - should we change Plots to align with Makie? |
Hm, Makie has one transpose and one axis flip compared to the terminal representation of a matrix: [1 0
2 0
3 0] vs [ 0 0 0
1 2 3] so all other things equal, if we can get closer to the terminal representation that would be good. The |
The correspondence to terminal representation is what controls the differences between matplotlib(seaborn)/matlab on the one hand, and makie/plotlyjs/R on the other. But that flip IS necessary in order for allowing adding other plots to the scene in the same coordinate system, and that is crucial IMHO. |
note that an image in julia should basically be displayed the same as a matrix in the terminal. While a heatmap is not really the same thing as a pixel array, I tend to think of it as somewhat similar. For example if I want to visualize a matrix of numbers I'd like to say "imagify this matrix using some nice colormapping". The transpose throws me off a little. then again, the "x, y, z" instead of "y, x, z" argument is also pretty convincing. |
FWIW I now think of the Plots' and Makie' versions as equally good (there are advantages with both), with the Makie having the advantage(?) of being shared by other plotting packages. |
That argument makes sense to me. I think as long as its reasonably simple to achieve the "matrix-showing" usecase (be it by using a setting or by transposing the data) everyone is served |
Can't we have both, a |
I might also switch sides: in plotting a vector, going from |
That's a very good, intuitive way to look at it. We agree then that the current Makie behaviour makes sense? I can't believe that Michael made me change my mind twice 😀 So, should we also change this in Plots? That would really be a breaking change. |
Well @daschw that's because you made me change my mind so we're even :-) And I agree with @Evizero that there should be a userfacing keyword to transpose the matrix, as well as of course a y/xflip argument, so discerning users can customize. And with @daschw (again) that there should be a Finally, I'd be fine with either or, changing Plots or leaving as is. The path of least resistance is to leave as is, we just need to keep this in mind when porting recipes. |
Least resistance sounds good. |
Right - let's keep it open as a reminder to implement the transpose/flip |
thanks for the detective work here :) |
This is a more general issue than heatmaps in plotting packages, it seems to come up anywhere a matrix is converted to an image. A matrix converted to an image with Images.jl and in Cairo/Gtk show rotated and as in the REPL respectively. Images.jl and ArchGDAL.jl disagree on which way to import images to matrix from a raster file. It might be good to have a general discussion across Julia packages for this sometime... |
Notice that the axes in @daschw's makie plot above are not correct - the heatmap is 2 blocks wide and 3 blocks tall, but the axes are showing 3 blocks wide and 2 blocks tall. edit: whoops, just noticed that @daschw brought up the same issue with the axes ticks |
I just ran into the problem that the axis scales are flipped. In @daschw's plot, the X axis should go from 0 to 3, and the Y axis should go from 0 to 2. |
If you swap I'm not sure that's the right fix, though. (I don't follow the code very well.) |
That seems like a reasonable fix - the idea is that we want to interpret the |
I think all heatmap issues should be fixed! |
Sorry, I'm confused. Is there an upstream fix (in AbstractPlotting) that we are waiting for? The axes are still flipped relative to the image in master. |
Not to sound snarky, but I think you would not be confused if you read the whole issue. |
FWIW, I very much like the way that
However we still have the fact that images appear rotated when naively loaded from file using |
I'm updating the worldclim example to 1.0 and fixing it, and ran into this issue:
(note that the matrix format in the example is a bit funky in both examples).
I have a strong feeling this is the source of the issues described in #137
The text was updated successfully, but these errors were encountered: