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

fix bug when declaring a cmap and color argument would produce len(df… #200

Merged
merged 7 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [#212](https://github.com/IAMconsortium/pyam/pull/212) Now natively support reading R-style data frames with year columns like "X2015"
- [#202](https://github.com/IAMconsortium/pyam/pull/202) Extend the `df.rename()` function with a `check_duplicates (default True)` validation option
- [#201](https://github.com/IAMconsortium/pyam/pull/201) Added native support for legends outside of plots with `pyam.plotting.OUTSIDE_LEGEND` with a tutorial
- [#200](https://github.com/IAMconsortium/pyam/pull/200) Bugfix when providing `cmap` and `color` arguments to plotting functions
- [#199](https://github.com/IAMconsortium/pyam/pull/199) Initializing an `IamDataFrame` accepts kwargs to fill or create from the data any missing required columns
- [#197](https://github.com/IAMconsortium/pyam/pull/197) Added a `normalize` function that normalizes all data in a data frame to a specific time period.
- [#195](https://github.com/IAMconsortium/pyam/pull/195) Fix filtering for `time`, `day` and `hour` to use generic `pattern_match()` (if such a column exists) in 'year'-formmatted IamDataFrames
Expand Down
10 changes: 7 additions & 3 deletions pyam/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

from pyam.logger import logger
from pyam.run_control import run_control
from pyam.utils import requires_package, SORT_IDX, isstr
from pyam.utils import requires_package, IAMC_IDX, SORT_IDX, isstr

from pandas.plotting._style import _get_standard_colors

Expand Down Expand Up @@ -108,9 +108,13 @@ def assign_style_props(df, color=None, marker=None, linestyle=None,
df : pd.DataFrame
data to be used for style properties
"""
if color is None and cmap is not None:
raise ValueError('`cmap` must be provided with the `color` argument')

# determine color, marker, and linestyle for each line
defaults = default_props(reset=True, num_colors=len(df),
colormap=cmap)
n = len(df[color].unique()) if color in df.columns else \
len(df[list(set(df.columns) & set(IAMC_IDX))].drop_duplicates())
defaults = default_props(reset=True, num_colors=n, colormap=cmap)

props = {}
rc = run_control()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ def test_line_plot(plot_df):
return fig


def test_line_plot_cmap(plot_df):
# need to provide cmap and color both
_plot_df = copy.deepcopy(plot_df)
_plot_df.set_meta(meta=[np.nan] * 4, name='test')
pytest.raises(ValueError, _plot_df.line_plot, cmap='magma')


@pytest.mark.mpl_image_compare(**MPL_KWARGS)
def test_line_plot_cmap_color_arg(plot_df):
_plot_df = copy.deepcopy(plot_df)
_plot_df.set_meta(meta=[np.nan] * 4, name='test')
fig, ax = plt.subplots(figsize=(8, 8))
_plot_df.line_plot(ax=ax, legend=True, cmap='magma', color='variable')
return fig


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