Skip to content

Commit 380b608

Browse files
committed
doc: vis_structure
1 parent eada8c0 commit 380b608

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed
50.1 KB
Loading
32.5 KB
Loading
29.3 KB
Loading

docs/source/tutorial/vis_structure.rst

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Structure Visualization
22
=============================
33

4-
.. hint::
4+
.. hint::
55

66
- Author: Xinwei Zhang
77
- Proof: `Yifan Feng (丰一帆) <https://fengyifan.site/>`_
@@ -12,8 +12,8 @@ DHG provides a simple interface to visualize the correlation structures:
1212

1313
1. Create a structure object (*i.e.*, :py:class:`dhg.Graph`, :py:class:`dhg.BiGraph`, :py:class:`dhg.DiGraph`, and :py:class:`dhg.Hypergraph`);
1414
2. Call the ``draw()`` method of the object;
15-
3. Call ``plt.show()`` to show the figure or ``plt.savefig()`` to save the figure.
16-
15+
3. Call ``plt.show()`` to show the figure or ``plt.savefig()`` to save the figure.
16+
1717
.. note:: The ``plt`` is short for ``matplotlib.pyplot`` module.
1818

1919

@@ -40,7 +40,7 @@ Visualization of Directed Graph
4040

4141
.. image:: ../_static/img/vis_digraph.png
4242
:align: center
43-
:alt: Visualization of Directed Graph
43+
:alt: Visualization of Directed Graph
4444
:height: 400px
4545

4646
.. code-block:: python
@@ -93,19 +93,69 @@ Advanced Usages
9393

9494
Customize Labels
9595
^^^^^^^^^^^^^^^^^^^^^^^^^
96-
Coming soon...
96+
The labels of the vertices could be customized by the ``v_label`` argument. The ``v_label`` could be a list of strings. The labels of the vertices are the strings in the list.
97+
For example, the following code shows how to customize the labels of the vertices of a graph.
98+
If the ``v_label`` is not specified, no labels will be shown in the figure.
99+
The ``font_size`` argument for ``dhg.Graph``, ``dhg.DiGraph``, and ``dhg.Hypergraph``, as well as ``u_font_size`` and ``v_font_size`` for ``dhg.BiGraph`` is used to specify the relative size of the font of the labels, and the default value is ``1.0``.
100+
The ``font_family`` argument is used to specify the font family of the labels, and the default value is ``'sans-serif'``.
101+
102+
.. code-block:: python
103+
104+
>>> import matplotlib.pyplot as plt
105+
>>> from dhg.random import graph_Gnm
106+
>>> g = graph_Gnm(10, 12)
107+
>>> labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
108+
>>> g.draw(v_label=labels, font_size=1.5, font_family='serif')
109+
>>> plt.show()
110+
111+
.. image:: ../_static/img/custom_label.png
112+
:align: center
113+
:alt: Customize label
114+
:height: 400px
115+
97116

98117
Customize Colors
99118
^^^^^^^^^^^^^^^^^^^^^^^^^
100-
Coming soon...
119+
For ``dhg.Graph``, ``dhg.DiGraph``, and ``dhg.Hypergraph``, the colors of the vertices could be customized by the ``v_color`` argument and the colors of the edges could be customized by the ``e_color`` argument. While for ``dhg.BiGraph``, the colors of the vertices in :math:`\mathcal{U}` could be customized by the ``u_color`` argument and the colors of the vertices in :math:`\mathcal{V}` could be customized by the ``v_color`` argument. Both the ``v_color``, ``u_color``, and ``e_color`` could be a string or list of strings. If a string is provided, all the vertices or edges will be colored by the string. If a list of strings is provided, the colors of the vertices or edges are the strings in the list. For example, the following code shows how to customize the colors of the vertices and edges of a hypergraph.
120+
121+
.. code-block:: python
122+
123+
>>> import matplotlib.pyplot as plt
124+
>>> from dhg.random import hypergraph_Gnm
125+
>>> hg = hypergraph_Gnm(10, 8, method='low_order_first')
126+
>>> hg.draw(v_color='cyan', e_color='grey')
127+
>>> plt.show()
128+
129+
.. image:: ../_static/img/custom_color.png
130+
:align: center
131+
:alt: Customize color
132+
:height: 400px
133+
101134

102135
Customize Sizes
103136
^^^^^^^^^^^^^^^^^^^^^^^^^
104-
Coming soon...
137+
For ``dhg.Graph``, ``dhg.DiGraph``, and ``dhg.Hypergraph``, the sizes of the vertices could be customized by the ``v_size`` argument and the sizes of the edges could be customized by the ``e_size`` argument. While for ``dhg.BiGraph``, the sizes of the vertices in :math:`\mathcal{U}` could be customized by the ``u_size`` argument and the sizes of the vertices in :math:`\mathcal{V}` could be customized by the ``v_size`` argument. Both the ``v_size``, ``u_size``, and ``e_size`` could be a float or list of float. If a float is provided, all the vertices or edges will be sized by the float. If a list of floats is provided, the sizes of the vertices or edges are the floats in the list. ``v_line_width`` represents the width of the surrounding line of the vertices. ``e_line_width`` represents the width of the line of the edges.
138+
All of the sizes above represent the relative size, and the default values are ``1.0``. For example, the following code shows how to customize the sizes of the vertices and edges of a hypergraph.
139+
140+
.. code-block:: python
141+
142+
>>> import matplotlib.pyplot as plt
143+
>>> from dhg.random import graph_Gnm
144+
>>> g = graph_Gnm(10, 12)
145+
>>> g.draw(v_size=1.5, v_line_width=1.5, e_line_width=1.5)
146+
>>> plt.show()
147+
148+
.. image:: ../_static/img/custom_size.png
149+
:align: center
150+
:alt: Customize size
151+
:height: 400px
152+
153+
105154

106155
Customize Layout
107156
^^^^^^^^^^^^^^^^^^^^^^^^^
108-
Coming soon...
157+
The layout of the structures is based on the modified directed-force layout algorithm. There are four forces to determine the position of the nodes, *i.e.*, node attraction force :math: `f_{na}`, node repulsion force :math: `f_{nr}`, edge repulsion force :math: `f_{er}`, and the center force :math: `f_c`. :math: `f_{na}` is the spring force which attracts the adjacent nodes. :math: `f_{nr}` is used to repel the nodes from each other. :math: `f_{er}` is used to repel the hyperedges from each other, which only make sense for hypergraph visualization. :math: `f_c` is used to attract the nodes to the center (two centers for the bipartite graphs).
158+
The strength of the forces could be customized by ``forces`` argument, which is a dictionary with the keys ``Simulator.NODE_ATTRACTION``, ``Simulator.NODE_REPULSION``, ``Simulator.EDGE_REPULSION``, and ``Simulator.CENTER_GRAVITY``. The default values of the forces are ``1.0``.
109159

110160

111161
.. different style, change size, change color, change opacity

0 commit comments

Comments
 (0)