1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Sampson\n\nSampson's monastery data.\n\nShows how to read data from a zip file and plot multiple frames.\n\nThe data file can be found at:\n\n- https://github.com/networkx/networkx/blob/main/examples/drawing/sampson_data.zip\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import zipfile\nfrom io import BytesIO as StringIO\n\nimport matplotlib.pyplot as plt\nimport networkx as nx\n\nwith zipfile.ZipFile(\"sampson_data.zip\") as zf:\n e1 = StringIO(zf.read(\"samplike1.txt\"))\n e2 = StringIO(zf.read(\"samplike2.txt\"))\n e3 = StringIO(zf.read(\"samplike3.txt\"))\n\nG1 = nx.read_edgelist(e1, delimiter=\"\\t\")\nG2 = nx.read_edgelist(e2, delimiter=\"\\t\")\nG3 = nx.read_edgelist(e3, delimiter=\"\\t\")\npos = nx.spring_layout(G3, iterations=100, seed=173)\nplt.clf()\n\nplt.subplot(221)\nplt.title(\"samplike1\")\nnx.draw(G1, pos, node_size=50, with_labels=False)\nplt.subplot(222)\nplt.title(\"samplike2\")\nnx.draw(G2, pos, node_size=50, with_labels=False)\nplt.subplot(223)\nplt.title(\"samplike3\")\nnx.draw(G3, pos, node_size=50, with_labels=False)\nplt.subplot(224)\nplt.title(\"samplike1,2,3\")\nnx.draw(G3, pos, edgelist=list(G3.edges()), node_size=50, with_labels=False)\nnx.draw_networkx_edges(G1, pos, alpha=0.25)\nnx.draw_networkx_edges(G2, pos, alpha=0.25)\nplt.tight_layout()\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
|