How To Export Data Visualizations from Jupyter Lab and Jupyter Notebook

When you’re done crunching numbers, analyzing datasets, and crafting your visualizations in Jupyter Notebook, the real challenge for data analysts begins: presenting these findings effectively. Whether you’re showcasing trends, highlighting key metrics, or unveiling predictions, you need to export Jupyter Notebook content and deliver these insights to non-technical stakeholders in a way they can easily understand.

Why Presenting Your Findings Matters

Creating visually appealing charts and insightful data models in Jupyter Notebook or Jupyter Lab is just the start. The real impact lies in how well you communicate those insights. For data analysts, the challenge often isn’t performing the analysis but presenting it in a way that resonates with non-technical audiences. This is where exporting your Jupyter Notebook to PDF or creating accessible visualizations comes into play. Check out our installation guides on how to get Jupyter Notebook or Jupyter Lab set up if you are just starting out. If you need to download and install Python you can read out Python guide as well.

Presenting your findings effectively is necessary for a variety of reasons:

  1. Clear Communication of Insights: Stakeholders may not have the technical expertise to interpret raw data or Python code. By exporting data from Jupyter Notebook into easy-to-understand formats, like images, PDFs, or HTML files, you ensure your insights are accessible and actionable.
  2. Enhanced Decision-Making: Whether you’re visualizing trends, forecasts, or key metrics, polished presentations help decision-makers grasp the story your data tells. For example, saving Seaborn or Matplotlib visualizations as high-quality PNGs ensures your visuals are professional and engaging.
  3. Versatile Sharing Options: Exporting data visualizations from Jupyter Notebook gives you the flexibility to tailor your presentation. You can compile visuals into a PDF for email distribution, create interactive HTML files for web sharing, or insert images into PowerPoint for meetings.
  4. Time Efficiency: Automating the export process with Python saves time, especially for recurring reports. Tools like nbconvert or libraries such as fpdf streamline exporting data and visualizations, ensuring consistency and reducing manual effort.

By leveraging tools and strategies to export Jupyter Notebook content, you ensure that your analysis reaches the right audience effectively. This process not only amplifies the value of your work but also allows stakeholders to make data-driven decisions.


Save Visualizations as Image Files

Saving your visualizations as static image files is good for preparing data insights for presentations, reports, or distribution. Formats like PNG, JPEG, and SVG are widely compatible, ensuring your visualizations are accessible and easy to share across various platforms. These formats also make it easier to integrate visuals into PowerPoint presentations, PDF reports, or online documents.

Saving Visualizations in Matplotlib

Matplotlib, a popular plotting library in Python that allows you to easily save your visualizations as image files. Here’s how to do it:

import matplotlib.pyplot as plt

# Example visualization
plt.plot([1, 2, 3], [4, 5, 6], marker='o', color='blue')
plt.title('Sample Visualization')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')

# Save the plot as a PNG image
plt.savefig('visualization.png', dpi=300, bbox_inches='tight')
plt.show()

The above Python code will display a line chart as in the image below that can be exported from Jupyter Notebook.

Matplotlib Line Chart Export Jupyter Notebook Visualization
Saving Visualizations in Seaborn

Seaborn, which is built on top of Matplotlib, is another popular library that great for creating nice looking statistical plots. The process for saving these visualizations is nearly identical, as it uses Matplotlib’s savefig method. Here’s an example:

import seaborn as sns
import matplotlib.pyplot as plt

sns.set(style='whitegrid') # Apply a clean, grid-based style
sns.barplot(x=[1, 2, 3], y=[4, 5, 6], palette='muted')
plt.title('Sample Bar Plot')

# Save the plot as an image
plt.savefig('barplot.png', dpi=300, bbox_inches='tight')
plt.show()

The above Python code will display a bar chart as in the image below that can be exported from Jupyter Notebook or Jupyter Lab.

Seaborn Bar Plot from Python Code for Jupyter Notebook
When to Use These Formats
  • PNG (Portable Network Graphics): Ideal for presentations and documents due to its high quality and lossless compression.
  • JPEG (Joint Photographic Experts Group): Suitable for web-based visuals where file size is a concern, though it may lose some detail.
  • SVG (Scalable Vector Graphics): Perfect for visuals that need to be scaled without losing quality, commonly used in web design or printed materials.
Why Saving Visualizations Matters

Exporting visualizations as static images from Jupyter Notebook ensures your insights are portable and ready for any medium. This method is essential when preparing reports for non-technical stakeholders or integrating visuals into professional-grade presentations.


Exporting Interactive Visualizations

Interactive visualizations are a great way to engage your audience and make data exploration more dynamic. Libraries like Plotly make it easy to create these visualizations, but you will need to consider the format when exporting. Unlike static images, interactive plots allow stakeholders to explore the data themselves, offering deeper insights. Below are two key approaches to exporting Plotly visualizations for sharing and distribution.

Exporting Plotly Visualizations as Images

When you need a static version of an interactive visualization to include in reports, presentations, or publications, exporting as an image is the best approach. Plotly provides the write_image function to save your interactive visualizations as high-quality image files. This method needs the Kaleido package, which simplifies the image generation process. Here’s how to get it set up:

Install Kaleido

Kaleido allows you to export Plotly visualizations to static image formats such as PNG, JPEG, and PDF without needing addtional dependencies like a browser or a running server.

Run the following command in your terminal or Jupyter Notebook to install Kaleido:

pip install -U kaleido

Next, run the following Python code to create and dipslay a Plot with Plotly. The write_image function in Plotly is used to save the visualization as a file, not to display it. To display the plot in your Jupyter Notebook, you need to explicitly call fig.show().

import plotly.express as px

# Example interactive plot
fig = px.line(x=[1, 2, 3], y=[4, 5, 6], title='Sample Interactive Plot')

# Display the plot in the notebook
fig.show()

# Save the plot as a PNG image
fig.write_image('interactive_plot.png')

Your output from the above code will look similar to the image below. When you hover over different areas on the line in the chart, the coordinate numbers will display:

Plotly Line Chart showing the coordinates on the line chart with Python code in Jupyter Lab

Key Benefits of Plotly:

  • High-Quality Output: Images exported using Plotly maintain the sharpness and clarity of your visualizations.
  • Ease of Use: Static images can be easily embedded in documents, slides, or web pages without additional dependencies.
  • Broad Compatibility: Formats like PNG ensure compatibility across different platforms and devices.
Exporting Interactive Visualizations as HTML

If you want to preserve the interactivity of your Plotly visualizations, exporting them as an HTML file is the best choice. HTML format retains all interactive features, such as zooming, hovering, and data filtering, allowing stakeholders to explore the data directly in their browsers.

Here’s how to save your visualization as an HTML file:

import webbrowser
import os

# Create a sample interactive plot
fig = px.line(x=[1, 2, 3], y=[4, 5, 6], title='Sample Interactive Plot')

# Save the plot as an HTML file
html_file = 'interactive_plot.html'
fig.write_html(html_file)

# Automatically open the saved HTML file in your browser
webbrowser.open(f'file://{os.path.abspath(html_file)}')

How It Works:

  • The write_html function generates a standalone .html file containing your visualization and all necessary scripts.
  • This file can be shared via email, uploaded to a website, or distributed through cloud services like Google Drive.

Advantages of HTML Export:

  • Interactivity Preserved: Users can interact with the plot just as they would in a Jupyter Notebook.
  • No Additional Setup Required: Stakeholders only need a web browser to view the visualization.
  • Easy Sharing: The file can be opened on any device with a modern browser, making it highly accessible.
Export as HTML and Convert Jupyter Notebook to PDF
  1. Export as HTML:
    • Open the notebook.
    • Go to File > Download as > HTML (.html).
  2. Convert HTML to PDF:
    • Open the exported HTML file in a browser.
    • Use the browser’s Print function (Ctrl+P or Command+P).
    • Choose Save as PDF as the destination.

Final Thoughts

Effectively exporting and presenting your data visualizations is key to ensuring that your insights make an impact. Whether you’re presenting static images or interactive files, it’s important to tailor the presentation format to your audience. By following these steps — saving visuals in accessible formats like static images or interactive files, compiling them into user-friendly formats such as PDFs or presentations, and using clear, simple language — you can communicate your analysis in a way that resonates, even with those without a technical background. Always keep in mind that your goal is to make the data easily understandable and actionable, and these strategies will help you achieve that goal.


Discover more from Lets Learn Data Science

Subscribe to get the latest posts sent to your email.

We want to hear from you

Scroll to Top

Discover more from Lets Learn Data Science

Subscribe now to keep reading and get access to the full archive.

Continue reading