Skip to content

Commit 92ef944

Browse files
committed
adding bounding rectangle for figure
1 parent b1352c1 commit 92ef944

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pygame_matplotlib/backend_pygame.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ def __init__(self, *args, **kwargs):
2424
pygame.Surface.__init__(self, self.bbox.size)
2525
self.fill('white')
2626

27+
def set_bounding_rect(self, rect: pygame.Rect):
28+
"""Set a bounding rectangle around the figure."""
29+
# First convert inches to pixels for matplotlib
30+
DPI = self.get_dpi()
31+
self.set_size_inches(rect.width/float(DPI), rect.height/float(DPI))
32+
# Initialize a new surface for the plot
33+
pygame.Surface.__init__(self, (rect.width, rect.height))
34+
# Redraw the figure
35+
self.canvas.draw()
36+
2737
class RendererPygame(RendererBase):
2838
"""The renderer handles drawing/rendering operations.
2939

0 commit comments

Comments
 (0)