Coordinates

coord_axes_inside

class plotnine_extra.coord_axes_inside(xlim=None, ylim=None, expand=True, xintercept=0.0, yintercept=0.0, labels_inside=False)[source]

Bases: plotnine.coord_cartesian

Cartesian coordinates with axes drawn inside the panel.

Parameters:
  • xlim – Same as coord_cartesian.

  • ylim – Same as coord_cartesian.

  • expand (bool) – Same as coord_cartesian.

  • xintercept (float, default 0) – x-position at which the y axis spine should sit.

  • yintercept (float, default 0) – y-position at which the x axis spine should sit.

  • labels_inside (bool, default False) – If True, tick labels are drawn alongside the relocated spine; otherwise the standard outer labels are kept.

Notes

Plotnine 0.15/0.16 does not expose a post-draw hook on the coord class. This implementation therefore wraps ggplot.draw() via __radd__ so that apply_axes_inside() is invoked on the resulting matplotlib Figure after plotnine finishes rendering. The standard axis spines are otherwise left alone by coord_cartesian.

is_linear = True

apply_axes_inside

plotnine_extra.apply_axes_inside(figure, xintercept=0.0, yintercept=0.0, labels_inside=False)[source]

Reposition the axis spines of every Axes in figure so that they cross at (xintercept, yintercept).

This is the manual half of coord_axes_inside. Call it after ggplot.draw():

fig = (p + coord_axes_inside(xintercept=5)).draw(show=False)
apply_axes_inside(fig, xintercept=5)
Parameters:
  • figure (Figure)

  • xintercept (float)

  • yintercept (float)

  • labels_inside (bool)

Return type:

Figure