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.

Add stacked lines to stacked area plot

See original GitHub issue

Is your feature request related to a problem? Please describe. I wonder whether stacked lines could be added to stacked area plots (vstack_area()), which is the default in Seaborn or Plotly for example.

Describe the solution you’d like Stacked line (vline_stack()) and area (vstack_area()) plots take mostly the same arguments. One solution would be to just call vline_stack every time vstack_area is called. The solution I wanted to suggest in a PR for discussion is a bit more flexible, as it allows a line_width argument to be specified, in which case vline_stack is called. bokeh/plotting/figure.py:

def varea_stack(self, stackers, **kw):
    result = []
    if 'line_width' in kw:
        line_width = kw['line_width']
        kw.pop('line_width')
        result.append(self.vline_stack(stackers=stackers, line_width=line_width, **kw))
    for kw in double_stack(stackers, "y1", "y2", **kw):
        result.append(self.varea(**kw))
    return result

instead of

def varea_stack(self, stackers, **kw):
    result = []
    for kw in double_stack(stackers, "y1", "y2", **kw):
        result.append(self.varea(**kw))
    return result

This relies on vline_stack() and vstack_area() not diverging in future versions however. You will also notice that the legend has changed: it can be fixed if people think it’s an issue.

Describe alternatives you’ve considered One could just call vline_stack() whenever they make a stacked area plot, but other libraries seem to have chosen a different default.

Additional context Without stacked lines Without stacked lines

np.random.seed(seed=10)
df = pd.DataFrame(np.random.randint(10, 100, size=(15, 10))).add_prefix('y')

p = figure(x_range=(0, len(df)-1), y_range=(0, 800))
names = ["y%d" % i for i in range(10)]

p.varea_stack(
    stackers=names, x='index', 
    color=brewer['Spectral'][10], 
    legend_label=names, 
    source=df,
    line_width=2, 
    alpha=0.5,
)
p.legend.items.reverse()

show(p)

With stacked lines With stacked lines

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
bryevdvcommented, May 22, 2020

@harabat Offhand I think I am -1 on adding line properties to the low level VArea itself. I think your initial implementation, that confines changes to the higher level “stacked” glyph helpers, is a perfectly reasonable direction to pursue, it just needs to be more careful and thorough about handling the arguments. I’ll have to think about it some more.

Regardless, I am definitely reticent to start defaulting the alpha to anything other than 1. There is no default glyph in Bokeh that this is the case for, and apart from being a breaking change, I think it is good to keep the consistent expectation “If I want alpha, I have to set it” true everywhere. I’d be more inclined to follow the seaborn example where the line and area alpha are both 1 but the line color defaults to white to leave “line gaps” between the areas. We would want to start off with a default line_color=None in 2.x to avoid breaking changes, then change to line_color="white" default in Bokeh 3.0 when a breaking change can be made.

0reactions
harabatcommented, Sep 3, 2020

Turns out I forgot we had identified several options and didn’t actually decide on either.

Rereading through the discussions, I’m more inclined to go with my original approach and your comments on it: confine changes to varea_stack, while making sure all lineprops arguments are accounted for, and add line renderers with line_color=None by default (to switch to line_color='white' in 3.0).

My gripes with the option of adding a new vstack helper are that it’d be a confusing stack function, compared with the more clear cut varea_stack, vline_stack, and vbar_stack. Also, I can’t help but side with Seaborn and Pandas on the idea of having lines by default in stacked area charts.

Obviously, the above holds for the horizontal equivalents as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Add a Line to an Excel Stacked Chart - Techwalla
Click "Add" in the "Select Data Series" dialog box under "Legend Entries." Step 3. Enter the data range you want to use for...
Read more >
How to Create an Area Chart in Excel (explained with Examples)
Creating a Stacked Area Chart · Select the entire dataset (A1:D6) · Click the Insert tab. · In the Chart group, click on...
Read more >
Stacked area chart - Python Graph Gallery
A collection of stacked area chart examples made with Python, coming with explanation and reproducible code.
Read more >
Stacked Area Chart with Line in Excel (2 Practical Examples)
we'll learn how Excel stacked area chart with line using the Insert tab and so on effectively with appropriate illustrations.
Read more >
A Complete Guide to Area Charts | Tutorial by Chartio
In the stacked area chart, lines are plotted one at a time, with the height of the most recently-plotted group serving as a...
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