File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77"""
88import matplotlib .pyplot as plt
99import numpy as np
10+ from matplotlib .figure import Figure
11+ from matplotlib .backends .backend_agg import FigureCanvas
1012
11- # make an agg figure
12- fig , ax = plt .subplots ()
13+ # Create a figure that pyplot does not know about.
14+ fig = Figure ()
15+ # attach a non-interactive Agg canvas to the figure
16+ # (as a side-effect of the ``__init__``)
17+ canvas = FigureCanvas (fig )
18+ ax = fig .subplots ()
1319ax .plot ([1 , 2 , 3 ])
1420ax .set_title ('a simple figure' )
15- fig . canvas . draw ()
16-
21+ # Force a draw so we can grab the pixel buffer
22+ canvas . draw ()
1723# grab the pixel buffer and dump it into a numpy array
18- X = np .array (fig . canvas .renderer .buffer_rgba ())
24+ X = np .array (canvas .renderer .buffer_rgba ())
1925
2026# now display the array X as an Axes in a new figure
2127fig2 = plt .figure ()
You can’t perform that action at this time.
0 commit comments