# How can I analyze and visualize networks?

Once you have successfully installed `pathpy`, as a first step we can work through a basic (temporal) network analysis and visualisation example. Here, we assume that your are working in a `jupyter` notebook, but feel free to use any `python`-friendly development environment like, e.g. pyCharm or Visual Studio Code.

Assuming that you have installed `jupyter`, we first start a new notebook server. Open a terminal window and type:

`> jupyter notebook`

This will bring up your system's default browser. Click the `New` button to create an empty python 3 notebook. In this notebook, we first need to import `pathpy`. In the first empty cell of the notebook enter the following code and run the cell, e.g. by pressing `Shift+Enter`:

`import pathpy as pp`

We can create a toy example (directed) network by adding the following code and then running the cell:

```n = pp.Network(directed=True)
print(n)```
```Directed network
Nodes:	5

The `print` statement will output a default string representation of the instance, which provides basic information on the type of the network and the number of nodes and links. To visualize this network, we can simply type the name of the variable in a new `jupyter` cell and execute it:

`n`

In `jupyter`, this will output a basic network visualisation that is actually interactive, i.e. you can drag nodes with the mouse, you can pan and you can zoom with the mouse wheel. To calculate node centralities, we can use the functions in the module `pathpy.algorithms.centralities`. To calculate the betweenness centralities of all nodes, we can write:

```c = pp.algorithms.centralities.betweenness(n)
print(c)```
```2019-03-22 00:05:41 [Severity.INFO]	Calculating betweenness centralities ...
{'c': 4.0, 'a': 0, 'b': 0, 'd': 0, 'e': 0}```

Executing this cell will print a dictionary that contains the betweenness centralities of all nodes. We can easily use this centralities to influence the visualisation of the network by means of `pathpy`'s styling mechanism. For instance, to scale the sizes of nodes according to their betweenness centrality we can write:

```style = {}
style['node_size'] = {v:3+u for v,u in c.items()}
pp.visualisation.plot(n, **style)```

For more advanced network analysis and visualisation features, including `pathpy`'s templating mechanism that gives you the full power of CSS and JavaScript, we refer the reader to this three hour hands-on tutorial.

© Data Analytics Group, University of Zurich, 2019