Exporting and Embedding
Save and share figures.
Exporting and Embedding is a free Python Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Sharing Your Work
A finished chart is only useful if others can see it. Plotly figures can be saved as interactive HTML, exported as static images, or embedded in web pages and reports.
Choosing the right format depends on whether the audience needs interactivity.
Saving Interactive HTML
fig.write_html('chart.html') writes a standalone file that keeps all interactivity. Opening it in any browser gives zoom, hover, and pan with no Python needed.
This is the best format for sharing a live, explorable chart.
Choosing a Filename
Naming matters when you generate many exports. A timestamped, slugified name avoids collisions. This is plain string handling.
title = 'Q3 Sales Report!'
slug = ''.join(ch.lower() if ch.isalnum() else '_' for ch in title)
slug = '_'.join(p for p in slug.split('_') if p)
print(slug + '.html')Static Image Export
For PDFs, slides, or emails you need a static image. fig.write_image('chart.png') produces PNG, JPEG, SVG, or PDF. This requires the kaleido engine to be installed.
Static images lose interactivity but embed anywhere.
Picking a Format
Match format to use:
- HTML live exploration, web pages
- PNG/JPEG raster, good for slides and email
- SVG vector, scales without blur for print
- PDF documents
A small decision table makes the choice quick.
use_case = 'print'
format_map = {'web': 'html', 'slides': 'png', 'print': 'svg', 'document': 'pdf'}
print('Best format for', use_case, '->', format_map[use_case])Embedding in a Page
To embed in an existing site without a full HTML file, use fig.to_html(full_html=False, include_plotlyjs='cdn'). It returns just the chart's HTML fragment, which you paste into your template.
Loading plotly.js from a CDN keeps your page light.
Including the Library
Interactive HTML needs the plotly.js library. Options for include_plotlyjs:
Truebundle it (large, works offline)'cdn'link to a CDN (small, needs internet)Falseassume the page already loaded it
Choose based on offline needs and page weight.
Export Resolution
For static images, control size and sharpness with width, height, and scale. A scale=2 doubles the pixel density for crisp images on high-resolution screens.
width, height, scale = 800, 600, 2
print('Output pixels:', width * scale, 'x', height * scale)JSON Round-Trips
A figure can be serialized with fig.to_json() and rebuilt with plotly.io.from_json(). This is handy for caching figures or sending them between a server and a browser.
The JSON fully describes the data and layout.
Reproducibility
When you share an export, also keep the script that produced it. A PNG cannot be re-edited, but the code can regenerate the chart with new data. Treat the code, not the image, as the source of truth.
Embedding in Notebooks and Markdown
In Jupyter, a figure displays inline automatically when it is the last expression in a cell. For static documentation, export an image and reference it from Markdown. For live docs, embed the HTML fragment instead.
Pick interactive HTML when the reader benefits from exploring, and a static image when they only need to look.
Quick Check
Test your export knowledge.
Recap
You learned to share figures:
write_htmlfor interactive standalone fileswrite_image(with kaleido) for PNG/SVG/PDFto_html(full_html=False)to embed a fragment, withinclude_plotlyjscontrolling the library- Use
scalefor high-resolution images, and keep the source code for reproducibility
Frequently asked questions
Is the “Exporting and Embedding” lesson free?
Yes — the full text of “Exporting and Embedding” is free to read here on the web, and the Python Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO.
What will I learn in “Exporting and Embedding”?
Save and share figures. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Python Academy?
No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Exporting and Embedding” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Python Academy lesson?
Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Plotly Express Basics
- Interactive Features
- Dashboards Concepts
- Exporting and Embedding