예제 #1
0
    def _get_3d_domain_lines(
            domains: Dict[str, Optional[List[Simplex]]]) -> List[Scatter3d]:
        """
        Returns a list of Scatter3d objects tracing the domain lines on a
        3-dimensional chemical potential diagram.
        """
        x, y, z = [], [], []
        for phase, simplexes in domains.items():
            if simplexes:
                for s in simplexes:
                    x.extend(s.coords[:, 0].tolist() + [None])
                    y.extend(s.coords[:, 1].tolist() + [None])
                    z.extend(s.coords[:, 2].tolist() + [None])

        lines = [
            Scatter3d(
                x=x,
                y=y,
                z=z,
                mode="lines",
                line=dict(color="black", width=4.5),
                showlegend=False,
            )
        ]
        return lines
예제 #2
0
    def plot_3d(self):
        z = self.get_point_clouds()

        fig = Figure(data=Scatter3d(x=z[:,0].ravel(), y=z[:,1].ravel(), z=z[:,2].ravel(),
                                        mode='markers',
                                        marker=dict(size=1)        
                                        )
                        )

        x_range = [floor(z[:,0].min()), ceil(z[:,0].max())]
        y_range = [floor(z[:,1].min()), ceil(z[:,1].max())]
        z_range = [floor(z[:,2].min()), ceil(z[:,2].max())]

        x_len = x_range[1] - x_range[0]
        y_len = y_range[1] - y_range[0]
        z_len = z_range[1] - z_range[0]
        base = min([x_len, y_len, z_len])
        
        fig.update_layout(
            scene = dict(
                aspectmode='manual', aspectratio=dict(x=x_len/base, y=y_len/base, z=z_len/base),
                xaxis = dict(range=x_range),
                yaxis = dict(range=y_range),
                zaxis = dict(range=z_range)
            )
        )

        return fig
예제 #3
0
def show_flats(flats: DataFrame, title: str):
    (
        Figure()
        .add_trace(Scatter3d(
            name='',
            x=flats['longitude'],
            y=flats['latitude'],
            z=flats['rate'],
            mode='markers',
            marker={
                'size': 4,
                'color': flats['zone_id'],
                'showscale': True,
                'colorbar': {'title': 'ID кластера'}
            },
            hovertemplate=(
                '<b>Координати</b>: (%{x:.3f}, %{y:.3f})<br>'
                '<b>Середня вартість</b>: %{z:.2f} $<br>'
                '<b>ID кластера</b>: %{text}'
            ),
            text=flats['zone_id']
        ))
        .update_layout(
            title=title,
            scene={
                'xaxis_title': 'Довгота',
                'yaxis_title': 'Широта',
                'zaxis_title': 'Вартість 1 кв. м., $'
            },
            showlegend=False
        )
        .show()
    )
예제 #4
0
    def _draw_impulse(self, color, name, center=None):
        marker_dict = dict(size=7, color=color, symbol="x")
        impulse = Scatter3d(x=center[0],
                            y=center[1],
                            z=center[2],
                            marker=marker_dict,
                            name=name)
        self._figure.add_trace(impulse)

        return impulse
예제 #5
0
    def _plot_coordinates(self, coordinates, label, colors, dashed):
        trace = Scatter3d(
            x=coordinates.x.to(u.km).value,
            y=coordinates.y.to(u.km).value,
            z=coordinates.z.to(u.km).value,
            name=label,
            line=dict(color=colors[0], width=5, dash="dash" if dashed else "solid"),
            mode="lines",  # Boilerplate
        )
        self._figure.add_trace(trace)

        return trace, [trace.line.color]
예제 #6
0
    def _plot_trajectory(self, trajectory, label, color, dashed):
        trace = Scatter3d(
            x=trajectory.x.to(u.km).value,
            y=trajectory.y.to(u.km).value,
            z=trajectory.z.to(u.km).value,
            name=label,
            line=dict(color=color, width=5,
                      dash="dash" if dashed else "solid"),
            mode="lines",  # Boilerplate
        )
        self._figure.add_trace(trace)

        return trace
예제 #7
0
    def _get_3d_formula_lines(
        draw_domains: Dict[str, np.ndarray],
        formula_colors: Optional[List[str]],
    ) -> List[Scatter3d]:
        """Returns a list of Scatter3d objects defining the bounding polyhedra"""
        if formula_colors is None:
            formula_colors = px.colors.qualitative.Dark2

        lines = []
        for idx, (formula, coords) in enumerate(draw_domains.items()):
            points_3d = coords[:, :3]
            domain = ConvexHull(points_3d[:, :-1])
            simplexes = [
                Simplex(points_3d[indices]) for indices in domain.simplices
            ]

            x, y, z = [], [], []
            for s in simplexes:
                x.extend(s.coords[:, 0].tolist() + [None])
                y.extend(s.coords[:, 1].tolist() + [None])
                z.extend(s.coords[:, 2].tolist() + [None])

            line = Scatter3d(
                x=x,
                y=y,
                z=z,
                mode="lines",
                line={
                    "width": 8,
                    "color": formula_colors[idx]
                },
                opacity=1.0,
                name=f"{formula} (lines)",
            )
            lines.append(line)
        return lines
예제 #8
0
model_handler = ModelsHandler('data/kaggle')
model_id = 5
vertices, _ = model_handler.model_id_to_vertices_and_triangles(model_id)
color_array = model_handler.get_color_to_3dpoints_arrays(model_id)
color_array_vertices = color_array.reshape(-1, 3)[::10]
fig = make_subplots(rows=1,
                    cols=2,
                    specs=[[{
                        'type': 'scatter3d'
                    }, {
                        'type': 'scatter3d'
                    }]])
fig.add_trace(Scatter3d(x=vertices[:, 0],
                        y=vertices[:, 1],
                        z=vertices[:, 2],
                        mode='markers',
                        marker_color=model_handler.color_points(
                            vertices, model_id)),
              row=1,
              col=1)
fig.add_trace(Scatter3d(x=vertices[:, 0],
                        y=vertices[:, 1],
                        z=vertices[:, 2],
                        mode='markers',
                        marker_color=model_handler.color_points(
                            color_array_vertices, model_id)),
              row=1,
              col=2)
fig.show()