Skip to content

Commit

Permalink
Add width and height aesthetics to geom_tile
Browse files Browse the repository at this point in the history
  • Loading branch information
has2k1 committed May 9, 2024
1 parent 0b5478a commit 34309f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion doc/changelog.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ title: Changelog

- Stopped spurious warnings of the form ``PlotnineWarning: Failed to apply
`after_scale` modifications to the legend.`` when the `after_scale`
mapping is for another aesthetic.
mapping is for another aestetic.

- Added `width` and `height` as default aesthetics of [](:class:`~plotnine.geom_tile`).

## v0.13.5
(2024-04-26)
Expand Down
12 changes: 10 additions & 2 deletions plotnine/geoms/geom_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class geom_tile(geom_rect):
"fill": "#333333",
"linetype": "solid",
"size": 0.1,
"width": None,
"height": None,
}
REQUIRED_AES = {"x", "y"}
DEFAULT_PARAMS = {
Expand All @@ -44,12 +46,18 @@ def setup_data(self, data: pd.DataFrame) -> pd.DataFrame:
try:
width = data.pop("width")
except KeyError:
width = resolution(data["x"], False)
width = self.aes_params.get(
"width",
resolution(data["x"], False),
)

try:
height = data.pop("height")
except KeyError:
height = resolution(data["y"], False)
height = self.aes_params.get(
"height",
resolution(data["y"], False),
)

data["xmin"] = data["x"] - width / 2
data["xmax"] = data["x"] + width / 2
Expand Down

0 comments on commit 34309f3

Please sign in to comment.