Exemplo n.º 1
0
    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
Exemplo n.º 2
0
"""
elements = []

nb_elements = 50
available_colors = [colors.VIOLET, colors.BLUE, colors.GREEN, colors.RED, colors.YELLOW, colors.CYAN, colors.ROSE]
directions = ['north', 'south', 'west', 'east']
for i in range(nb_elements):
    random_color = available_colors[random.randint(0, len(available_colors) - 1)]
    random_direction = directions[random.randint(0, len(directions) - 1)]
    elements.append({'x': random.uniform(0, 200),
                     'y': random.uniform(0, 100),
                     'color': random_color,
                     'direction': random_direction})

""" ParallelPlot """
parallelplot1 = plot_data.ParallelPlot(axes=['x', 'y', 'color', 'direction'])
parallelplot2 = plot_data.ParallelPlot(axes=['x', 'color'])

"""Scatterplots"""
scatterplot1 = plot_data.Scatter(x_variable='x', y_variable='y')

scatterplot2 = plot_data.Scatter(x_variable='y', y_variable='color',
                                 point_style=plot_data.PointStyle(shape='square'))  # optional argument that changes
                                                                                    # points' appearance

scatterplot3 = plot_data.Scatter(x_variable='x', y_variable='direction')

"""PrimitiveGroupContainers"""
contour = plot_data.Contour2D(plot_data_primitives=[plot_data.LineSegment2D([1, 1], [1, 2]),
                                                    plot_data.LineSegment2D([1, 2], [2, 2]),
                                                    plot_data.LineSegment2D([2, 2], [2, 1]),
Exemplo 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)
Exemplo 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]
Exemplo 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
        ]
Exemplo n.º 6
0
import plot_data.colors as colors
import random

elements = []

axes = ['cost', 'mass', 'wiring_length']

for i in range(100):

    elements.append({
        'mass': 52 + 47 * random.random(),
        'cost': 231 + 89 * random.random(),
        'wiring_length': 8.9 + 3.1 * random.random()
    })

parallel_plot = plot_data.ParallelPlot(disposition='vertical', axes=axes)

# Scatter

scatter1 = plot_data.Scatter(elements=elements,
                             x_variable='cost',
                             y_variable='mass')

scatter2 = plot_data.Scatter(elements=elements,
                             x_variable='cost',
                             y_variable='wiring_length')

plots = [parallel_plot, scatter1, scatter2]

multipleplots = plot_data.MultiplePlots(elements=elements,
                                        plots=plots,
Exemplo n.º 7
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
Exemplo n.º 8
0
from plot_data.colors import *
import random

elements = []
SHAPES = ['round', 'square', 'triangle', 'ellipse']
COLORS = [RED, BLUE, GREEN, YELLOW, ORANGE, VIOLET]
for i in range(50):
    random_shape = SHAPES[random.randint(0, len(SHAPES) - 1)]
    random_color = COLORS[random.randint(0, len(SHAPES) - 1)]
    elements.append({'mass': random.uniform(0, 50),
                     'length': random.uniform(0, 100),
                     'shape': random_shape,
                     'color': random_color
                     })

parallelplot = plot_data.ParallelPlot(elements=elements,
                                      axes=['mass', 'length', 'shape', 'color'])

# The line above shows the minimum requirements for creating a
# parallel plot. However, many options are available for further customization.

# 'edge_style' option allows customization of the lines
edge_style = plot_data.EdgeStyle(line_width=1, color_stroke=VIOLET, dashline=[])

# 'disposition' = 'vertical' or 'horizontal' whether you want the axis to be
# vertical of hozizontal. This can be changed by pressing the 'disp' button on
# canvas as well.
disposition = 'horizontal'

# Next, ParallelPlots "sort" an axis when clicking on it by displaying a color
# interpolation on the lines. When the attribute 'rgbs' is not given to the ParallePlot
# it is set to [red, blue, green]. However, users are free to set as many