Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable colors as list in plot.pie() #563

Merged
merged 5 commits into from
Jul 30, 2021

Conversation

danielhuppmann
Copy link
Member

@danielhuppmann danielhuppmann commented Jul 21, 2021

Please confirm that this PR has done the following:

  • Tests Added
  • Documentation Added
  • Name of contributors Added to AUTHORS.rst
  • Description in RELEASE_NOTES.md Added

Description of PR

This PR enables passing an explicit colors arg as list to to the pie plot, see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pie.html

It also implements the title keyword argument, which was previously ignored in the implementation, and future-proofs pandas (using min(level=0) will be disabled).

@codecov
Copy link

codecov bot commented Jul 21, 2021

Codecov Report

Merging #563 (c4b7935) into main (32fcd33) will increase coverage by 0.0%.
The diff coverage is 100.0%.

Impacted file tree graph

@@          Coverage Diff          @@
##            main    #563   +/-   ##
=====================================
  Coverage   93.6%   93.7%           
=====================================
  Files         50      50           
  Lines       5313    5322    +9     
=====================================
+ Hits        4978    4987    +9     
  Misses       335     335           
Impacted Files Coverage Δ
pyam/plotting.py 92.9% <100.0%> (+<0.1%) ⬆️
tests/test_plotting.py 100.0% <100.0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 32fcd33...c4b7935. Read the comment docs.

@danielhuppmann danielhuppmann requested a review from gidden July 21, 2021 19:56
@danielhuppmann danielhuppmann marked this pull request as ready for review July 21, 2021 19:56
Copy link
Member

@gidden gidden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great new feature! Some small adjustments requested. Is it possible to add a test of some kind for the 'future proofing' via groupby? Not required given all tests currently pass, but would be nice for future us's to not change..

pyam/plotting.py Outdated
@@ -274,7 +274,7 @@ def pie(
value="value",
category="variable",
legend=False,
title=True,
title=False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I would suggest a default value of None. In other plotting funcs, title can be True if there is logic available to find a reasonable default. If not, then it will be set by the kwarg value. Would suggest also updating docstring to string, optional

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - also change the docstring for the title keyword argument to follow Axes.set_title()

(
plot_df.filter(
variable="Primary Energy", model="test_model", year=2010
).plot.pie(ax=ax, category="scenario", colors=["red", "blue"], title="foo")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is pedantic, but can you use values other than red and blue here so this test is easily visually distinguishable from the default values (e.g. in test_pie_plot_labels.png).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@danielhuppmann
Copy link
Member Author

Thanks for the suggestions, all implemented!

Not quite sure what you mean by adding a test for resolving a future-warning? If you go back to a previous test run, section "Test with pytest", line 270, there is a warning that this particular code will stop working. If you compare this to the current test runs, this warning is gone. (There are plenty of others, though, tackling them one at a time).

@gidden
Copy link
Member

gidden commented Jul 30, 2021

Not quite sure what you mean by adding a test for resolving a future-warning? If you go back to a previous test run, section "Test with pytest", line 270, there is a warning that this particular code will stop working. If you compare this to the current test runs, this warning is gone. (There are plenty of others, though, tackling them one at a time).

Specifically the line

mins = pd.concat([allmins, intermins]).groupby(level=0).min()

I was curious it is was possible to add any test for this. If not, that's fine.

@gidden
Copy link
Member

gidden commented Jul 30, 2021

Ahh ok, I understand now. Thanks!

@gidden gidden merged commit 666da23 into IAMconsortium:main Jul 30, 2021
@danielhuppmann danielhuppmann deleted the plotting/pie branch July 30, 2021 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants