Intro to Data Visualization
  • Introduction
  • Getting started
    • Introduction to Pandas
    • Accessing Files on Colab
    • Reviewing Data
      • Understanding type(data) in Pandas
    • Data Types
      • Categorical Data
      • Numeric Data
      • Temporal Data
      • Geographic Data
    • How to Check Data Type
    • Slicing and Subsetting DataFrames
    • Aggregating Data
  • Visualization Types
    • Exploratory Process
    • Explanatory Process
  • data exploration
    • Exploration Overview
    • Exploration with Plotly
      • Exploring Distributions
      • Exploring Relationships
      • Exploring with Regression Plots
      • Exploring Correlations
      • Exploring Categories
      • Exploring Time Series
      • Exploring Stocks with Candlestick
      • Exploring with Facets
      • Exploring with Subplots
    • Exploring with AI
  • Data Explanation
    • Data Explanation with Plotly
      • Using Text
      • Using Annotations
      • Using Color
      • Using Shape
      • Accessibility
      • Using Animations
    • Use Cases
  • Exercises and examples
    • Stock Market
      • Loading Yahoo! Finance Data
      • Use Cases for YF
      • Exploring YF Data
      • Understanding Boeing Data Over Time
      • Polishing the visualization
      • Analyzing with AI
      • Comparisons
    • The Gapminder Dataset
      • Loading the Gapminder Data
      • Use Cases
      • Exploring the Data
      • Exporting a Static Image
Powered by GitBook
On this page
  1. Exercises and examples
  2. The Gapminder Dataset

Exporting a Static Image

Exporting a static image from a Plotly Express visualization allows you to save your plots as high-quality files for use in presentations, reports, or publications. Plotly supports exporting images in various formats such as PNG, JPEG, SVG, and PDF. To do this, you need to install the kaleido library, which serves as a fast and efficient image export engine. After creating a Plotly figure, use the .write_image() method to save it to a specified file path. For example, after creating a chart (fig), you can save it as fig.write_image("plot.png"). You can also adjust the resolution and size by specifying parameters like width, height, and scale. This functionality ensures that your interactive Plotly visualizations can be seamlessly incorporated into static documents or shared in non-interactive formats. Here’s an example:

!pip install -U kaleido
!pip install plotly
import kaleido
import plotly
import plotly.express as px
import plotly.io as pio
import plotly.express as px

# Sample data and visualization
df = px.data.gapminder()
fig = px.scatter(
    df[df['year'] == 2007],
    x='gdpPercap',
    y='lifeExp',
    size='pop',
    color='continent',
    title='Life Expectancy vs GDP per Capita (2007)',
    log_x=True
)

# Save the figure as a static image
fig.write_image("scatter_plot.png", width=800, height=600, scale=2)

Ensure you have kaleido installed (pip install -U kaleido) before using the export functionality.

PreviousExploring the Data

Last updated 3 months ago