Skip to content
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
5 changes: 5 additions & 0 deletions doc/changelog.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ title: Changelog
the closing edge of a polygon is now curved along with the rest of its
boundary instead of being drawn as a straight chord.

- Stacked bars in a non-linear coordinate system (e.g.
[](:class:`~plotnine.coord_trans`)) no longer show triangular spikes; each
rectangle is now drawn as its own polygon instead of merging a bar's
segments into a single path.

- The space between facet panels now accounts for the margins of the axis
text, so with free scales large margins no longer push the tick labels
into the neighbouring panel.
Expand Down
5 changes: 5 additions & 0 deletions plotnine/geoms/geom_rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def draw_panel(
"""
if not coord.is_linear:
data = _rectangles_to_polygons(data)
# Each rectangle is its own closed polygon. Grouping by the
# `group` aesthetic would merge a stacked bar's segments into one
# open path, and coord.munch would then bend the join between
# consecutive rectangles into a spurious spike.
data["group"] = np.repeat(np.arange(len(data) // 4), 4)
for _, gdata in data.groupby("group"):
gdata.reset_index(inplace=True, drop=True)
geom_polygon.draw_group(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions tests/test_coords.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
coord_flip,
coord_trans,
geom_bar,
geom_col,
geom_line,
geom_point,
geom_polygon,
ggplot,
xlim,
)
from plotnine.data import mtcars

n = 10 # Some even number greater than 2

Expand Down Expand Up @@ -90,6 +92,14 @@ def test_coord_trans_munches_polygon_closing_edge():
assert p == "coord_trans_munches_polygon_closing_edge"


def test_coord_trans_stacked_bars_have_no_spikes():
# Each stacked segment must be its own polygon. If they merge into one
# path, the join between consecutive segments becomes a diagonal that
# munch subdivides into a triangular spike across the bar.
p = ggplot(mtcars, aes("factor(cyl)", "mpg")) + geom_col() + coord_trans()
assert p == "coord_trans_stacked_bars_have_no_spikes"


def test_datetime_coord_limits():
n = 6

Expand Down
Loading