-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathfigure.py
More file actions
48 lines (34 loc) · 1.42 KB
/
Copy pathfigure.py
File metadata and controls
48 lines (34 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from __future__ import annotations
from typing import TypeVar
from matplotlib.artist import Artist
from matplotlib.figure import Figure
TArtist = TypeVar("TArtist", bound=Artist)
class p9Figure(Figure):
"""
Figure for plotnine plots
Stamps figure-level artists (added through the public methods
``add_artist``, ``add_subplot``, ``add_axes``, ``figimage``,
``text``) with strictly increasing zorders, so insertion order
dictates paint order — matplotlib stable-sorts by zorder before
rendering.
"""
_next_zorder: int
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# figure.patch sits at zorder 1; start above it.
self._next_zorder = 2
def _stamp(self, artist: TArtist) -> TArtist:
artist.set_zorder(self._next_zorder)
self._next_zorder += 1
return artist
def add_artist(self, artist: TArtist, *args, **kwargs) -> TArtist:
super().add_artist(artist, *args, **kwargs)
return self._stamp(artist)
def add_subplot(self, *args, **kwargs):
return self._stamp(super().add_subplot(*args, **kwargs))
def add_axes(self, *args, **kwargs):
return self._stamp(super().add_axes(*args, **kwargs))
def figimage(self, *args, **kwargs):
return self._stamp(super().figimage(*args, **kwargs))
def text(self, *args, **kwargs):
return self._stamp(super().text(*args, **kwargs))