File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change 7
7
"""
8
8
import matplotlib .pyplot as plt
9
9
import numpy as np
10
+ from matplotlib .figure import Figure
11
+ from matplotlib .backends .backend_agg import FigureCanvas
10
12
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 ()
13
19
ax .plot ([1 , 2 , 3 ])
14
20
ax .set_title ('a simple figure' )
15
- fig . canvas . draw ()
16
-
21
+ # Force a draw so we can grab the pixel buffer
22
+ canvas . draw ()
17
23
# 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 ())
19
25
20
26
# now display the array X as an Axes in a new figure
21
27
fig2 = plt .figure ()
You can’t perform that action at this time.
0 commit comments