question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use lineplot with numpy array

See original GitHub issue

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: These style levels 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?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
mwaskomcommented, Jul 17, 2018

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.

0reactions
diego898commented, Sep 2, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plot line graph from NumPy array - GeeksforGeeks
Plot line graph from NumPy array ; np.arange(start, end): This function returns equally spaced values from the interval [start, end). ; plt.title ...
Read more >
Simple line plots using seaborn - python - Stack Overflow
It's possible to get this done using seaborn.lineplot() but it involves some additional work of converting numpy arrays to pandas dataframe.
Read more >
Creating line plots using NumPy arrays - O'Reilly
In order to create a simple line plot using a NumPy array, we can use this code: #Import required packagesimport numpy as npimport...
Read more >
NumPy - Matplotlib - Tutorialspoint
An ndarray object x is created from np.arange() function as the values on the x axis. The corresponding values on the y axis...
Read more >
seaborn.lineplot — seaborn 0.12.1 documentation - PyData |
Draw a line plot with possibility of several semantic groupings. The relationship between x and y can be shown for different subsets of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found