question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Heatmap (both go and px) not showing text annotations on Hugo site

See original GitHub issue

Hi, my issue appears to be similar to issue #3527, but on that issue they’re using different environments (Dash and Jupyter). I figured I’d provide more data over here. My use case is creating plotly.py figures in vscode, then exporting the figures as json to Hugo, and calling them inside markdown files via Hugo shortcodes. This flow is working great so far, except for this issue where heatmap text annotations don’t show up in posts.

My environment: Ubuntu 20.04.4 LTS Python 3.9.5 (default, Nov 23 2021, 15:27:38) [GCC 9.3.0] on linux plotly==5.6.0 hugo v0.88.1-5BC54738 linux/amd64 BuildDate=2021-09-04T09:39:19Z VendorInfo=gohugoio VSCode Version: 1.65.2 Commit: c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1 Date: 2022-03-10T15:36:26.048Z Electron: 13.5.2 Chromium: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Linux x64 5.4.0-105-generic

Test case: (from https://plotly.com/python/heatmaps/)

import plotly.graph_objects as go

fig = go.Figure(data=go.Heatmap(
                    z=[[1, 20, 30],
                      [20, 1, 60],
                      [30, 60, 1]],
                    text=[['one', 'twenty', 'thirty'],
                          ['twenty', 'one', 'sixty'],
                          ['thirty', 'sixty', 'one']],
                    texttemplate="%{text}",
                    textfont={"size":20}))

Hugo Config:

 <!-- head tag -->
  {{ if .Params.plotly }}
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
  {{ end }}
<!-- layouts/shortcodes/plotly.html -->
{{ $json := .Get "json" }} 
{{ $height := .Get "height" | default "200px" }}
<div id="{{$json}}" class="plotly" style="height:{{$height}}; margin-top:-1rem;"></div>
<script>
    Plotly.d3.json({{ $json }}, function (err, fig) {
        Plotly.plot('{{$json}}', fig.data, fig.layout, { responsive: true });
    });
</script>
<!-- call from within post.md -->
{{< plotly json="/json/heatmap2.json" height="700px" >}}

My workflow:

  • Create an annotated heatmap fig on a VSCode Python script (using either graph_objects or plotly.express)
  • Create the figure using: fig.show(), fig.write_image("fig.png") and fig.write_json(fig.json")
  • Annotations show perfectly for fig.show(), fig.write_image("fig.png")
  • I copy and paste fig.json in my hugo/static/ folder
  • The heatmap shows, but without annotations, see pic below Thanks for reading. Happy to help with any tests.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rafaelmarinocommented, Apr 12, 2022

Thanks Nicolas, that makes sense. I read through some of that, followed a few links, and I’m happy to report I’ve managed to get it working 😃

For those who stumble upon this thread in the future, here’s what I did:

  1. Update head.html with:
  <script src="https://d3js.org/d3.v7.min.js"></script>
  <script src="https://cdn.plot.ly/plotly-2.11.1.min.js"></script>
  1. Update plotly.html with:
d3.json({{ $json }}).then(function (fig) {
        Plotly.newPlot('{{$json}}', fig.data, fig.layout, { responsive: true });
});
0reactions
shouldseecommented, Oct 9, 2022

This is indeed awkward but we chose this path in order not to impose breaking changes on folks relying on the “latest” URL so we will not be changing the version of Plotly.js that it points to any more. We apologize for the confusion.

Gotcha. Thanks for explaining!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to show text on a heatmap with Plotly? - Stack Overflow
When I run the example interactively, I do indeed get the text labels. But my application is part of a Dash app, and...
Read more >
seaborn heatmap not displaying correctly
I don't know what exactly has caused this. How can I make the annotations and the x/y labels centered again? In both images...
Read more >
Make circular heatmaps - A Bioinformagician
Circular heatmaps are pretty. With circlize package, it is possible to implement circular heatmaps by the low-level function circos.rect() .
Read more >
Analyzing RNA-seq data with DESeq2 - Bioconductor
Abstract. A basic task in the analysis of count data from RNA-seq is the detection of differentially expressed genes.
Read more >
classifieR a flexible interactive cloud-application for functional ...
Single sample annotation of cancer patient samples, ... (E) This page has a detailed table and interactive heatmap (not shown), ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found