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. data exploration
  2. Exploration with Plotly

Exploring with Subplots

Subplots in Plotly are an essential feature for visualizing multiple charts in a single figure, enabling comparisons across datasets and/or metrics. Subplots allow users to display multiple plots, such as line charts, scatter plots, bar charts, or even mixed chart types, arranged in a grid layout. With Plotly's make_subplots function, users can define the number of rows and columns, specify shared axes, and even customize the layout for each subplot. These features make subplots particularly useful in scenarios like financial analysis, where a user may want to display price movements, trading volume, and technical indicators side by side for better context.

Here's an example of creating a plot with two line charts.

import plotly.express as px
import pandas as pd
from plotly.subplots import make_subplots

# Download Stock Data from plotly.express
df = px.data.stocks()

# Create two line charts
fig1 = px.line(df, 'date', y=['GOOG'], color_discrete_sequence=['black'])
fig2 = px.line(df, 'date', y=['AAPL', 'AMZN'])

# Make one figure with two subplots
fig = make_subplots(rows=2, cols=1)

# Add the data from the line charts to the subplots
fig.add_trace(fig1['data'][0], row=1, col=1)
fig.add_trace(fig2['data'][0], row=2, col=1) # line 1 in fig2
fig.add_trace(fig2['data'][1], row=2, col=1) # line 2 in fig2
    
fig.show()

A key advantage of Plotly's subplots is their interactivity, which includes zooming, panning, and tooltips, even when managing complex layouts. Users can customize individual subplots by adjusting titles, axis labels, and colors while maintaining a cohesive overall design. For instance, one subplot can display a histogram for data distribution, while another shows a scatter plot for trend analysis, both sharing the same x-axis. Additionally, subplots can incorporate different chart types and scales, such as combining linear and logarithmic axes or overlaying time series and categorical data. This flexibility and versatility make Plotly subplots an ideal choice for creating comprehensive and interactive dashboards.

PreviousExploring with FacetsNextExploring with AI

Last updated 3 months ago