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.

Feature request: Add argument "fill" to lineplot()

See original GitHub issue

kdeplot() offers an argument fill. It would be nice to offer this argument to lineplot() as well.

sns.lineplot(
   data=data, x="x", y="y", hue="category", fill=True, palette="crest", alpha=.5, linewidth=0
)

image (image from kdeplot docu)

Keep in mind that the lineplot can be used in the context of a polar plot (axis projection: “polar”).

PS: happy New Year!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mwaskomcommented, Jan 2, 2021

But isn’t seaborn’s theme, hue/style selection or handling of the legend superior compared to pandas’ plotting features?

Not really, because seaborn does all of its theming through the matplotlib rc system, which pandas plots also pick up. So if you set a theme “in seaborn”, it will affect pandas plots too.

I don’t think it makes much sense to have a lineplot that draws areas … lineplot uses filling to represent uncertainty which is different (in tension with, actually) using it to represent the quantity.

But … on the user side it’s easy to define a simple function that adds fills to a line plot, e.g. something like

def fill_under_lines(ax=None, alpha=.2, **kwargs):
    if ax is None:
        ax = plt.gca()
    for line in ax.lines:
        x, y = line.get_xydata().T
        ax.fill_between(x, 0, y, color=line.get_color(), alpha=alpha, **kwargs)

If you have that sitting in a personal function library, you can call it after you make a lineplot and it will add fills that match the lines in your plot, essentially just as you’d like.

2reactions
mwaskomcommented, Jan 1, 2021

I am -1 on adding this to lineplot, but am somewhat open to the idea of an areaplot. There are a few things one would need to think about though:

  • There would need to be a way to show errorbars, I’m not really sure that there’s a good way to do that with area plots
  • Currently, the way things work in seaborn is that all of the plots in the same module (and same figure-level interface) support the same semantic mappings. lineplot and scatterplot support hue, size, and style. It’s not obvious how to add size and style. Well, with style, you could do hatching, but I have been reluctant to add hatching to seaborn because of limitations in the matplotlib API for hatches. Perhaps it would be possible to relax the constraint, but it’s the kind of thing that would add some complexity and so would need a good motivation.
  • Naturally the next step after giving the mouse the areaplot cookie is that they would want some “stacked” area plot milk. The logic that does stacking for filled densities or histograms assumes a different internal representation of the data than is in the relational plots. On a medium-long term time horizon, I’d like to make that more general, but I’d consider that a prerequisite to adding this.

So if the question is “should seaborn have an area plot that can’t do aggregation/errorbars and only has hue semantic mapping” my answer would probably be no because that exists in pandas builtin plotting and I try not to devote effort to straight up duplication of plots you can already make with matplotlib or pandas. If some of these problems can be solved, I’d consider it worth adding to seaborn. But it’s a low priority right now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I create a multiline plot using seaborn? - Stack Overflow
This: sns.lineplot(data=data_preproc). will do what you want.
Read more >
Pandas Line Plot | Python - Machine Learning Plus
Pandas provides you a quick and easy way to visualize the relationship between the features of a dataframe. The Pandas line plot represents ......
Read more >
Python Seaborn Data Visualization Tutorial for Beginners
Python Seaborn Complete Tutorial for Beginners. Seaborn Line Plot | Python Seaborn Data Visualization Tutorial for Beginners.
Read more >
Line chart - The R Graph Gallery
ggplot2 allows to draw line charts thanks to the geom_line() function. It expects as input a data frame with 2 numeric variables, one...
Read more >
A Complete Guide to Plotting Categorical Variables with ...
There are lots of questions to ask and relationships between ... can take an added hue argument to add another variable for comparison....
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