Unexpected behaviour in `stack_plot()`
See original GitHub issueDescription of the issue
I’ve been trying to use the stack_plot()
function for some follow-up SR15 assessment, and noticed two major issues.
- Timeseries data starting with zero are ignored completely
- 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()
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:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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.