Basic scatter plotter for simple lines

Parameters allow users to change the configuration of an plotter when scheduling an experiment

Name Description Type Default
xlabel The label of the X-axis (horizontal) string X
ylabel The label of the Y-axis (vertical) string Y
title The title for this plot string Scatter plot
xaxis_multiplier The multiplication factor for the X-axis (horizontal) float64 1.0
yaxis_multiplier The multiplication factor for the Y-axis (vertical) float64 1.0
legend Short description of the data, to be added to the plot string
grid If we should draw grid lines or not for the plot bool False
xaxis_log If X-axis (horizontal) should be in log-scale bool False
yaxis_log If Y-axis (vertical) should be in log-scale bool False
dpi Dots-per-inch in raster image formats uint16 60
width Width of the resulting image in pixels uint16 400
height Height of the resulting image in pixels uint16 300
content_type The type of image returned string image/png
line_attributes Scatter/Line attributes passed directly to Matplotlib string
xxxxxxxxxx
58
 
1
# Makes sure we won't require an X11 connection
2
import matplotlib
3
matplotlib.use('Agg')
4
import matplotlib.pyplot
5
6
import numpy
7
import itertools
8
9
10
class Plotter(baselib.Plotter):
11
12
    def setup(self, parameters):
13
14
        super(Plotter, self).setup(parameters)
15
        self.line_attributes = parameters.get('line_attributes', '').split('&')
16
        self.line_attributes = [k for k in self.line_attributes if k]
17
        return True
18
19
20
    def process(self, inputs):
21
22
        fig, ax = super(Plotter, self).prepare_canvas()
23
24
        colormap = matplotlib.pyplot.cm.gist_ncar
25
        ax.set_color_cycle([colormap(k) for k in numpy.linspace(0, 0.9, len(inputs))])
26
        
27
        args = []
28
        label = []
29
30
        single_experiment = len(inputs) == 1
31
32
        for xp_label, xp_data in inputs:
33
            for scatter in xp_data.data:
34
35
                # the data
36
                args.append(scatter.x * self.xaxis_multiplier)
37
                args.append(scatter.y * self.yaxis_multiplier)
38
39
                # the label
40
                if self.label: #gets the label from user overwritten input
41
                    label.append(self.label[len(label)%len(self.label)])
42
                else: #make-up label
43
                    if single_experiment:
44
                        label.append(scatter.label)
45
                    else:
46
                        text = [k for k in (xp_label, scatter.label) if k]
47
                        label.append('-'.join(text))
48
49
                # the line attributes
50
                if self.line_attributes:
51
                    args.append(self.line_attributes[len(label)%len(self.line_attributes)])
52
53
        lines = ax.plot(*args)
54
        if len(lines) > 1:
55
            ax.legend(lines, label, loc='best', fancybox=True, framealpha=0.5)
56
57
        super(Plotter, self).apply_parameters(ax)
58
        return super(Plotter, self).encode_figure(fig)

This is the default plotter for scatter plots. It provides sensible defaults in case the user has not selected any.

No reports are using this plotter.
Created with Raphaël 2.1.2[compare]plot/scatter/12015May4
Terms of Service | Contact Information | BEAT platform version 2.2.1b0 | © Idiap Research Institute - 2013-2025