Skip to content

Commit

Permalink
fix stack plot bug part 1 issue 266 (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
znicholls authored and danielhuppmann committed Oct 19, 2019
1 parent 1d0d5d2 commit 151bc67
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

# Next Release

- [#270](https://github.com/IAMconsortium/pyam/pull/270) Include variables with zeros in `stack_plot` (see [#266](https://github.com/IAMconsortium/pyam/issues/266))
- [#269](https://github.com/IAMconsortium/pyam/pull/269) Ensure append doesn't accidentally swap indexes
- [#268](https://github.com/IAMconsortium/pyam/pull/268) Update `aggregate_region` so it can find variables below sub-cateogories too
- [#267](https://github.com/IAMconsortium/pyam/pull/267) Make clear error message if variable-region pair is missing when `check_aggregate_region` is called
Expand Down
2 changes: 1 addition & 1 deletion pyam/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def stack_plot(df, x='year', y='value', stack='variable',
# 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).
pos_cols = [c for c in _df if (_df[c] > 0).all()]
pos_cols = [c for c in _df if (_df[c] >= 0).all()]
cross_cols = first_zero_times.columns[::-1].tolist()
neg_cols = [c for c in _df if (_df[c] < 0).all()]
col_order = pos_cols + cross_cols + neg_cols
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,3 +580,21 @@ def test_stack_plot_negative_emissions_kwargs_custom_total(plot_stack_plot_df):
ax=ax,
)
return fig


@pytest.mark.mpl_image_compare(**MPL_KWARGS)
def test_stack_plot_missing_zero_issue_266(plot_stack_plot_df):
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')

fig, ax = plt.subplots(figsize=(8, 8))
df.stack_plot(ax=ax)

return fig

0 comments on commit 151bc67

Please sign in to comment.