Seaborn: How to use lineplot with numpy array

Created on 17 Jul 2018  路  5Comments  路  Source: mwaskom/seaborn

Related to this StackOverflow question, I'm confused about how to replace the error-bar functionality of tsplot. Previously, it was possible to make a time-series plot with confidence interval shading using:

x = np.linspace(0, 15, 31)
data = np.sin(x) + np.random.rand(10, 31) + np.random.randn(10, 1)
sns.tsplot(data)

How do I replace this with sns.linplot call? When I try sns.lineplot(data=data) it tells me ValueError: Thesestylelevels are missing dashes: {6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30}.

I tried looking at the code to see if I could make the fix myself, but it seems almost as if what I'm trying to do is a bad idea. Is Seaborn not intended to satisfy this case? Is the key to manipulate the data into a DataFrame? Is there any way I can discuss the design of plotting time-series with you or has the window for this discussion passed?

Most helpful comment

The equivalent would be to make a long-form pandas dataframe:

x = np.linspace(0, 15, 31)
data = np.sin(x) + np.random.rand(10, 31) + np.random.randn(10, 1)
df = pd.DataFrame(data).melt()
sns.lineplot(x="variable", y="value", data=df)

image

lineplot has some support for wide form data, but like other modern seaborn functions it's limited in what it can do with it.

All 5 comments

The equivalent would be to make a long-form pandas dataframe:

x = np.linspace(0, 15, 31)
data = np.sin(x) + np.random.rand(10, 31) + np.random.randn(10, 1)
df = pd.DataFrame(data).melt()
sns.lineplot(x="variable", y="value", data=df)

image

lineplot has some support for wide form data, but like other modern seaborn functions it's limited in what it can do with it.

Thank you for taking the time to reply and explaining the intentionally designed limitations of Seaborn.

I came across this as well, with a numpy array of size (numOfTimeSeries x lengthOfTimeSeries). Unfortunately, this now gives you x-axis values from 0 to lengthOfTimeSeries instead of what you expect.

As this has replaced tsplot, there should probably be a straightforward way to plot an array of size (numOfTimeSeries x lengthOfTimeSeries) as it was under tsplot.

There is a straightforward way, and it鈥檚 provided in the second comment in this thread.

Previously, you would be able to type:

# myArrayOfEstimates = generate the array of size (numOfTimeSeries x lengthOfTimeSeries)
plt.plot(x,f(x),label='f(x)');
sns.tsplot(myArrayOfEstimates,time=x,color='orange',err_style='unit_traces');

to generate something that looks like:
image

Now, as I understand it, I have to use pandas to melt my array and then perform various shifts/corrections in order to be able to use this plot with something else.


Or:

plt.plot(x,f(x),label='f(x)');
sns.tsplot(myArrayOfEstimates,time=x,color='orange',ci='sd');

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tritemio picture tritemio  路  3Comments

alexpetralia picture alexpetralia  路  3Comments

sungshine picture sungshine  路  3Comments

amelio-vazquez-reina picture amelio-vazquez-reina  路  4Comments

Bercio picture Bercio  路  3Comments