Skip to content

Commit

Permalink
Squash and rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhuppmann committed Jul 28, 2021
1 parent 32fcd33 commit a5a40be
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ the attribute `_LONG_IDX` as deprecated. Please use `dimensions` instead.
## Individual updates

- [#564](https://github.com/IAMconsortium/pyam/pull/564) Add an example with a secondary axis to the plotting gallery
- [#563](https://github.com/IAMconsortium/pyam/pull/563) Enable `colors` keyword argument as list in `plot.pie()`
- [#560](https://github.com/IAMconsortium/pyam/pull/560) Add a feature to `swap_year_for_time()`
- [#559](https://github.com/IAMconsortium/pyam/pull/559) Add attribute `dimensions`, fix compatibility with pandas v1.3
- [#557](https://github.com/IAMconsortium/pyam/pull/557) Swap time for year keeping subannual resolution
Expand Down
29 changes: 17 additions & 12 deletions pyam/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def pie(
value="value",
category="variable",
legend=False,
title=True,
title=False,
ax=None,
cmap=None,
**kwargs,
Expand Down Expand Up @@ -313,8 +313,7 @@ def pie(
for col in set(SORT_IDX) - set([category]):
if len(df[col].unique()) > 1:
msg = (
"Can not plot multiple {}s in a pie plot with value={},"
+ " category={}"
"Can not plot multiple {}s in a pie plot with value={} and category={}"
)
raise ValueError(msg.format(col, value, category))

Expand All @@ -332,19 +331,25 @@ def pie(
"color"
]
rc = run_control()
color = []
for key, c in zip(_df.index, defaults):
if "color" in rc and category in rc["color"] and key in rc["color"][category]:
c = rc["color"][category][key]
color.append(c)

if "colors" in kwargs:
colors = kwargs.pop("colors")
else:
colors = []
for key, c in zip(_df.index, defaults):
if category in rc["color"] and key in rc["color"][category]:
c = rc["color"][category][key]
colors.append(c)

# plot data
_df.plot(kind="pie", colors=color, ax=ax, explode=explode, **kwargs)
_df.plot(kind="pie", colors=colors, ax=ax, explode=explode, **kwargs)

# add legend
# add legend and title
ax.legend(loc="center left", bbox_to_anchor=(1.0, 0.5), labels=_df.index)
if not legend:
ax.legend_.remove()
if title:
ax.set_title(title)

# remove label
ax.set_ylabel("")
Expand Down Expand Up @@ -1081,7 +1086,7 @@ def line(
.T.interpolate(method="index")
.T # interpolate
)
mins = pd.concat([allmins, intermins]).min(level=0)
mins = pd.concat([allmins, intermins]).groupby(level=0).min()
allmaxs = data.groupby(color).max()
intermaxs = (
data.dropna(axis=1)
Expand All @@ -1091,7 +1096,7 @@ def line(
.T.interpolate(method="index")
.T # interpolate
)
maxs = pd.concat([allmaxs, intermaxs]).max(level=0)
maxs = pd.concat([allmaxs, intermaxs]).groupby(level=0).max()
# do the fill
for idx in mins.index:
ymin = mins.loc[idx]
Expand Down
Binary file added tests/expected_figs/test_pie_plot_colors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expected_figs/test_pie_plot_other.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,18 @@ def test_pie_plot_legend(plot_df):
return fig


@pytest.mark.mpl_image_compare(**MPL_KWARGS)
def test_pie_plot_colors(plot_df):
fig, ax = plt.subplots(figsize=(8, 8))
with update_run_control(RC_TEST_DICT):
(
plot_df.filter(
variable="Primary Energy", model="test_model", year=2010
).plot.pie(ax=ax, category="scenario", colors=["red", "blue"], title="foo")
)
return fig


@pytest.mark.mpl_image_compare(**MPL_KWARGS)
def test_pie_plot_other(plot_df):
fig, ax = plt.subplots(figsize=(8, 8))
Expand Down

0 comments on commit a5a40be

Please sign in to comment.