dhg.visualization
Structure Visualization
Graph
- dhg.visualization.draw_graph(g, e_style='line', v_label=None, v_size=1.0, v_color='r', v_line_width=1.0, e_color='gray', e_fill_color='whitesmoke', e_line_width=1.0, font_size=1.0, font_family='sans-serif', push_v_strength=1.0, push_e_strength=1.0, pull_e_strength=1.0, pull_center_strength=1.0)[source]
Draw the graph structure. The supported edge styles are:
'line'and'circle'.- Parameters
g (
dhg.Graph) – The DHG’s graph object.e_style (
str) – The edge style. The supported edge styles are:'line'and'circle'. Defaults to'line'.v_label (
list, optional) – A list of vertex labels. Defaults toNone.v_size (
Union[float, list]) – The vertex size. Ifv_sizeis afloat, all vertices will have the same size. Ifv_sizeis alist, the size of each vertex will be set according to the corresponding element in the list. Defaults to1.0.v_color (
Union[str, list]) – The vertex color. Ifv_coloris astr, all vertices will have the same color. Ifv_coloris alist, the color of each vertex will be set according to the corresponding element in the list. Defaults to'r'.v_line_width (
Union[str, list]) – The vertex line width. Ifv_line_widthis afloat, all vertices will have the same line width. Ifv_line_widthis alist, the line width of each vertex will be set according to the corresponding element in the list. Defaults to1.0.e_color (
Union[str, list]) –The edge color. If
e_coloris astr, all edges will have the same color. Ife_coloris alist, the color of each edge will be set according to the corresponding element in the list. Defaults to'gray'.e_fill_color (
Union[str, list]) – The edge fill color. Ife_fill_coloris astr, all edges will have the same fill color. Ife_fill_coloris alist, the fill color of each edge will be set according to the corresponding element in the list. Defaults to'whitesmoke'. This argument is only valid whene_styleis'circle'.e_line_width (
Union[str, list]) – The edge line width. Ife_line_widthis afloat, all edges will have the same line width. Ife_line_widthis alist, the line width of each edge will be set according to the corresponding element in the list. Defaults to1.0.font_size (
int) – The font size. Defaults to1.0.font_family (
str) – The font family. Defaults to'sans-serif'.push_v_strength (
float) – The vertex push strength. Defaults to1.0.push_e_strength (
float) – The edge push strength. Defaults to1.0.pull_e_strength (
float) – The edge pull strength. Defaults to1.0.pull_center_strength (
float) – The center pull strength. Defaults to1.0.
Directed Graph
- dhg.visualization.draw_digraph(g, e_style='line', v_label=None, v_size=1.0, v_color='r', v_line_width=1.0, e_color='gray', e_line_width=1.0, font_size=1.0, font_family='sans-serif', push_v_strength=1.0, push_e_strength=1.0, pull_e_strength=1.0, pull_center_strength=1.0)[source]
Draw the directed graph structure.
- Parameters
g (
dhg.DiGraph) – The DHG’s directed graph object.e_style (
str) – The edge style. The supported styles are only'line'. Defaults to'line'.v_label (
list) – The vertex label. Defaults toNone.v_size (
Union[str, list]) – The vertex size. Ifv_sizeis afloat, all vertices will have the same size. Ifv_sizeis alist, the size of each vertex will be set according to the corresponding element in the list. Defaults to1.0.v_color (
Union[str, list]) –The vertex color. If
v_coloris astr, all vertices will have the same color. Ifv_coloris alist, the color of each vertex will be set according to the corresponding element in the list. Defaults to'r'.v_line_width (
Union[str, list]) – The vertex line width. Ifv_line_widthis afloat, all vertices will have the same line width. Ifv_line_widthis alist, the line width of each vertex will be set according to the corresponding element in the list. Defaults to1.0.e_color (
Union[str, list]) –The edge color. If
e_coloris astr, all edges will have the same color. Ife_coloris alist, the color of each edge will be set according to the corresponding element in the list. Defaults to'gray'.e_line_width (
Union[str, list]) – The edge line width. Ife_line_widthis afloat, all edges will have the same line width. Ife_line_widthis alist, the line width of each edge will be set according to the corresponding element in the list. Defaults to1.0.font_size (
int) – The font size. Defaults to1.0.font_family (
str) – The font family. Defaults to'sans-serif'.push_v_strength (
float) – The vertex push strength. Defaults to1.0.push_e_strength (
float) – The edge push strength. Defaults to1.0.pull_e_strength (
float) – The edge pull strength. Defaults to1.0.pull_center_strength (
float) – The center pull strength. Defaults to1.0.
Bipartite Graph
- dhg.visualization.draw_bigraph(g, e_style='line', u_label=None, u_size=1.0, u_color='m', u_line_width=1.0, v_label=None, v_size=1.0, v_color='r', v_line_width=1.0, e_color='gray', e_line_width=1.0, u_font_size=1.0, v_font_size=1.0, font_family='sans-serif', push_u_strength=1.0, push_v_strength=1.0, push_e_strength=1.0, pull_e_strength=1.0, pull_u_center_strength=1.0, pull_v_center_strength=1.0)[source]
Draw the bipartite graph structure.
- Parameters
g (
dhg.BiGraph) – The DHG’s bipartite graph object.e_style (
str) – The edge style. The supported edge styles are only'line'. Defaults to'line'.u_label (
list) – The label of vertices in set \(\mathcal{U}\). Defaults toNone.u_size (
Union[str, list]) – The size of vertices in set \(\mathcal{U}\). Ifu_sizeis afloat, all vertices will have the same size. Ifu_sizeis alist, the size of each vertex will be set according to the corresponding element in the list. Defaults to1.0.u_color (
Union[str, list]) –The color of vertices in set \(\mathcal{U}\). If
u_coloris astr, all vertices will have the same color. Ifu_coloris alist, the color of each vertex will be set according to the corresponding element in the list. Defaults to'm'.u_line_width (
Union[str, list]) – The line width of vertices in set \(\mathcal{U}\). Ifu_line_widthis afloat, all vertices will have the same line width. Ifu_line_widthis alist, the line width of each vertex will be set according to the corresponding element in the list. Defaults to1.0.v_label (
list) – The label of vertices in set \(\mathcal{V}\). Defaults toNone.v_size (
Union[str, list]) – The size of vertices in set \(\mathcal{V}\). Ifv_sizeis afloat, all vertices will have the same size. Ifv_sizeis alist, the size of each vertex will be set according to the corresponding element in the list. Defaults to1.0.v_color (
Union[str, list]) –The color of vertices in set \(\mathcal{V}\). If
v_coloris astr, all vertices will have the same color. Ifv_coloris alist, the color of each vertex will be set according to the corresponding element in the list. Defaults to'r'.v_line_width (
Union[str, list]) – The line width of vertices in set \(\mathcal{V}\). Ifv_line_widthis afloat, all vertices will have the same line width. Ifv_line_widthis alist, the line width of each vertex will be set according to the corresponding element in the list. Defaults to1.0.e_color (
Union[str, list]) –The color of edges. If
e_coloris astr, all edges will have the same color. Ife_coloris alist, the color of each edge will be set according to the corresponding element in the list. Defaults to'gray'.e_line_width (
Union[str, list]) – The line width of edges. Ife_line_widthis afloat, all edges will have the same line width. Ife_line_widthis alist, the line width of each edge will be set according to the corresponding element in the list. Defaults to1.0.u_font_size (
float) – The font size of vertex labels in set \(\mathcal{U}\). Defaults to1.0.v_font_size (
float) – The font size of vertex labels in set \(\mathcal{V}\). Defaults to1.0.font_family (
str) – The font family of vertex labels. Defaults to'sans-serif'.push_u_strength (
float) – The strength of pushing vertices in set \(\mathcal{U}\). Defaults to1.0.push_v_strength (
float) – The strength of pushing vertices in set \(\mathcal{V}\). Defaults to1.0.push_e_strength (
float) – The strength of pushing edges. Defaults to1.0.pull_e_strength (
float) – The strength of pulling edges. Defaults to1.0.pull_u_center_strength (
float) – The strength of pulling vertices in set \(\mathcal{U}\) to the center. Defaults to1.0.pull_v_center_strength (
float) – The strength of pulling vertices in set \(\mathcal{V}\) to the center. Defaults to1.0.
Hypergraph
- dhg.visualization.draw_hypergraph(hg, e_style='circle', v_label=None, v_size=1.0, v_color='r', v_line_width=1.0, e_color='gray', e_fill_color='whitesmoke', e_line_width=1.0, font_size=1.0, font_family='sans-serif', push_v_strength=1.0, push_e_strength=1.0, pull_e_strength=1.0, pull_center_strength=1.0)[source]
Draw the hypergraph structure.
- Parameters
hg (
dhg.Hypergraph) – The DHG’s hypergraph object.e_style (
str) – The style of hyperedges. The available styles are only'circle'. Defaults to'circle'.v_label (
list) – The labels of vertices. Defaults toNone.v_size (
floatorlist) – The size of vertices. Defaults to1.0.v_color (
strorlist) –The color of vertices. Defaults to
'r'.v_line_width (
floatorlist) – The line width of vertices. Defaults to1.0.e_color (
strorlist) –The color of hyperedges. Defaults to
'gray'.e_fill_color (
strorlist) –The fill color of hyperedges. Defaults to
'whitesmoke'.e_line_width (
floatorlist) – The line width of hyperedges. Defaults to1.0.font_size (
float) – The font size of labels. Defaults to1.0.font_family (
str) – The font family of labels. Defaults to'sans-serif'.push_v_strength (
float) – The strength of pushing vertices. Defaults to1.0.push_e_strength (
float) – The strength of pushing hyperedges. Defaults to1.0.pull_e_strength (
float) – The strength of pulling hyperedges. Defaults to1.0.pull_center_strength (
float) – The strength of pulling vertices to the center. Defaults to1.0.
Feature Visualization
Feature Visualization in Euclidean Space
- dhg.visualization.draw_in_euclidean_space(embeddings, label=None, dim=2, cmap='viridis')[source]
Visualize embeddings in Eulidean Space with t-SNE algorithm.
- Parameters
feature (
np.ndarray) – The feature matrix. Size \((N, C)\).label (
np.ndarray, optional) – The label matrix. Size \((N, )\).dim (
int) – Project the embedding intodim-dimensional space, which is2or3. Defaults to2.cmap (
str, optional) – The color map. Defaults to"viridis".
Feature Visualization in Poincare Ball
- dhg.visualization.project_to_poincare_ball(embeddings, dim=2, reduce_method='pca')[source]
Project embeddings from Euclidean space to Hyperbolic space.
- Parameters
feature (
np.ndarray) – The feature matrix. Size \((N, C)\).dim (
int) – Project the embedding intodim-dimensional space, which is2or3. Defaults to2.reduce_method (
str) – The method to project the embedding into low-dimensional space. It can bepcaortsne. Defaults topca.
- dhg.visualization.draw_in_poincare_ball(embeddings, label=None, dim=2, reduce_method='pca', cmap='viridis')[source]
Visualize embeddings in Poincare Ball.
- Parameters
feature (
np.ndarray) – The feature matrix. Size \((N, C)\).label (
np.ndarray, optional) – The label matrix. Size \((N, )\). Defaults toNone.dim (
int) – Project the embedding intodim-dimensional space, which is2or3. Defaults to2.reduce_method (
str) – The method to project the embedding into low-dimensional space. It can bepcaortsne. Defaults topca.cmap (
str, optional) –The color map. Defaults to
"viridis".
Make Animations
- dhg.visualization.animation_of_3d_euclidean_space(embeddings, label=None, cmap='viridis')[source]
Make 3D animation of embeddings visualization of tSNE algorithm. This function will return the animation object ani. You can save the animation by
ani.save("animation.gif").- Parameters
feature (
np.ndarray) – The feature matrix. Size \((N, C)\).label (
np.ndarray, optional) – The label matrix. Size \((N, )\). Defaults toNone.cmap (
str, optional) –The color map. Defaults to
"viridis".
Example
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from dhg.visualization import animation_of_3d_euclidean_space >>> x = np.random.rand(100, 32) >>> ani = animation_of_3d_euclidean_space(x) >>> plt.show() >>> ani.save('a.gif')
- dhg.visualization.animation_of_3d_poincare_ball(embeddings, label=None, reduce_method='pca', cmap='viridis')[source]
Make 3D animation of embeddings visualization on Poincare Ball. This function will return the animation object ani. You can save the animation by
ani.save("animation.gif").- Parameters
feature (
np.ndarray) – The feature matrix. Size \((N, C)\).label (
np.ndarray, optional) – The label matrix. Size \((N, )\). Defaults toNone.reduce_method (
str) – The method to project the embedding into low-dimensional space. It can bepcaortsne. Defaults topca.cmap (
str, optional) –The color map. Defaults to
"viridis".
Example
>>> import numpy as np >>> import matplotlib.pyplot as plt >>> from dhg.visualization import animation_of_3d_poincare_ball >>> x = np.random.rand(100, 32) >>> ani = animation_of_3d_poincare_ball(x) >>> plt.show() >>> ani.save('a.gif')