Questions tagged [seaborn]

Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. Add the seaborn-0.12.x tag for questions about seaborn.objects.

Seaborn is a library for making statistical graphics in Python. It is built on top of matplotlib and is tightly integrated with the PyData stack, including support for numpy and pandas data structures, and statistical routines from scipy and statsmodels.

Here is some of the functionality that seaborn offers:

  • A dataset-oriented API for examining relationships between multiple variables
  • Convenient views onto the overall structure of complex datasets
  • Specialized support for using categorical variables to show observations or aggregate statistics
  • Options for visualizing univariate or bivariate distributions and for comparing them between subsets of data
  • Automatic estimation and plotting of linear regression models for different kinds of dependent variables
  • High-level abstractions for structuring multi-plot grids that let you easily build complex visualizations
  • Concise control over matplotlib figure styling with several built-in themes
  • Tools for choosing color palettes that faithfully reveal patterns in your data

This tag should be used for seaborn related questions. Since seaborn heavily builds on top of matplotlib, and since many seaborn related problems can be come by using standard matplotlib techniques, it is advisable to additionally add the tag to any seaborn question as well.

It is traditionally imported with:

import seaborn as sns

Example gallery:

some visualizations generated by seaborn

more visualizations generated by seaborn

9450 questions
3161
votes
14 answers

How do I change the size of figures drawn with Matplotlib?

How do I change the size of figure drawn with Matplotlib?
tatwright
  • 37,567
  • 6
  • 21
  • 9
1574
votes
18 answers

How to put the legend outside the plot

I have a series of 20 plots (not subplots) to be made in a single figure. I want the legend to be outside of the box. At the same time, I do not want to change the axes, as the size of the figure gets reduced. I want to keep the legend box outside…
pottigopi
  • 15,759
  • 3
  • 15
  • 4
536
votes
9 answers

Improve subplot size/spacing with many subplots

I need to generate a whole bunch of vertically-stacked plots in matplotlib. The result will be saved using savefig and viewed on a webpage, so I don't care how tall the final image is, as long as the subplots are spaced so they don't overlap. No…
mcstrother
  • 6,867
  • 5
  • 22
  • 18
490
votes
13 answers

How to change the figure size of a seaborn axes or figure level plot

How do I change the size of my image so it's suitable for printing? For example, I'd like to use to A4 paper, whose dimensions are 11.7 inches by 8.27 inches in landscape orientation.
Michael Grazebrook
  • 5,361
  • 3
  • 16
  • 18
471
votes
6 answers

How to draw vertical lines on a given plot

Given a plot of a signal in time representation, how can I draw lines marking the corresponding time index? Specifically, given a signal plot with a time index ranging from 0 to 2.6 (seconds), I want to draw vertical red lines indicating the…
Francis
  • 6,416
  • 5
  • 24
  • 32
414
votes
10 answers

How to invert the x or y axis

I have a scatter plot graph with a bunch of random x, y coordinates. Currently the Y-Axis starts at 0 and goes up to the max value. I would like the Y-Axis to start at the max value and go up to 0. points = [(10,5), (5,11), (24,13), (7,8)] x_arr…
DarkAnt
  • 4,163
  • 2
  • 17
  • 6
332
votes
7 answers

Plot a horizontal line on a given plot

How do I add a horizontal line to an existing plot?
Ibe
  • 5,615
  • 7
  • 32
  • 45
308
votes
8 answers

Seaborn plots not showing up

I'm sure I'm forgetting something very simple, but I cannot get certain plots to work with Seaborn. If I do: import seaborn as sns Then any plots that I create as usual with matplotlib get the Seaborn styling (with the grey grid in the…
rtc3po
  • 3,191
  • 2
  • 11
  • 7
284
votes
10 answers

How to save a Seaborn plot into a file

I tried the following code (test_seaborn.py): import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt matplotlib.style.use('ggplot') import seaborn as sns sns.set() df = sns.load_dataset('iris') sns_plot = sns.pairplot(df,…
neversaint
  • 60,904
  • 137
  • 310
  • 477
268
votes
9 answers

Rotate label text in seaborn

I have a simple factorplot import seaborn as sns g = sns.factorplot("name", "miss_ratio", "policy", dodge=.2, linestyles=["none", "none", "none", "none"], data=df[df["level"] == 2]) The problem is that the x labels all run together, making…
dan
  • 4,262
  • 7
  • 25
  • 40
258
votes
6 answers

Plotting a 2D heatmap

Using Matplotlib, I want to plot a 2D heat map. My data is an n-by-n Numpy array, each with a value between 0 and 1. So for the (i, j) element of this array, I want to plot a square at the (i, j) coordinate in my heat map, whose color is…
Karnivaurus
  • 22,823
  • 57
  • 147
  • 247
251
votes
5 answers

Label axes on Seaborn Barplot

I'm trying to use my own labels for a Seaborn barplot with the following code: import pandas as pd import seaborn as sns fake = pd.DataFrame({'cat': ['red', 'green', 'blue'], 'val': [1, 2, 3]}) fig = sns.barplot(x = 'val', y = 'cat', …
Erin Shellman
  • 3,553
  • 4
  • 21
  • 26
246
votes
13 answers

How to plot in multiple subplots

I am a little confused about how this code works: fig, axes = plt.subplots(nrows=2, ncols=2) plt.show() How does the fig, axes work in this case? What does it do? Also why wouldn't this work to do the same thing: fig = plt.figure() axes =…
bugsyb
  • 5,662
  • 7
  • 31
  • 47
241
votes
12 answers

How to add hovering annotations to a plot

I am using matplotlib to make scatter plots. Each point on the scatter plot is associated with a named object. I would like to be able to see the name of an object when I hover my cursor over the point on the scatter plot associated with that…
jdmcbr
  • 5,964
  • 6
  • 28
  • 38
228
votes
10 answers

How to plot multiple dataframes in subplots

I have a few Pandas DataFrames sharing the same value scale, but having different columns and indices. When invoking df.plot(), I get separate plot images. what I really want is to have them all in the same plot as subplots, but I'm unfortunately…
Jimmy C
  • 9,270
  • 11
  • 44
  • 64
1
2 3
99 100