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.

Unexpected behaviour in `stack_plot()`

See original GitHub issue

Description of the issue

I’ve been trying to use the stack_plot() function for some follow-up SR15 assessment, and noticed two major issues.

  1. Timeseries data starting with zero are ignored completely
  2. Multiple crossings of the zero baseline end up shown wrong

Illustration

import pandas as pd
import pyam
df = pyam.IamDataFrame(pd.DataFrame([
    ['a', 1, 2, 3, 4],
    ['b', 0, 1, 2, 3],
    ['c', -1, 1, -1, 1],
    ['d', 1, 1, 1, -1]
    ],
    columns=['variable', 2010, 2020, 2030, 2040],
), model='model_a', scenario='scen_a', region='World', unit='some_unit')
df.stack_plot()

image

More insights

In the source of stack_plot(), there is this docstring…

    # Sort lines so that negative timeseries are on the right, positive
    # timeseries are on the left and timeseries which go from positive to
    # negative are ordered such that the timeseries which goes negative first
    # is on the right (case of timeseries which go from negative to positive
    # is an edge case we haven't thought about as it's unlikely to apply to
    # us).

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
znichollscommented, Sep 7, 2019

I was thinking that splitting all timeseries data into a positive and negative component might do the trick… But making it pretty afterwards will be a pain.

Yep I think that’s probably best. Keeping track of colours and joining dots as they cross back and forth will be hard. If you do it with loops initially I think it should be easier to implement and then it can be refactored to vector operations afterwards.

0reactions
danielhuppmanncommented, Sep 7, 2019

I was thinking that splitting all timeseries data into a positive and negative component might do the trick… But making it pretty afterwards will be a pain.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected plotting behaviour using matplotlib and time ...
I'd like to plot a line graph of a time series using matlplotlib, however matplotlib will not plot all of my data unless...
Read more >
Unexpected behaviour of eigfields() - EasySpin forum
UPD. It seems that MATLAB function eig() sorts its output according to increment of eigenvalues. Top. Stefan Stoll ...
Read more >
Fixing too many ticks — Matplotlib 3.6.2 documentation
One common cause for unexpected tick behavior is passing a list of strings instead of numbers or datetime objects. This can easily happen...
Read more >
Matplotlib.pyplot.stackplot() in Python - GeeksforGeeks
Matplotlib.pyplot.stackplot() in Python. Improve Article ... Stackplot is used to draw a stacked area plot. It displays the complete data ...
Read more >
Data Visualization. Data visualization is the discipline of… | by Blake ...
After preparing the the data, we can use matplotlib's plot() function to create the ... functions to avoid any errors or unexpected behaviour...
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