Skip to content

Commit

Permalink
Correct line plot title (#176)
Browse files Browse the repository at this point in the history
* updated title operation for line_plot function and corrected some pep8 issues

* updated title operation for line_plot function and corrected some pep8 issues - second try

* updated release notes

* corrected title for line plots
  • Loading branch information
OFR-IIASA authored and gidden committed Jan 24, 2019
1 parent 8a6ca9c commit 8f1d58e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
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

- [#176](https://github.com/IAMconsortium/pyam/pull/176) Corrected title setting operation in line_plot function
- [#175](https://github.com/IAMconsortium/pyam/pull/175) Update link to tutorial in readme.md
- [#174](https://github.com/IAMconsortium/pyam/pull/174) Add a function `difference()` to compare two IamDataFrames
- [#171](https://github.com/IAMconsortium/pyam/pull/171) Fix a bug when reading from an `ixmp.TimeSeries` object, refactor to mitigate circular dependency
Expand Down
36 changes: 19 additions & 17 deletions pyam/plotting.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import itertools
import os
import warnings

try:
Expand Down Expand Up @@ -135,7 +134,7 @@ def reshape_bar_plot(df, x, y, bars):
@requires_package(gpd, 'Requires geopandas')
@lru_cache()
def read_shapefile(fname, region_col=None, **kwargs):
"""Read a shapefile for use in regional plots. Shapefiles must have a
"""Read a shapefile for use in regional plots. Shapefiles must have a
column denoted as "region".
Parameters
Expand All @@ -156,9 +155,9 @@ def read_shapefile(fname, region_col=None, **kwargs):

@requires_package(gpd, 'Requires geopandas')
@requires_package(cartopy, 'Requires cartopy')
def region_plot(df, column='value', ax=None, crs=None, gdf=None, add_features=True,
vmin=None, vmax=None, cmap=None, cbar=True, legend=False,
title=True):
def region_plot(df, column='value', ax=None, crs=None, gdf=None,
add_features=True, vmin=None, vmax=None, cmap=None,
cbar=True, legend=False, title=True):
"""Plot data on a map.
Parameters
Expand All @@ -181,10 +180,10 @@ def region_plot(df, column='value', ax=None, crs=None, gdf=None, add_features=Tr
cmap : string, optional
The colormap to use.
cbar : bool or dictionary, optional, default: True
Add a colorbar. If a dictionary is provided, it will be used as keyword
Add a colorbar. If a dictionary is provided, it will be used as keyword
arguments in creating the colorbar.
legend : bool or dictionary, optional, default: False
Add a legend. If a dictionary is provided, it will be used as keyword
Add a legend. If a dictionary is provided, it will be used as keyword
arguments in creating the legend.
title : bool or string, optional
Display a default or custom title.
Expand Down Expand Up @@ -293,7 +292,8 @@ def pie_plot(df, value='value', category='variable',
"""
for col in set(SORT_IDX) - set([category]):
if len(df[col].unique()) > 1:
msg = 'Can not plot multiple {}s in pie_plot with value={}, category={}'
msg = 'Can not plot multiple {}s in pie_plot with value={},' +\
' category={}'
raise ValueError(msg.format(col, value, category))

if ax is None:
Expand Down Expand Up @@ -378,7 +378,8 @@ def stack_plot(df, x='year', y='value', stack='variable',
colors = []
for key in _df.columns:
c = next(defaults)
if 'color' in rc and stack in rc['color'] and key in rc['color'][stack]:
if 'color' in rc and stack in rc['color'] and\
key in rc['color'][stack]:
c = rc['color'][stack][key]
colors.append(c)

Expand Down Expand Up @@ -797,14 +798,15 @@ def line_plot(df, x='year', y='value', ax=None, legend=None, title=True,
ax.set_ylabel(ylabel)

# build a default title if possible
_title = []
for var in ['model', 'scenario', 'region', 'variable']:
if var in df.columns.names:
values = df.columns.get_level_values(var).unique()
if len(values) == 1:
_title.append('{}: {}'.format(var, values[0]))
if title and _title:
ax.set_title(' '.join(_title))
if title:
default_title = []
for var in ['model', 'scenario', 'region', 'variable']:
if var in df.columns.names:
values = df.columns.get_level_values(var).unique()
if len(values) == 1:
default_title.append('{}: {}'.format(var, values[0]))
title = ' '.join(default_title) if title is True else title
ax.set_title(title)

return ax, handles, labels

Expand Down

0 comments on commit 8f1d58e

Please sign in to comment.