# Hi evrybody, I'm trying to overlay a scatter plot with a heatmap using Plots.jl bu

**URL:** https://discourse.julialang.org/t/hi-evrybody-im-trying-to-overlay-a-scatter-plot-with-a-heatmap-using-plots-jl-bu/56067
**Category:** General Usage
**Created:** [February 26, 2021, 6:56am UTC](https://discourse.julialang.org/t/hi-evrybody-im-trying-to-overlay-a-scatter-plot-with-a-heatmap-using-plots-jl-bu/56067 "2021-02-26T06:56:28Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)
#### Post date: [February 26, 2021, 6:56am UTC](https://discourse.julialang.org/t/hi-evrybody-im-trying-to-overlay-a-scatter-plot-with-a-heatmap-using-plots-jl-bu/56067/1 "2021-02-26T06:56:28Z")

</div>

Hi evrybody, I’m trying to overlay a scatter plot with a heatmap using Plots.jl but I can’t figure it out how heatmap is oriented (or find much documentation on the plots.jl heatmap function).  
The heat map seems turned by 90 degrees (or transposed, transposing the heat-value matrix seems to fix the issue). Maybe it fills row-wise from the top left corner while reading the array column-wise?  
Here is an example showing the problem

```julia
n_points = 100
w = [4, 0.7, -2.3]
σ(a) = 1 / (1 + exp(-a))
x_data = randn(n_points) 
y_data = randn(n_points) 
y_data[1:n_points÷2] .+= 8
labels = [round(σ(p'*w)) for p in eachrow([ones(n_points) x_data y_data])]
plt = scatter(x_data, y_data, zcolor=labels)
xs = range(-4, 3, length=100)
ys = range(-4, 11, length=100)
grid = [[1, x, y] for x in xs, y in ys]
heat = [σ(p'*w) for p in grid]
heatmap!(plt, xs, ys, heat, alpha=0.5)
# this doesn't look right

# now transpose and it does
plt = scatter(x_data, y_data, zcolor=labels)
heatmap!(plt, xs, ys, transpose(heat), alpha=0.5)

```

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1614322489458500?thread_ts=1614322489.458500&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

### Author: ![briochemc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/briochemc/32/4209_2.png) [@briochemc](https://discourse.julialang.org/u/briochemc)
#### Post date: [February 26, 2021, 10:24am UTC](https://discourse.julialang.org/t/hi-evrybody-im-trying-to-overlay-a-scatter-plot-with-a-heatmap-using-plots-jl-bu/56067/2 "2021-02-26T10:24:00Z")

</div>

Well, you’ve solved your question, but FWIW, the reasoning is that heatmap’s orientation was made to match precedence (matplotlib IIRC), so the first dimension is the y axis and the second dimension is the x axis. This way, for example, taking a heatmap of a 3×5 matrix, as in

```julia
julia> heatmap(randn(3,5))

```

produces a 3×5 matrix-looing plot, i.e., something like

 ![Screen Shot 2021-02-26 at 9.21.25 pm](https://global.discourse-cdn.com/julialang/original/3X/5/0/505458b9e5cd0d6dab1638cd2915a0a6eb2c9f43.jpeg)

---

<div class="post-metadata">

### Author: ![imLew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/imlew/32/22324_2.png) [@imLew](https://discourse.julialang.org/u/imLew)
#### Post date: [February 26, 2021, 12:41pm UTC](https://discourse.julialang.org/t/hi-evrybody-im-trying-to-overlay-a-scatter-plot-with-a-heatmap-using-plots-jl-bu/56067/3 "2021-02-26T12:41:09Z")

</div>

OP here.  
Thanks for your answer, that background is exactly why I asked.  
What I had did seem to fix it but it might have been a case of two mistakes cancelling each other out. It’s good to know that transposing the heatmap is the general solution to my problem.
