Skip to content

Commit

Permalink
ENH: rects with infinite coordinates
Browse files Browse the repository at this point in the history
closes #166
  • Loading branch information
has2k1 committed Aug 1, 2018
1 parent 3029492 commit 013b8bc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ Enhancements
- You can now use a ``dict`` (with manual scales) to map data values to
aesthetics (:issue:`169`).

- You can now specify infinite coordinates with :class:`plotnine.geoms.geom_rect`
(:issue:`166`)

Bug Fixes
*********

Expand Down
10 changes: 10 additions & 0 deletions plotnine/geoms/geom_rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from matplotlib.collections import PolyCollection
from six.moves import zip
import numpy as np

from ..utils import to_rgba, SIZE_FACTOR
from ..doctools import document
Expand Down Expand Up @@ -39,6 +40,15 @@ def draw_group(data, panel_params, coord, ax, **params):
data = coord.transform(data, panel_params, munch=True)
data['size'] *= SIZE_FACTOR
verts = [None] * len(data)

# Make it easy to specify rects that fill the x|y range
xlimits = panel_params['x_range']
ylimits = panel_params['y_range']
data['xmin'].replace(-np.inf, xlimits[0], inplace=True)
data['xmax'].replace(np.inf, xlimits[1], inplace=True)
data['ymin'].replace(-np.inf, ylimits[0], inplace=True)
data['ymax'].replace(np.inf, ylimits[1], inplace=True)

limits = zip(data['xmin'], data['xmax'],
data['ymin'], data['ymax'])

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 26 additions & 1 deletion plotnine/tests/test_geom_rect_tile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import absolute_import, division, print_function

import pandas as pd
import numpy as np

from plotnine import ggplot, aes, geom_rect, geom_tile, labs, theme
from plotnine import ggplot, aes, geom_point, geom_rect, geom_tile, labs, theme

n = 4

Expand Down Expand Up @@ -72,3 +73,27 @@ def test_tile_aesthetics():
_theme)

assert p == 'tile-aesthetics'


def test_infinite_rects():
df = pd.DataFrame({
'x': range(10),
'y': range(10)
})
rdf = pd.DataFrame({
'xmin': [3],
'xmax': 7,
'ymin': -np.inf,
'ymax': np.inf,
})

p = (ggplot(df, aes('x', 'y'))
+ geom_point()
+ geom_rect(
data=rdf,
mapping=aes(xmin='xmin', xmax='xmax', ymin='ymin', ymax='ymax'),
alpha=0.2,
inherit_aes=False)
)

assert p == 'infinite-rects'

0 comments on commit 013b8bc

Please sign in to comment.