slhck
slhck

Reputation: 38672

How do I change the size of a seaborn tsplot?

Seaborn's tsplot does not offer a size option like some of the other plot types (e.g., lmplot). I understand that this is due to tsplot being an axis-level function and lmplot, for example, being a figure-level function.

Question:

I really just want a simple tsplot and set the size of the figure like I would do in lmplot. How can I do that?

What I've tried:

This probably means I have to combine a FacetGrid (with just one facet) with my tsplot. There does not seem to be any straightforward example online.

When I do:

sns.tsplot(data = data, time = "index", value = "score", unit = "mode", condition = "mode")

I get a nice plot, with the condition properly colored, just with the wrong size:

grid = sns.FacetGrid(data, size = 10)
grid.map(sns.tsplot, data = data, time = "index", value = "score", unit = "mode", condition = "mode")

I get this:

Upvotes: 2

Views: 1683

Answers (1)

mwaskom
mwaskom

Reputation: 49002

tsplot just plots onto the currently active matplotlib axes, unless you specify one to the ax parameter. That means any of the various ways to control the figure size in matplotlib apply. My preferred approach would be:

f, ax = plt.subplots(figsize=(10, 4))
sns.tsplot(..., ax=ax)

It's not strictly necessary to specify the ax here, but probably good form.

Upvotes: 4

Related Questions