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
Esempio n. 2
0
                                                    plot_data.LineSegment2D([2, 2], [2, 1]),
                                                    plot_data.LineSegment2D([2, 1], [1, 1])],
                              surface_style=plot_data.SurfaceStyle(colors.LIGHTORANGE))

circle1 = plot_data.Circle2D(cx=0, cy=0, r=10)
circle2 = plot_data.Circle2D(cx=1, cy=1, r=5, surface_style=plot_data.SurfaceStyle(colors.RED))
circle3 = plot_data.Circle2D(cx=1, cy=1, r=5, surface_style=plot_data.SurfaceStyle(colors.LIGHTBROWN))

primitive_group1 = [circle1]
primitive_group2 = [contour]
primitive_group3 = [circle2]
primitive_group4 = [circle3]
primitive_groups = [primitive_group1, primitive_group2, primitive_group3, primitive_group4]

primitive_group_container = plot_data.PrimitiveGroupsContainer(primitive_groups=primitive_groups,
                                                               associated_elements=[1, 2, 3, 4],
                                                               x_variable='x', y_variable='y')

histogram = plot_data.Histogram(x_variable='x')

"""Creating the multiplot"""
plots = [parallelplot1, parallelplot2, scatterplot1,
         scatterplot2, scatterplot3, graph2d, primitive_group_container,
         histogram]

multiplot = plot_data.MultiplePlots(plots=plots, elements=elements,
                                    initial_view_on=True)

# Display
plot_data.plot_canvas(plot_data_object=multiplot, debug_mode=True)
Esempio n. 3
0
# This script shows how to instantiate a MultiplePlots from a csv file
import plot_data

# ParallelPlot
axes = ['price_wather', 'length_wather', 'price_air']
parallel_plot = plot_data.ParallelPlot(axes=axes)

# Scatter
scatter_plot = plot_data.Scatter(x_variable='price_wather', y_variable='length_wather')

catalog = plot_data.get_csv_vectors('../plot_data/data/data.csv')
points = [{var: catalog.get_value_by_name(line, var)
           for var in axes}
          for line in catalog.array]

plots = [parallel_plot, scatter_plot]

multipleplots = plot_data.MultiplePlots(elements=points, plots=plots,
                                        initial_view_on=True)

# If debug_mode == True, set it to False
plot_data.plot_canvas(plot_data_object=multipleplots, debug_mode=True)
Esempio n. 4
0
    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]
Esempio n. 5
0
    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
        ]
Esempio n. 6
0
    def plot_clusters(self):
        colors = [
            RED, GREEN, ORANGE, BLUE, LIGHTSKYBLUE, ROSE, VIOLET, LIGHTRED,
            LIGHTGREEN, CYAN, BROWN, GREY, HINT_OF_MINT, GRAVEL
        ]
        all_points = []
        for i, point in enumerate(self.matrix_mds):
            point = {
                'x': point[0],
                'y': point[1],
                'Aver path': self.gearboxes_ordered[i].average_path_length,
                'Aver L clutch-input':
                self.gearboxes_ordered[i].average_clutch_distance,
                'ave_l_ns': self.gearboxes_ordered[i].ave_l_ns,
                'Number shafts': self.gearboxes_ordered[i].number_shafts,
                'Std input_cluches':
                self.gearboxes_ordered[i].std_clutch_distance,
                'Density': self.gearboxes_ordered[i].density,
                'Cluster': self.labels_reordered[i]
            }
            all_points.append(point)

        point_families = []
        for i, indexes in enumerate(self.list_indexes_groups):
            color = colors[i]
            point_family = plot_data.PointFamily(point_color=color,
                                                 point_index=indexes,
                                                 name='Cluster ' +
                                                 str(self.clusters[i]))
            point_families.append(point_family)

        all_attributes = [
            'x', 'y', 'Aver path', 'Aver L clutch-input', 'ave_l_ns',
            'Number shafts', 'Number gears', 'Std input/cluches', 'Density'
        ]
        pp_attributes = [
            'Aver path', 'Number shafts', 'ave_l_ns', 'Aver L clutch-input',
            'Std input/cluches', 'Number  gears', 'Density', 'Cluster'
        ]

        tooltip = plot_data.Tooltip(attributes=all_attributes)

        edge_style = plot_data.EdgeStyle(color_stroke=BLACK, dashline=[10, 5])

        plots = [
            plot_data.Scatter(tooltip=tooltip,
                              x_variable='x',
                              y_variable='y',
                              elements=all_points)
        ]

        rgbs = [[192, 11, 11], [14, 192, 11], [11, 11, 192]]
        plots.append(
            plot_data.ParallelPlot(elements=all_points,
                                   edge_style=edge_style,
                                   disposition='vertical',
                                   axes=pp_attributes,
                                   rgbs=rgbs))
        sizes = [
            plot_data.Window(width=560, height=300),
            plot_data.Window(width=560, height=300)
        ]
        coords = [(0, 0), (0, 300)]
        clusters = plot_data.MultiplePlots(plots=plots,
                                           coords=coords,
                                           sizes=sizes,
                                           elements=all_points,
                                           point_families=point_families,
                                           initial_view_on=True)
        return clusters