Пример #1
0
    def _to_primitives(self):
        r = 0.04
        primitives = []
        pos = nx.kamada_kawai_layout(self.graph)

        for edge in self.graph.edges:
            node1, node2 = edge[0], edge[1]
            pos1, pos2 = pos[node1], pos[node2]
            line = plot_data.LineSegment2D([pos1[0], pos1[1]],
                                           [pos2[0], pos2[1]],
                                           edge_style=plot_data.EdgeStyle())
            primitives.append(line)

        for node, data in self.graph.nodes(data=True):
            position = pos[node]
            color, shape, name = data['color'], data['shape'], data['name']
            x, y = position[0], position[1]
            edge_style = plot_data.EdgeStyle(color_stroke=color)
            surface_style = plot_data.SurfaceStyle(color_fill=color)
            if shape == '.':
                point_style = plot_data.PointStyle(color_fill=color,
                                                   color_stroke=color,
                                                   size=4)
                prim = plot_data.Point2D(x, y, point_style=point_style)
            elif shape == 'o':
                prim = plot_data.Circle2D(x,
                                          y,
                                          r,
                                          edge_style=edge_style,
                                          surface_style=surface_style)
            elif shape == 's':
                x1, x2, y1, y2 = x - r, x + r, y - r, y + r
                l1 = plot_data.LineSegment2D([x1, y1], [x2, y1])
                l2 = plot_data.LineSegment2D([x2, y1], [x2, y2])
                l3 = plot_data.LineSegment2D([x2, y2], [x1, y2])
                l4 = plot_data.LineSegment2D([x1, y2], [x1, y1])
                prim = plot_data.Contour2D([l1, l2, l3, l4],
                                           edge_style=edge_style,
                                           surface_style=surface_style)
            else:
                raise NotImplementedError
            primitives.append(prim)

            text_style = plot_data.TextStyle(text_color='rgb(0,0,0)',
                                             text_align_x='center',
                                             text_align_y='middle')
            text = plot_data.Text(name, x, y, text_style=text_style)
            primitives.append(text)

        return primitives
Пример #2
0
 def plot_data(self,
               edge_style: plot_data.EdgeStyle = None,
               surface_style: plot_data.SurfaceStyle = None):
     """
     Dessia plot_data method
     return a plotdata.Circle2D object
     """
     if edge_style is None:
         edge_style = plot_data.EdgeStyle(line_width=1,
                                          color_stroke=BLACK,
                                          dashline=[])
     if surface_style is None:
         surface_style = plot_data.SurfaceStyle(color_fill=CYAN)
     return plot_data.Circle2D(cx=self.position.x,
                               cy=self.position.y,
                               r=self.diameter / 2,
                               edge_style=edge_style,
                               surface_style=surface_style)
Пример #3
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]
Пример #4
0
from plot_data.colors import *
import numpy as np

k = 0

T1 = np.linspace(1, 20, 20)
I1 = [t**2 for t in T1]
elements1 = []
for k in range(len(T1)):
    elements1.append({'time': T1[k], 'electric current': I1[k]})
dataset1 = plot_data.Dataset(elements=elements1, name='I1 = f(t)')

# 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)',
                                   point_style=point_style,
                                   edge_style=edge_style)

# Now let's create another dataset for the purpose of this exercice
T2 = np.linspace(1, 20, 100)
I2 = [100 * (2 + np.cos(t)) for t in T2]
elements2 = []
for k in range(1, len(T2)):
    elements2.append({'time': T2[k], 'electric current': I2[k]})

dataset2 = plot_data.Dataset(elements=elements2, name='I2 = f(t)')
Пример #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
        ]
Пример #6
0
# An example of primitive_group instantiation.
# primitive_group: an object that contains multiple primitives. A primitive
# is either a Circle2D, a LineSegment, a Contour2D, an Arc2D or a Text

import plot_data
import numpy as npy
import plot_data.colors as colors

# defining a couple style objects
# edges customization
edge_style = plot_data.EdgeStyle(line_width=1,
                                 color_stroke=colors.RED,
                                 dashline=[])
# surfaces customization
hatching = plot_data.HatchingSet(0.5, 3)
surface_style = plot_data.SurfaceStyle(color_fill=colors.WHITE,
                                       opacity=1,
                                       hatching=hatching)

# Creating several primitives. plot_data() functions are used to convert
# a volmdlr object into a plot_data object

# arc
arc = plot_data.Arc2D(cx=8, cy=0, r=2, start_angle=0, end_angle=npy.pi / 2)

# square contour
rectangle_size = 2
contour = plot_data.Contour2D(plot_data_primitives=[
    plot_data.LineSegment2D([0, 0], [0, rectangle_size]),
    plot_data.LineSegment2D([0, rectangle_size],
                            [rectangle_size, rectangle_size]),
Пример #7
0
# Then, points' appearance can be modified through point_style attribute
point_style = plot_data.PointStyle(
    color_fill=colors.LIGHTGREEN,
    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,
Пример #8
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
Пример #9
0
    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
# colors as they want, as long as they are in rgb. A wide panel of rgb colors
# are available in plot_data/colors.py
rgbs = [BLUE, YELLOW, ORANGE]

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