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
  • Scatter Plot with Shapes
  • Dot Plot with Shapes
  1. Data Explanation
  2. Data Explanation with Plotly

Using Shape

Using shape to represent data or categories in data visualization is crucial for effectively distinguishing between different groups or dimensions in a dataset. Shapes provide a visual cue that allows viewers to quickly identify and compare categories, even when multiple variables are plotted in a single chart. For example, in a scatter plot showing customer segmentation, circles, triangles, and squares can represent distinct groups such as age brackets or geographic regions. This differentiation is especially valuable in multivariate visualizations where color, size, or other encodings are already in use. Shapes are also helpful for ensuring accessibility, as they provide a non-color-based way to distinguish categories, accommodating viewers with color vision deficiencies. By leveraging shapes thoughtfully, visualizations become more intuitive, allowing audiences to better interpret complex datasets and draw meaningful insights. Shapes in scatter plots and dot plots can add another layer of distinction to your visualizations, helping differentiate groups or categories within your data.


Scatter Plot with Shapes

You can use the symbol parameter in Plotly Express to assign different shapes to data points based on a categorical column.

import pandas as pd
import plotly.express as px

# Sample data
data = {
    'X': [1, 2, 3, 4, 5],
    'Y': [10, 20, 15, 25, 18],
    'Category': ['A', 'B', 'A', 'B', 'A']
}

df = pd.DataFrame(data)

# Scatter plot with different shapes
fig = px.scatter(
    df, 
    x='X', 
    y='Y', 
    color='Category', 
    symbol='Category',  # Use shapes based on 'Category'
    title='Scatter Plot with Shapes'
)
fig.show()

Dot Plot with Shapes

Dot plots are a variation of scatter plots where shapes can emphasize categories.

# Dot plot with shapes
fig = px.scatter(
    df, 
    x='Category', 
    y='Y', 
    color='Category', 
    symbol='Category',  # Assign shapes based on 'Category'
    size=[10, 20, 15, 25, 18],  # Optional: Control dot size
    title='Dot Plot with Shapes'
)
fig.update_traces(marker=dict(symbol='circle'))  # Optional: Ensure uniform base shape
fig.show()

Key Parameters for Shapes in Plotly Express

  • symbol: Assigns shapes to data points based on a column.

  • size: Adjusts the size of the markers for emphasis.

  • symbol_sequence: Customize the sequence of shapes (e.g., circles, squares, triangles).

Shape Customization Tips

  1. Use shapes to distinguish categories effectively, especially when colors alone might not suffice.

  2. Combine shapes with other visual cues like color and size for multidimensional differentiation.

  3. Keep the chart uncluttered by limiting the number of distinct shapes used.

These features make scatter and dot plots more versatile, improving the clarity and interpretability of your data visualizations.

PreviousUsing ColorNextAccessibility

Last updated 3 months ago