def generate_multiplot(self, values: Dict[str, Any] = None): # TOCHECK Avoid circular imports import plot_data from plot_data.colors import BLACK, LIGHTBLUE, LIGHTGREY, BLUE if values is None: values = [] for i, line in enumerate(self.array): value = {} for variable in self.variables: value[variable] = self.get_value_by_name(line, variable) # for objective_name, ratings in objective_ratings.items(): # value[objective_name] = ratings[i] values.append(value) fontsize = 12 first_vars = self.variables[:2] values2d = [{key: val[key]} for key in first_vars for val in values] rgbs = [[192, 11, 11], [14, 192, 11], [11, 11, 192]] tooltip = plot_data.Tooltip(to_disp_attribute_names=self.variables, name='Tooltip') scatterplot = plot_data.Scatter(axis=plot_data.Axis(), tooltip=tooltip, to_disp_attribute_names=first_vars, elements=values2d, name='Scatter Plot') parallelplot = plot_data.ParallelPlot( disposition='horizontal', to_disp_attribute_names=self.variables, rgbs=rgbs, elements=values) objects = [scatterplot, parallelplot] sizes = [ plot_data.Window(width=560, height=300), plot_data.Window(width=560, height=300) ] coords = [(0, 0), (0, 300)] multiplot = plot_data.MultiplePlots(plots=objects, elements=values, sizes=sizes, coords=coords, name='Results plot') return multiplot
def plot_data(self): cycle_time = [ i + 1 for i in range(len(self.wltp_cycle.cycle_speeds[:-1])) ] points = [] for car_speed, wheel_torque, engine_speed, engine_torque, fuel_consumption, time, gear in zip( self.wltp_cycle.cycle_speeds[:-1], self.wltp_cycle.cycle_torques, self.engine_speeds, self.engine_torques, self.fuel_consumptions, cycle_time, self.gears_ratios[0]): points.append({ 'c_s': car_speed, 'whl_t': wheel_torque, 'w_e': engine_speed, 't_e': engine_torque, 'f_cons (g/kWh)': fuel_consumption * 3.6e9, 'time': time, 'gear': gear }) color_fill = LIGHTBLUE color_stroke = GREY point_style = plot_data.PointStyle(color_fill=color_fill, color_stroke=color_stroke) axis = plot_data.Axis() attributes = ['c_s', 'f_cons (g/kWh)'] tooltip = plot_data.Tooltip(attributes=attributes) objects = [ plot_data.Scatter(tooltip=tooltip, x_variable=attributes[0], y_variable=attributes[1], point_style=point_style, elements=points, axis=axis) ] attributes = ['whl_t', 'f_cons (g/kWh)'] tooltip = plot_data.Tooltip(attributes=attributes) objects.append( plot_data.Scatter(tooltip=tooltip, x_variable=attributes[0], y_variable=attributes[1], point_style=point_style, elements=points, axis=axis)) attributes = ['w_e', 't_e', 'f_cons (g/kWh)'] edge_style = plot_data.EdgeStyle() rgbs = [[192, 11, 11], [14, 192, 11], [11, 11, 192]] objects.append( plot_data.ParallelPlot(elements=points, edge_style=edge_style, disposition='vertical', axes=attributes, rgbs=rgbs)) coords = [(0, 0), (500, 0), (1000, 0)] sizes = [ plot_data.Window(width=500, height=500), plot_data.Window(width=500, height=500), plot_data.Window(width=500, height=500) ] multiplot = plot_data.MultiplePlots(elements=points, plots=objects, sizes=sizes, coords=coords) list_colors = [BLUE, BROWN, GREEN, BLACK] graphs2d = [] point_style = plot_data.PointStyle(color_fill=RED, color_stroke=BLACK, size=1) tooltip = plot_data.Tooltip(attributes=['sec', 'gear']) edge_style = plot_data.EdgeStyle(line_width=0.5, color_stroke=list_colors[0]) elements = [] for i, gear in enumerate(self.gears_ratios[0]): elements.append({'sec': cycle_time[i], 'gear': gear}) dataset = plot_data.Dataset(elements=elements, edge_style=edge_style, tooltip=tooltip, point_style=point_style) graphs2d.append( plot_data.Graph2D(graphs=[dataset], x_variable='sec', y_variable='gear')) tooltip = plot_data.Tooltip(attributes=['sec', 'f_cons (g/kWh)']) edge_style = plot_data.EdgeStyle(line_width=0.5, color_stroke=list_colors[0]) elements = [] for i, gear in enumerate(self.gears_ratios[0]): point = { 'sec': cycle_time[i], 'f_cons (g/kWh)': self.fuel_consumptions[i] * 3.6e9 } elements.append(point) dataset = plot_data.Dataset(elements=elements, edge_style=edge_style, tooltip=tooltip, point_style=point_style) graphs2d.append( plot_data.Graph2D(graphs=[dataset], x_variable='sec', y_variable='f_cons (g/kWh)')) tooltip = plot_data.Tooltip(attributes=['sec', 'w_e']) edge_style = plot_data.EdgeStyle(line_width=0.5, color_stroke=list_colors[2]) elements = [] for i, torque in enumerate(self.wltp_cycle.cycle_torques): elements.append({ 'sec': cycle_time[i], 'w_e': self.engine_speeds[i] }) dataset = plot_data.Dataset(elements=elements, edge_style=edge_style, tooltip=tooltip, point_style=point_style) graphs2d.append( plot_data.Graph2D(graphs=[dataset], x_variable='sec', y_variable='w_e')) tooltip = plot_data.Tooltip(attributes=['sec', 'w_t']) edge_style = plot_data.EdgeStyle(line_width=0.5, color_stroke=list_colors[3]) elements = [] for i, torque in enumerate(self.wltp_cycle.cycle_torques): elements.append({ 'sec': cycle_time[i], 'w_t': self.engine_torques[i] }) dataset = plot_data.Dataset(elements=elements, edge_style=edge_style, tooltip=tooltip, point_style=point_style) graphs2d.append( plot_data.Graph2D(graphs=[dataset], x_variable='sec', y_variable='w_t')) coords = [(0, 0), (0, 187.5), (0, 375), (0, 562.5)] sizes = [ plot_data.Window(width=1500, height=187.5), plot_data.Window(width=1500, height=187.5), plot_data.Window(width=1500, height=187.5), plot_data.Window(width=1500, height=187.5) ] multiplot2 = plot_data.MultiplePlots(elements=points, plots=graphs2d, sizes=sizes, coords=coords) return [multiplot, multiplot2]
def plot_data(self): attributes = ['cx', 'cy'] # Contour contour = self.standalone_subobject.contour().plot_data() primitives_group = plot_data.PrimitiveGroup(primitives=[contour], name='Contour') # Scatter Plot bounds = {'x': [0, 6], 'y': [100, 2000]} catalog = Catalog.random_2d(bounds=bounds, threshold=8000) points = [ plot_data.Point2D(cx=v[0], cy=v[1], name='Point' + str(i)) for i, v in enumerate(catalog.array) ] axis = plot_data.Axis() tooltip = plot_data.Tooltip(to_disp_attribute_names=attributes, name='Tooltips') scatter_plot = plot_data.Scatter(axis=axis, tooltip=tooltip, elements=points, to_disp_attribute_names=attributes, name='Scatter Plot') # Parallel Plot attributes = ['cx', 'cy', 'color_fill', 'color_stroke'] parallel_plot = plot_data.ParallelPlot( elements=points, to_disp_attribute_names=attributes, name='Parallel Plot') # Multi Plot objects = [scatter_plot, parallel_plot] sizes = [ plot_data.Window(width=560, height=300), plot_data.Window(width=560, height=300) ] coords = [(0, 0), (300, 0)] multi_plot = plot_data.MultiplePlots(elements=points, plots=objects, sizes=sizes, coords=coords, name='Multiple Plot') attribute_names = ['time', 'electric current'] tooltip = plot_data.Tooltip(to_disp_attribute_names=attribute_names) time1 = linspace(0, 20, 20) current1 = [t**2 for t in time1] elements1 = [] for time, current in zip(time1, current1): elements1.append({'time': time, 'electric current': current}) # The previous line instantiates a dataset with limited arguments but # several customizations are available point_style = plot_data.PointStyle(color_fill=RED, color_stroke=BLACK) edge_style = plot_data.EdgeStyle(color_stroke=BLUE, dashline=[10, 5]) custom_dataset = plot_data.Dataset(elements=elements1, name='I = f(t)', tooltip=tooltip, point_style=point_style, edge_style=edge_style) # Now let's create another dataset for the purpose of this exercice time2 = linspace(0, 20, 100) current2 = [100 * (1 + cos(t)) for t in time2] elements2 = [] for time, current in zip(time2, current2): elements2.append({'time': time, 'electric current': current}) dataset2 = plot_data.Dataset(elements=elements2, name='I2 = f(t)') graph2d = plot_data.Graph2D(graphs=[custom_dataset, dataset2], to_disp_attribute_names=attribute_names) return [ primitives_group, scatter_plot, parallel_plot, multi_plot, graph2d ]
color_stroke=colors.VIOLET, stroke_width=0.5, size=2, # 1, 2, 3 or 4 shape='square') # 'circle', 'square' or 'crux' # Finally, axis can be personalized too graduation_style = plot_data.TextStyle(text_color=colors.BLUE, font_size=10, font_style='Arial') axis_style = plot_data.EdgeStyle(line_width=0.5, color_stroke=colors.ROSE, dashline=[]) axis = plot_data.Axis(nb_points_x=7, nb_points_y=5, graduation_style=graduation_style, axis_style=axis_style) # a tooltip is drawn when clicking on a point. Users can choose what information # they want to be displayed. tooltip = plot_data.Tooltip(attributes=['mass', 'length', 'shape', 'color']) # Now, here is the new scatterplot customized_scatterplot = plot_data.Scatter(x_variable='mass', y_variable='shape', point_style=point_style, elements=elements, axis=axis, tooltip=tooltip) # if debug_mode is True, set it to False