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
# Makes sure we won't require an X11 connection
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot
import numpy
import itertools
class Plotter(baselib.Plotter):
def setup(self, parameters):
super(Plotter, self).setup(parameters)
self.line_attributes = parameters.get('line_attributes', '').split('&')
self.line_attributes = [k for k in self.line_attributes if k]
return True
def process(self, inputs):
fig, ax = super(Plotter, self).prepare_canvas()
colormap = matplotlib.pyplot.cm.gist_ncar
ax.set_color_cycle([colormap(k) for k in numpy.linspace(0, 0.9, len(inputs))])
args = []
label = []
single_experiment = len(inputs) == 1
for xp_label, xp_data in inputs:
for scatter in xp_data.data:
# the data
args.append(scatter.x * self.xaxis_multiplier)
args.append(scatter.y * self.yaxis_multiplier)
# the label
if self.label: #gets the label from user overwritten input
label.append(self.label[len(label)%len(self.label)])
else: #make-up label
if single_experiment:
label.append(scatter.label)
else:
text = [k for k in (xp_label, scatter.label) if k]
label.append('-'.join(text))
# the line attributes
if self.line_attributes:
args.append(self.line_attributes[len(label)%len(self.line_attributes)])
lines = ax.plot(*args)
if len(lines) > 1:
ax.legend(lines, label, loc='best', fancybox=True, framealpha=0.5)
super(Plotter, self).apply_parameters(ax)
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.