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.

Rendering any math prevents plotly plots from rendering

See original GitHub issue

Describe the bug

context When I write a python notebook with Latex-style math (\begin{align*} \end{align*} or dollar sign math) in a cell above, my plotly figures in a cell below in the same notebook fail to render. They take up the exact space I expect them to, only its white space with nothing there.

I know this is the issue because once I remove the Latex-style math from my notebook, the page renders my plotly figures just fine.

expectation I expected both rendered math and plotly plots in the same notebook to render properly.

bug But instead only the math block renders.

A screenshot of my math block: image

Here is a screenshot where I expect my plot: image

Here’s my _config.yml file:

# Book settings
# Learn more at https://jupyterbook.org/customize/config.html

title: title
author: authors
logo: images/favicon.png
copyright: "2022"

# Ignore files not named in too
only_build_toc_files: true

# Force re-execution of notebooks on each build.
# See https://jupyterbook.org/content/execute.html
execute:
  execute_notebooks: 'cache'
  # execute_notebooks: "force"
  timeout: 10000
  allow_errors: true

# Parsing math blocks
parse:
  myst_enable_extensions:
    # don't forget to list any other extensions you want enabled,
    # including those that are enabled by default!
    - amsmath
# Define the name of the latex output file for PDF builds
latex:
  latex_documents:
    targetname: book.tex

# Add a bibtex file so that we can create citations
#bibtex_bibfiles:
#  - references.bib

# Information about where the book exists on the web
repository:
  url: https://github.com/richardye101/repo  # Online location of your book
  path_to_book: ../content  # Optional path to your book, relative to the repository root
  branch: main  # Which branch of the repository should be used when creating links (optional)

# Add GitHub buttons to your book
# See https://jupyterbook.org/customize/config.html#add-a-link-to-your-repository
html:
  favicon: "images/favicon.png"
  use_issues_button: true
  use_repository_button: true

# Plotly
sphinx:
  config:
    html_js_files:
    - https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js

problem This is a problem for people with would like to build pages with both Latex-style math and render plotly plots on the same page because it doesn’t work.

Reproduce the bug

  1. Create a notebook with a Latex-style math block in a markdown cell like so:
\begin{align*}
\sum^n_{i=1} x 
\end{align*}

or

$ x = 1$

or

$$
\sum^n_{i=1} x
$$
  1. Import and use plotly to create an interactive plot in a code cell below:
import plotly.express as px
from sklearn import datasets
from sklearn.decomposition import PCA

iris = datasets.load_iris()
X = iris.data
y = iris.target
pca = PCA(n_components = 3)
pca_embedding = pca.fit_transform(X)
pca_embedding = pd.DataFrame(pca_embedding, index = y)

fig = px.scatter(pca_embedding, x =0 , y = 1, hover_data={"species": pca_embedding.index},
                     color = pca_embedding.index, width=1100, height=700)
fig.update_layout(legend=dict(
    orientation="h",
    yanchor="bottom",
    y = -.25,
    xanchor="center",
    x = .5
))
fig.show()

### Code also used to plot the 3d plotly figure
fig_3d = px.scatter_3d(pca_embedding, x =0 , y = 1, z = 2, hover_data={"name": pca_embedding.index},
                    color = pca_embedding.index, width=1200, height=700)
fig_3d.update_layout(legend=dict(
        orientation="h",
        yanchor="bottom",
        y = -.25,
        xanchor="center",
        x = .5
    ))
fig_3d.show()
  1. Build the book

List your environment

Jupyter Book : 0.12.3 External ToC : 0.2.4 MyST-Parser : 0.15.2 MyST-NB : 0.13.2 Sphinx Book Theme : 0.1.10 Jupyter-Cache : 0.4.3 NbClient : 0.5.13

Python: 3.9.12

macOS Catalina: 10.15.7

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mmckycommented, Apr 13, 2022

thanks for reporting this @richardye101

@AakashGfude we should look into this re: plotly work that we are doing for themes.

0reactions
AakashGfudecommented, Apr 29, 2022

This issue will take a new plotly release to be resolved it seems. According to the thread I raised in plotly https://github.com/plotly/plotly.py/issues/3696 . We will have to wait a bit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Displaying figures in Python - Plotly
The current and available renderers are configured using the plotly.io.renderers configuration object. Display this object to see the current default renderer ...
Read more >
Introduction to Data visualization using Plotly.NET
Plotly; Chart functions; Rendering Charts; Styling your Charts ... We can prevent this by using a function that for every chart returns a...
Read more >
Plotly.NET
NET provides functions for generating and rendering plotly.js charts in . ... We recommend creating a single chart for each workflow to prevent...
Read more >
Python Plotly: How to prevent title from overlapping the plot?
Data View is the process of presenting data in image and image format. Visual representation of data makes understanding complex concepts easier ...
Read more >
Cytoscape.js
An amount of padding (in rendered pixels) to have around the graph (default 0 ). Details. If no collection is specified, then the...
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