Convert Figma logo to code with AI

mwaskom logoseaborn

Statistical data visualization in Python

12,475
1,918
12,475
179

Top Related Projects

16,136

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!

matplotlib: plotting with Python

19,285

Interactive Data Visualization in the browser, from Python

9,274

Declarative statistical visualization library for Python

With Holoviews, your data visualizes itself.

Quick Overview

Seaborn is a powerful data visualization library built on top of Matplotlib for Python. It provides a high-level interface for creating attractive and informative statistical graphics, making it easier to create complex visualizations with less code.

Pros

  • Easy to use with a high-level interface for creating complex plots
  • Produces aesthetically pleasing visualizations out of the box
  • Integrates well with pandas DataFrames and numpy arrays
  • Offers a wide variety of statistical plot types and options

Cons

  • Can be slower than Matplotlib for large datasets
  • Limited customization options compared to Matplotlib
  • Steeper learning curve for advanced customizations
  • Some plot types may not be as flexible as their Matplotlib counterparts

Code Examples

Creating a scatter plot with a regression line:

import seaborn as sns
import matplotlib.pyplot as plt

sns.regplot(x="sepal_length", y="sepal_width", data=iris)
plt.show()

Generating a heatmap from a correlation matrix:

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

corr = df.corr()
sns.heatmap(corr, annot=True, cmap="coolwarm")
plt.show()

Creating a boxplot with multiple categories:

import seaborn as sns
import matplotlib.pyplot as plt

sns.boxplot(x="day", y="total_bill", hue="smoker", data=tips)
plt.show()

Getting Started

To get started with Seaborn, follow these steps:

  1. Install Seaborn using pip:

    pip install seaborn
    
  2. Import Seaborn in your Python script:

    import seaborn as sns
    import matplotlib.pyplot as plt
    
  3. Load a sample dataset and create a basic plot:

    tips = sns.load_dataset("tips")
    sns.scatterplot(x="total_bill", y="tip", data=tips)
    plt.show()
    

This will create a simple scatter plot using the tips dataset. From here, you can explore more complex plot types and customizations offered by Seaborn.

Competitor Comparisons

16,136

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!

Pros of Plotly

  • Interactive and dynamic visualizations with zooming, panning, and hover effects
  • Supports a wide range of chart types, including 3D plots and animations
  • Easy to create web-based dashboards and share interactive plots online

Cons of Plotly

  • Steeper learning curve compared to Seaborn's simpler API
  • Larger file sizes and slower rendering for complex plots
  • Less integrated with the scientific Python ecosystem

Code Comparison

Seaborn:

import seaborn as sns
import matplotlib.pyplot as plt

sns.scatterplot(x="sepal_length", y="sepal_width", data=iris)
plt.show()

Plotly:

import plotly.express as px

fig = px.scatter(iris, x="sepal_length", y="sepal_width")
fig.show()

Both libraries offer powerful data visualization capabilities, but they cater to different use cases. Seaborn excels in creating static, publication-quality plots with a focus on statistical visualizations, while Plotly shines in creating interactive, web-friendly charts and dashboards. The choice between the two depends on the specific requirements of your project and the intended audience for your visualizations.

matplotlib: plotting with Python

Pros of Matplotlib

  • More flexible and customizable for complex visualizations
  • Wider range of plot types and features
  • Larger community and ecosystem of extensions

Cons of Matplotlib

  • Steeper learning curve for beginners
  • More verbose code required for basic plots
  • Less aesthetically pleasing default styles

Code Comparison

Matplotlib:

import matplotlib.pyplot as plt

plt.figure(figsize=(8, 6))
plt.scatter(x, y)
plt.xlabel('X Label')
plt.ylabel('Y Label')
plt.title('Scatter Plot')
plt.show()

Seaborn:

import seaborn as sns

sns.set(style="darkgrid")
sns.scatterplot(x=x, y=y)
plt.xlabel('X Label')
plt.ylabel('Y Label')
plt.title('Scatter Plot')

Seaborn builds on top of Matplotlib, providing a higher-level interface for statistical visualizations. It offers more attractive default styles and simplifies the creation of common plot types. However, Matplotlib remains the foundation and offers greater flexibility for custom visualizations. The choice between the two depends on the specific needs of the project and the user's familiarity with each library.

19,285

Interactive Data Visualization in the browser, from Python

Pros of Bokeh

  • Interactive visualizations: Bokeh excels at creating interactive plots and dashboards for web browsers
  • Flexibility: Offers more customization options and control over plot elements
  • Scalability: Better suited for handling large datasets and creating complex, multi-layered visualizations

Cons of Bokeh

  • Steeper learning curve: Requires more code and setup compared to Seaborn's simpler API
  • Less statistical functionality: Lacks built-in statistical plotting functions that Seaborn provides
  • Documentation: While improving, it's generally considered less comprehensive than Seaborn's

Code Comparison

Seaborn:

import seaborn as sns
import matplotlib.pyplot as plt

sns.scatterplot(x="sepal_length", y="sepal_width", data=iris)
plt.show()

Bokeh:

from bokeh.plotting import figure, show
from bokeh.sampledata.iris import flowers

p = figure(title="Iris Scatter Plot")
p.scatter(flowers["sepal_length"], flowers["sepal_width"])
show(p)

Both libraries offer powerful data visualization capabilities, but they cater to different use cases. Seaborn is ideal for quick statistical visualizations and integrates seamlessly with Matplotlib. Bokeh shines in creating interactive, web-ready visualizations with more customization options.

9,274

Declarative statistical visualization library for Python

Pros of Altair

  • More flexible and expressive grammar of graphics
  • Better support for interactive visualizations
  • Easier to create complex, multi-layered charts

Cons of Altair

  • Steeper learning curve for beginners
  • Slower rendering for large datasets
  • Less extensive built-in themes and styles

Code Comparison

Seaborn:

import seaborn as sns
import matplotlib.pyplot as plt

sns.scatterplot(x="total_bill", y="tip", data=tips)
plt.show()

Altair:

import altair as alt
from vega_datasets import data

chart = alt.Chart(data.tips()).mark_point().encode(
    x='total_bill',
    y='tip'
)
chart.show()

Both libraries offer powerful data visualization capabilities, but they cater to different needs. Seaborn is more accessible for beginners and provides a wide range of pre-defined plots with minimal code. Altair, on the other hand, offers greater flexibility and interactivity, making it suitable for creating complex, custom visualizations. The choice between the two depends on the specific requirements of your project and your familiarity with data visualization concepts.

With Holoviews, your data visualizes itself.

Pros of HoloViews

  • More flexible and customizable for complex, interactive visualizations
  • Better support for large datasets and streaming data
  • Seamless integration with other HoloViz tools like Panel and Datashader

Cons of HoloViews

  • Steeper learning curve compared to Seaborn's simpler API
  • Less extensive built-in statistical functionality
  • Smaller community and fewer readily available examples

Code Comparison

Seaborn:

import seaborn as sns
import matplotlib.pyplot as plt

sns.scatterplot(data=df, x='x', y='y', hue='category')
plt.show()

HoloViews:

import holoviews as hv
from holoviews import opts

hv.extension('bokeh')
scatter = hv.Scatter(df, 'x', 'y', 'category')
scatter.opts(color='category', size=8, tools=['hover'])

HoloViews offers more flexibility in creating interactive plots with tools like hover, while Seaborn provides a simpler API for quick statistical visualizations. HoloViews excels in creating complex, layered visualizations and handling large datasets, whereas Seaborn is more focused on statistical plotting and integrates tightly with Matplotlib.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README



seaborn: statistical data visualization

PyPI Version License DOI Tests Code Coverage

Seaborn is a Python visualization library based on matplotlib. It provides a high-level interface for drawing attractive statistical graphics.

Documentation

Online documentation is available at seaborn.pydata.org.

The docs include a tutorial, example gallery, API reference, FAQ, and other useful information.

To build the documentation locally, please refer to doc/README.md.

Dependencies

Seaborn supports Python 3.8+.

Installation requires numpy, pandas, and matplotlib. Some advanced statistical functionality requires scipy and/or statsmodels.

Installation

The latest stable release (and required dependencies) can be installed from PyPI:

pip install seaborn

It is also possible to include optional statistical dependencies:

pip install seaborn[stats]

Seaborn can also be installed with conda:

conda install seaborn

Note that the main anaconda repository lags PyPI in adding new releases, but conda-forge (-c conda-forge) typically updates quickly.

Citing

A paper describing seaborn has been published in the Journal of Open Source Software. The paper provides an introduction to the key features of the library, and it can be used as a citation if seaborn proves integral to a scientific publication.

Testing

Testing seaborn requires installing additional dependencies; they can be installed with the dev extra (e.g., pip install .[dev]).

To test the code, run make test in the source directory. This will exercise the unit tests (using pytest) and generate a coverage report.

Code style is enforced with flake8 using the settings in the setup.cfg file. Run make lint to check. Alternately, you can use pre-commit to automatically run lint checks on any files you are committing: just run pre-commit install to set it up, and then commit as usual going forward.

Development

Seaborn development takes place on Github: https://github.com/mwaskom/seaborn

Please submit bugs that you encounter to the issue tracker with a reproducible example demonstrating the problem. Questions about usage are more at home on StackOverflow, where there is a seaborn tag.