-
Notifications
You must be signed in to change notification settings - Fork 0
/
png_backend.py
60 lines (39 loc) · 1.26 KB
/
png_backend.py
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
49
50
51
52
53
54
55
56
57
58
59
60
"""
This submodule implements the PNG backend.
"""
from __future__ import print_function
import numpy as np
from mpl_base_backend import BackendMPL
class BackendPNG(BackendMPL):
"""
Backend for writing to PNG files
"""
def __init__(self):
BackendMPL.__init__(self)
self.name = '\PNG'
self.long_name = 'PNG backend'
self.interactive = False
from matplotlib.backends.backend_agg \
import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
self.FigureCanvas = FigureCanvas
self.Figure = Figure
self.max_auto_resolution = 1024
self.output_filename = ''
def init_figure(self):
"""
Create the figure
"""
self.fig = self.Figure()
self.canvas = self.FigureCanvas(self.fig)
def set_output_filename(self, filename):
"""
Set the output filename
"""
self.output_filename = filename
def output_canvas(self):
"""
Output canvas
"""
print('Writing to file {}.png...'.format(self.output_filename))
self.canvas.print_figure(self.output_filename)