def figure(self): data = [] color_cycle = cycle(px.colors.qualitative.Dark24) for comp, vertex_coords in self.info.comp_vertices.items(): color = next(color_cycle) vertex_coords = sort_coords(np.array(vertex_coords)) # add surface d = make_triangles(vertex_coords) data.append(go.Mesh3d(**d, alphahull=-1, opacity=0.3, hoverinfo='skip', color=color)) x_ave = sum(d["x"]) / len(vertex_coords) y_ave = sum(d["y"]) / len(vertex_coords) z_ave = sum(d["z"]) / len(vertex_coords) # add formula data.append(go.Scatter3d(x=[x_ave], y=[y_ave], z=[z_ave], text=[clean_formula(comp)], mode="text", textposition="middle center", textfont=dict(color=color, size=24), hoverinfo='skip')) if self.info.cpd.target: x, y, z, text = [], [], [], [] for label, cp in self.info.cpd.target_vertices.items(): x.append(cp[0]) y.append(cp[1]) z.append(cp[2]) text.append(label) data.append(go.Scatter3d(x=x, y=y, z=z, text=text, mode='markers+text', textfont=dict(size=24), hovertemplate="<b>label %{text}</b><br>" "energy (%{x:.2f}, %{y:.2f})")) fig = go.Figure(data=data) # fig.update_traces(marker_size=15) _range = [self.info.min_range * 1.001, -self.info.min_range * 0.1] vertex_elements = self.info.cpd.vertex_elements elements_str = [str(elem) for elem in self.info.cpd.vertex_elements] fig.update_layout( title=f"Chemical potential diagram of {'-'.join(elements_str)}", scene=dict( xaxis_title=f"{vertex_elements[0]} (eV)", yaxis_title=f"{vertex_elements[1]} (eV)", zaxis_title=f"{vertex_elements[2]} (eV)", xaxis_range=_range, yaxis_range=_range, zaxis_range=_range, ), width=700, height=700, font_size=15, title_font_size=30, showlegend=False) return fig
def draw_simplex(self, formula): vertex_coords = self.cpd.polygons[formula] atomic_fractions = self.cpd.atomic_fractions(formula) face = Poly3DCollection([sort_coords(np.array(vertex_coords))]) face.set_color(self._3d_simplex_color(atomic_fractions)) face.set_edgecolor("black") self._ax.add_collection3d(face)
def draw_simplex(self, composition): vertex_coords = self.info.comp_vertices[composition] atomic_fractions = self.info.atomic_fractions(composition) face = Poly3DCollection([sort_coords(np.array(vertex_coords))]) face.set_color(self._3d_simplex_color(atomic_fractions)) face.set_edgecolor("black") self._ax.add_collection3d(face)
def figure(self): data = [] color_cycle = cycle(px.colors.qualitative.Dark24) for comp, vertex_coords in self.cpd.polygons.items(): color = next(color_cycle) vertex_coords = sort_coords(np.array(vertex_coords)) # add surface d = make_triangles(vertex_coords) data.append( go.Mesh3d(**d, alphahull=-1, opacity=0.3, hoverinfo='skip', color=color)) # add formula data.append( go.Scatter3d(x=[sum(d["x"]) / len(vertex_coords)], y=[sum(d["y"]) / len(vertex_coords)], z=[sum(d["z"]) / len(vertex_coords)], text=[clean_formula(comp)], mode="text", textposition="middle center", textfont=dict(color=color, size=24), hoverinfo='skip')) if self.cpd.target: target_coords = self.cpd.target_coords x = [cp[0] for cp in target_coords.values()] y = [cp[1] for cp in target_coords.values()] z = [cp[2] for cp in target_coords.values()] label = [key for key in target_coords] data.append( go.Scatter3d(x=x, y=y, z=z, text=label, mode='markers+text', textfont=dict(size=24), hovertemplate=self.hover)) fig = go.Figure(data=data) # fig.update_traces(marker_size=15) fig.update_layout(scene=dict(zaxis_title=self.axes_titles[2], zaxis_range=self.range, **self.title_axis), font_size=15, **self.common_layout) return fig
def create_figure(self): data = [] for face_vertices in self._bz_plot_info.faces: vertex_coords = sort_coords(np.array(face_vertices)) # data.append(go.Mesh3d(**make_triangles(vertex_coords), # alphahull=-1, opacity=0.1, hoverinfo='skip', # color="blue")) for s, t in pairwise(vertex_coords): data.append( go.Scatter3d(x=[s[0], t[0]], y=[s[1], t[1]], z=[s[2], t[2]], mode="lines", hoverinfo="none", marker_color="black")) for label, coords in self._bz_plot_info.labels.items(): c_coords, f_coords = coords["cart"], coords["frac"] data.append( go.Scatter3d(x=[c_coords[0]], y=[c_coords[1]], z=[c_coords[2]], text=[plotly_sanitize_label(label)], mode="markers+text", marker=dict(color="orange", size=6), meta=f_coords, hovertemplate= "(%{meta[0]:.2f} %{meta[1]:.2f} %{meta[2]:.2f})", textposition="middle center", textfont=dict(size=32))) for i, l in self._bz_plot_info.band_paths: data.append( go.Scatter3d(x=[i[0], l[0]], y=[i[1], l[1]], z=[i[2], l[2]], mode="lines", opacity=0.5, hoverinfo="none", line_width=8, marker_color="purple")) _max = np.amax(np.array(sum(self._bz_plot_info.faces, []))) c_max = _max * 1.3 c_cone = _max * 0.3 data.append( go.Cone(x=[c_max], y=[0], z=[0], u=[c_cone], v=[0], w=[0], colorscale=[[0, 'rgb(200,200,200)'], [1, 'rgb(200,200,200)']], showscale=False, hovertemplate="<b>x</b>")) data.append( go.Cone(x=[0], y=[c_max], z=[0], u=[0], v=[c_cone], w=[0], colorscale=[[0, 'rgb(200,200,200)'], [1, 'rgb(200,200,200)']], showscale=False, hovertemplate="<b>y</b>")) data.append( go.Cone(x=[0], y=[0], z=[c_max], u=[0], v=[0], w=[c_cone], colorscale=[[0, 'rgb(200,200,200)'], [1, 'rgb(200,200,200)']], showscale=False, hovertemplate="<b>z</b>")) data.append( go.Scatter3d(x=[0, c_max], y=[0, 0], z=[0, 0], mode="lines", hoverinfo="none", marker_color="black")) data.append( go.Scatter3d(x=[0, 0], y=[0, c_max], z=[0, 0], mode="lines", hoverinfo="none", marker_color="black")) data.append( go.Scatter3d(x=[0, 0], y=[0, 0], z=[0, c_max], mode="lines", hoverinfo="none", marker_color="black")) for i, direct in zip(self._bz_plot_info.rec_lat_vec, ["kx", "ky", "kz"]): nn = sqrt(i[0]**2 + i[1]**2 + i[2]**2) kx, ky, kz = np.array(i) * c_max / nn * 1.15 norm_kx, norm_ky, norm_kz = np.array(i) * c_cone / nn data.append( go.Cone(x=[kx], y=[ky], z=[kz], u=[norm_kx], v=[norm_ky], w=[norm_kz], colorscale=[[0, 'rgb(100,100,100)'], [1, 'rgb(100,100,100)']], showscale=False, hovertemplate=f"<b>{direct}</b>")) data.append( go.Scatter3d(x=[0, kx], y=[0, ky], z=[0, kz], mode="lines", hoverinfo="none", marker_color="black")) range_max = c_max * 1.4 fig = go.Figure(data=data) fig.update_layout(title_font_size=30, font_size=24, width=900, height=900, showlegend=False, scene=dict(xaxis=dict(showspikes=False, range=[-range_max, range_max], showticklabels=False, visible=False), yaxis=dict(showspikes=False, range=[-range_max, range_max], showticklabels=False, visible=False), zaxis=dict(showspikes=False, range=[-range_max, range_max], showticklabels=False, visible=False))) return fig