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.

Proper display of Altair charts when exporting to PDF

See original GitHub issue

I have a Jupyter Notebook which has Altair charts in it for data visualisation. What I would like to do is to export the Notebook together with the charts to PDF using nbconvert. However, since Altair charts are JavaScript rendered, the exported document displays only alt.Chart(...) instead. Do you have any suggestions on how to set it up properly without having to export the chart to an image format and pasting it in the notebook?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
sousergecommented, Mar 20, 2020

Ok, I found this to be an issue with the way inkscape exports to PDF. A solution would be to overwrite the default inkscape command used by nbconvert to include a -D flag which ensures the exported area is the entire drawing:

jupyter nbconvert --to pdf --SVG2PDFPreprocessor.command="inkscape {from_filename} --export-pdf=\"{to_filename}\" -D" <your_notebook_name>

Tested with inkscape 0.92.1, the 1.0 version might have different flags.

1reaction
andyreagancommented, Jan 7, 2022

following these suggestions, I got a version that’s fully working too.

here’s a description of the process from end-to-end if anyone finds this thread too: https://github.com/andyreagan/papermill-altair-pdf

Read more comments on GitHub >

github_iconTop Results From Across the Web

Saving Altair Charts — Altair 4.2.0 documentation
Altair chart objects have a Chart.save() method which allows charts to be saved in a variety of formats. JSON format . The...
Read more >
Altair Monarch 2021 Help File - Exporting Data to PDF Files
With Monarch Classic, you can export extracted report data to a PDF file. If your table has a large number of fields (i.e.,...
Read more >
Altair report in HTML but charts only show partially
I send the HTML reports to team members but some of them say they can only see some of the charts displayed.
Read more >
Testing Altair-Saver - Nextjournal
Alternatively, you can enable an altair-viewer renderer and display the chart within a notebook as a specific type or set of types. For...
Read more >
Post-Pro ocessing - Altair University
to display scaled results (without actually changing the magnitude ... Selection Of Appropriate Type Of Stress: ... button is used to export t....
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