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
13 changes: 8 additions & 5 deletions plotnine/facets/facet.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,14 @@ def _inf_to_none(
ax.xaxis.set_major_formatter(MyFixedFormatter(panel_params.x.labels))
ax.yaxis.set_major_formatter(MyFixedFormatter(panel_params.y.labels))

pad_x = theme.get_margin("axis_text_x").pt.t
pad_y = theme.get_margin("axis_text_y").pt.r

ax.tick_params(axis="x", which="major", pad=pad_x)
ax.tick_params(axis="y", which="major", pad=pad_y)
# Blank axis text is not drawn, so its margin may be absent
# (resolves to None). Skip the tick-label padding in that case.
if not theme.T.is_blank("axis_text_x"):
pad_x = theme.get_margin("axis_text_x").pt.t
ax.tick_params(axis="x", which="major", pad=pad_x)
if not theme.T.is_blank("axis_text_y"):
pad_y = theme.get_margin("axis_text_y").pt.r
ax.tick_params(axis="y", which="major", pad=pad_y)

def __deepcopy__(self, memo: dict[Any, Any]) -> facet:
"""
Expand Down
8 changes: 8 additions & 0 deletions tests/test_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,11 @@ def test_override_axis_text():
)

assert p == "override_axis_text"


def test_blank_all_text_draws():
# Blanking the base `text` element removes every specific text
# themeable, so axis_text_x/_y margins resolve to None. Drawing must
# not crash when computing the tick-label padding. (Regression)
p = ggplot() + lims(x=(0, 100), y=(0, 100)) + theme(text=element_blank())
p.draw_test() # pyright: ignore # must not raise
Loading