コード例 #1
0
ファイル: graph.py プロジェクト: Dessia-tech/plot_data
    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
# The name says it all, primitive_group_containers contain primitive_groups.
# In the same way, primitive_groups contain primitives (ie: Arc2D, Circle2D, Contour2D,
# LineSegment and Text)

import plot_data
import plot_data.colors as colors

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]),
    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 = plot_data.PrimitiveGroup(primitives=[circle1])
primitive_group2 = plot_data.PrimitiveGroup(primitives=[contour])
primitive_group3 = plot_data.PrimitiveGroup(primitives=[circle2])
primitive_group4 = plot_data.PrimitiveGroup(primitives=[circle3])
コード例 #4
0
"""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]),
                                                    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')
コード例 #5
0
# 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]),
    plot_data.LineSegment2D([rectangle_size, rectangle_size],
コード例 #6
0
ファイル: scatter_plot.py プロジェクト: Dessia-tech/plot_data
                                x_variable='mass',
                                y_variable='length',
                                log_scale_x=True,
                                log_scale_y=True)

# The previous scripts shows the simplest way of creating a scatterplot.
# However, many options are available for further customization

# First of all, apart from tooltips' information, the user can customize
# the style. 'text_style' modifies the text while 'surface_style'
# changes the tooltip's interior. Tooltips are rounded-rectangle-shaped and the radius of the
# vertices can also be changed.
text_style = plot_data.TextStyle(text_color=colors.GREY,
                                 font_size=10,
                                 font_style='sans-serif')
surface_style = plot_data.SurfaceStyle(color_fill=colors.LIGHTVIOLET,
                                       opacity=0.3)
custom_tooltip = plot_data.Tooltip(attributes=['mass', 'length'],
                                   surface_style=surface_style,
                                   text_style=text_style,
                                   tooltip_radius=10)

# 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,