PlotlyJS.jl icon indicating copy to clipboard operation
PlotlyJS.jl copied to clipboard

`heatmap` flips rows/columns

Open ssfrr opened this issue 7 years ago • 3 comments

The heatmap plot type is useful for visualizing a matrix, but the cells are all transposed relative to how matrices are represented at the REPL. Additionally it is flipped so that index (1, 1) is at the bottom-left.

For Example:

plot(heatmap(z=reshape(1:12, 3, 4)))

Shows this: screen shot 2016-10-04 at 4 49 36 pm

The plotly.js docs don't seem to specify whether they expect row-major or column-major 2D arrays, but empirically they treat them as row-major. JSON.jl renders 2D matrices as column-major. It's always a tough call to decide when it's worth adding extra processing between PlotlyJS.jl and plotly.js, but in this case the behavior seems to be something of an implementation detail that it would be OK to change.

I'm a little more torn on the origin location (bottom-left vs. top-left) as that's a user-visible change that would make it behave differently than plotly.js.

ssfrr avatar Oct 04 '16 20:10 ssfrr

Thanks for opening this.

I think it probably makes sense to transpose the z matrix for the heat map. That being said, I don't know that PlotlyJS currently has the machinery in place to do this. We'll have to think about what point between creating a trace and displaying a plot is the right place for this type of logic.

I don't think we should try to change the location of the origin.

sglyon avatar Oct 05 '16 11:10 sglyon

Fyi this has been discussed at length and resolved in Plots: https://github.com/tbreloff/Plots.jl/issues?utf8=✓&q=is%3Aissue%20heatmap%20transpose https://github.com/tbreloff/Plots.jl/issues?utf8=%E2%9C%93&q=is%3Aissue%20heatmap%20transpose

You'll need to add 'yflip=true' to also put the origin in the upper-left corner (not the most common use of heatmap for most people).

On Wednesday, October 5, 2016, Spencer Lyon [email protected] wrote:

Thanks for opening this.

I think it probably makes sense to transpose the z matrix for the heat map. That being said, I don't know that PlotlyJS currently has the machinery in place to do this. We'll have to think about what point between creating a trace and displaying a plot is the right place for this type of logic.

I don't think we should try to change the location of the origin.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/spencerlyon2/PlotlyJS.jl/issues/80#issuecomment-251648419, or mute the thread https://github.com/notifications/unsubscribe-auth/AA492iqxBf_QfdcmRROLDY0_jcNFr6o-ks5qw4jHgaJpZM4KOJu5 .

tbreloff avatar Oct 05 '16 11:10 tbreloff

Thanks @tbreloff -- that's very helpful.

sglyon avatar Oct 05 '16 11:10 sglyon