# Share colormap for Plotly Stacked Heatmaps

**URL:** <https://discourse.julialang.org/t/share-colormap-for-plotly-stacked-heatmaps/84547>\
**Category:** Visualization\
**Tags:** question, dataframes, plotlyjs\
**Created:** [July 20, 2022, 3:59pm UTC](https://discourse.julialang.org/t/share-colormap-for-plotly-stacked-heatmaps/84547 "2022-07-20T15:59:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KaiserDan37](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kaiserdan37/32/38136_2.png) [@KaiserDan37](https://discourse.julialang.org/u/KaiserDan37)\
**Post date:** [July 20, 2022, 3:59pm UTC](https://discourse.julialang.org/t/share-colormap-for-plotly-stacked-heatmaps/84547/1 "2022-07-20T15:59:28Z")

</div>

Hello everyone,

I am creating a faceted plot using the Plotly backend and and having trouble with stacking subplots of heatmaps. Specifically, the colorbars appear to overlap and I would prefer if they shared a single colorbar. I have included a screenshot of the current behavior.

 ![Screenshot from 2022-07-20 11-40-13](https://global.discourse-cdn.com/julialang/original/3X/6/e/6e3444e8f8f95721d00577b5e130d559aa592a1e.png)

Here is the code I am currently using (some dummy data included to reproduce the error without taking too long to do the filtering) - Note some minor label and value changes when I created the dummy data versus my project data.

```julia
# Example set up
using Dataframes
using Plotly

# Dummy data
_a = DataFrame(Dict{String, Any}(
    "alpha" => [1,1,1,1,2,2,1,1,1,1,2,2],
    "beta" => [2,2,3,3,3,3,2,2,3,3,3,3],
    "aggregation" => ["OR","OR","OR","OR","OR","OR","XOR","XOR","XOR","XOR","XOR","XOR"],
    "edit_distance" => [0.029, 0.030, 0.036, 0.036, 0.036, 0.037, 0.033, 0.033, 0.039, 0.037, 0.053, 0.054]
))

# Heatmap, layer pairs vs edit distance, restricted to XOR aggregation
p2 = heatmap(filter(row -> row.aggregation == "XOR", _a),
    x=:alpha, y=:beta, z=:edit_distance,
)

# Heatmap, layer pairs vs edit distance, restricted to OR aggregation
p3 = heatmap(filter(row -> row.aggregation == "OR", _a),
    x=:alpha, y=:beta, z=:edit_distance,
)

# Faceted plot
p = make_subplots(
    rows=2, cols=1, shared_xaxes=true, shared_yaxes=true,
    subplot_titles=["XOR aggregation" "OR aggregation"]
)

## Adding panels
add_trace!(p, p2, row=2, col=1)
add_trace!(p, p3, row=1, col=1)

## Formating parent plot
relayout!(p, title_text="Example for Forum")

# Plotting faceted plot
p

```

I’ve perused the Plotly Julia references ([Heatmap traces](https://plotly.com/julia/reference/heatmap/) and [Subplots](https://plotly.com/julia/subplots/) in particular) and so far have not quite been able to find what I want. In the end, I want a single shared colorbar that describes the heatmaps in _both_ panels, like the below screenshot EDIT: New users can only post one embedded media, I am told, so look somewhere on this page for it - the colorbar of the first example there is what I mean. EDIT 2: New users can only put two links in their posts, so just google “Heatmaps Julia Plotly” and you will find it 🤦‍♂️

Any help would be greatly appreciated!

P.S. This is my first time posting here! I looked through the forums to ensure this wasn’t a duplicate, but to the best of my quick search I didn’t find anything. I have gotten a lot of help from this forum with other issues before and I am excited to finally start participating myself. Time to start looking where I can contribute solutions, too 👀

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [July 20, 2022, 5:07pm UTC](https://discourse.julialang.org/t/share-colormap-for-plotly-stacked-heatmaps/84547/2 "2022-07-20T17:07:10Z")

</div>

See this thread [https://discourse.julialang.org/t/plotting-heatmap-plotlyjs-double-bar/80199](https://discourse.julialang.org/t/plotting-heatmap-plotlyjs-double-bar/80199).

---

<div class="post-metadata">

**Author:** ![KaiserDan37](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kaiserdan37/32/38136_2.png) [@KaiserDan37](https://discourse.julialang.org/u/KaiserDan37)\
**Post date:** [July 21, 2022, 1:39pm UTC](https://discourse.julialang.org/t/share-colormap-for-plotly-stacked-heatmaps/84547/3 "2022-07-21T13:39:21Z")

</div>

Awesome, looks like I didn’t do a thorough enough job searching. Thank you!
