Debian Codegraph @

mplexporter/renderers/vincent_renderer.py

raw symbols SCIP
1 import warnings
2 from .base import Renderer
3 from ..exporter import Exporter
4
5
6 class VincentRenderer(Renderer):
7 def open_figure(self, fig, props):
8 self.chart = None
9 self.figwidth = int(props['figwidth'] * props['dpi'])
10 self.figheight = int(props['figheight'] * props['dpi'])
11
12 def draw_line(self, data, coordinates, style, label, mplobj=None):
13 import vincent # only import if VincentRenderer is used
14 if coordinates != 'data':
15 warnings.warn("Only data coordinates supported. Skipping this")
16 linedata = {'x': data[:, 0],
17 'y': data[:, 1]}
18 line = vincent.Line(linedata, iter_idx='x',
19 width=self.figwidth, height=self.figheight)
20
21 # TODO: respect the other style settings
22 line.scales['color'].range = [style['color']]
23
24 if self.chart is None:
25 self.chart = line
26 else:
27 warnings.warn("Multiple plot elements not yet supported")
28
29 def draw_markers(self, data, coordinates, style, label, mplobj=None):
30 import vincent # only import if VincentRenderer is used
31 if coordinates != 'data':
32 warnings.warn("Only data coordinates supported. Skipping this")
33 markerdata = {'x': data[:, 0],
34 'y': data[:, 1]}
35 markers = vincent.Scatter(markerdata, iter_idx='x',
36 width=self.figwidth, height=self.figheight)
37
38 # TODO: respect the other style settings
39 markers.scales['color'].range = [style['facecolor']]
40
41 if self.chart is None:
42 self.chart = markers
43 else:
44 warnings.warn("Multiple plot elements not yet supported")
45
46
47 def fig_to_vincent(fig):
48 """Convert a matplotlib figure to a vincent object"""
49 renderer = VincentRenderer()
50 exporter = Exporter(renderer)
51 exporter.run(fig)
52 return renderer.chart