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.

Write Image as PDF with Box saying "Loading [MathJax]/extensions/MathMenu.js"

See original GitHub issue

Hi,

截屏2021-11-15 下午4 34 46

I am trying to write plot into PDF format, but I cannot get rid of this box saying “Loading [MathJax]/extensions/MathMenu.js”, will you be able to tell me how should I fix it?

Here is the code I am using to generate the plot.

fig = go.Figure()
    fig.add_trace(go.Scatter(x=[0, 1, 2, 3, 4, 5], y=[0.5, 0.6, 0.7, 0.8, 0.9, 0.9], name='A',
                             line=dict(width=4), marker=dict(size=15, symbol='star')))
    fig.add_trace(go.Scatter(x=[0, 1, 2, 3, 4, 5], y=[0.4, 0.4, 0.4, 0.4, 0.4, 0.4], name='B',
                             line=dict(width=4), marker=dict(size=15, symbol='circle')))
    fig.add_trace(
        go.Scatter(x=[0, 1, 2, 3, 4, 5], y=[0.51, 0.52, 0.53, 0.54, 0.55, 0.56], name='C',
                   line=dict(width=4), marker=dict(size=15, symbol='x')))

    fig.update_layout(
        yaxis_range=[0.2, 1],
        legend=dict(
            x=0,
            y=0,
            traceorder="reversed",
            title_font_family="Times New Roman",
            font=dict(
                family="Courier",
                size=16,
                color="black"
            ),
            bgcolor="LightSteelBlue",
            bordercolor="Black",
            borderwidth=2
        )
    )
    fig.write_image("1.pdf")
    fig.show()

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:8
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

13reactions
nicolaskruchtencommented, Dec 15, 2021

Yes, we know the basic cause, see https://github.com/plotly/Kaleido/issues/122 for details.

Note that if the figure you’re rendering doesn’t actually use MathJax then you can prevent MathJax from being loaded at all by Kaleido with:

import plotly.io as pio   
pio.kaleido.scope.mathjax = None

Otherwise, if saving a “throwaway” PDF first helps, I would recommend that: basically save your figure twice.

3reactions
jorgeboucascommented, Dec 14, 2021

this worked for me:

figure="some_figure.pdf"
fig=px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])
fig.write_image(figure, format="pdf")
time.sleep(2)

fig=make_figure(df,pa)
fig.write_image(figure, format="pdf")

plotly==5.3.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

PDFBox - Inserting Image - Tutorialspoint
Step 1: Loading an Existing PDF Document. Load an existing PDF document using the static method load() of the PDDocument class. This method...
Read more >
Convert PDF files to images with PDFBox - Stack Overflow
Solution for the 2.0 version: PDDocument document = PDDocument.load(new File(pdfFilename)); PDFRenderer pdfRenderer ...
Read more >
PDF-LIB · Create and modify PDF documents in any ... - JS.ORG
Create PDF documents from scratch, or modify existing PDF documents. Draw text, images, and vector graphics. Embed your own fonts. Even embed and...
Read more >
Error: Insufficient data for an image in Acrobat or Acrobat Reader
When you open a PDF file in Acrobat or Acrobat Reader, the following error message is displayed: “Insufficient data for an image.
Read more >
Hopding/pdf-lib: Create and modify PDF documents ... - GitHub
Create and modify PDF documents in any JavaScript environment - GitHub ... Load a PDFDocument from the existing PDF bytes const pdfDoc =...
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