diff --git a/examples/visualize.ipynb b/examples/visualize.ipynb index d69e73c7b..4ac4e1d18 100644 --- a/examples/visualize.ipynb +++ b/examples/visualize.ipynb @@ -65,7 +65,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "26fb276b", "metadata": {}, "outputs": [], @@ -77,7 +77,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "id": "937f1476", "metadata": {}, "outputs": [], @@ -94,12 +94,175 @@ "gds = GraphDataScience(NEO4J_URI, auth=NEO4J_AUTH, database=NEO4J_DB)" ] }, + { + "cell_type": "markdown", + "id": "a96b84b5", + "metadata": {}, + "source": [ + "## Built-in visualization" + ] + }, + { + "cell_type": "markdown", + "id": "aa1f778c", + "metadata": {}, + "source": [ + "### IMDB" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "68125987", + "metadata": {}, + "outputs": [], + "source": [ + "G_imdb = gds.graph.load_imdb()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "acc92487", + "metadata": {}, + "outputs": [], + "source": [ + "G_imdb.visualize()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "21b17ba8", + "metadata": {}, + "outputs": [], + "source": [ + "G_imdb.visualize(directed=False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a2f6d726", + "metadata": {}, + "outputs": [], + "source": [ + "G_imdb.visualize(directed=False, theme=\"light\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "29534589", + "metadata": {}, + "outputs": [], + "source": [ + "G_imdb.visualize(directed=False, node_count=200)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b751ec2c", + "metadata": {}, + "outputs": [], + "source": [ + "G_imdb.drop()" + ] + }, + { + "cell_type": "markdown", + "id": "c6713a9d", + "metadata": {}, + "source": [ + "### Cora" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fe00c465", + "metadata": {}, + "outputs": [], + "source": [ + "G_cora = gds.graph.load_cora()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "258747fc", + "metadata": {}, + "outputs": [], + "source": [ + "G_cora.visualize()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6d5a0704", + "metadata": {}, + "outputs": [], + "source": [ + "G_cora.visualize(color_property=\"subject\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7dfe9e57", + "metadata": {}, + "outputs": [], + "source": [ + "G_cora.visualize(color_property=\"subject\", include_node_properties=[\"subject\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "db635dd6", + "metadata": {}, + "outputs": [], + "source": [ + "gds.degree.mutate(G_cora, mutateProperty=\"deg\")\n", + "G_cora.visualize(color_property=\"subject\", size_property=\"deg\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b6bc16f4", + "metadata": {}, + "outputs": [], + "source": [ + "G_cora.visualize(color_property=\"subject\", center_nodes=[12350])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "447f1a2d", + "metadata": {}, + "outputs": [], + "source": [ + "G_cora.drop()" + ] + }, + { + "cell_type": "markdown", + "id": "56dc02c4", + "metadata": {}, + "source": [ + "## Using PyVis" + ] + }, { "cell_type": "markdown", "id": "b1a8ab78", "metadata": {}, "source": [ - "## Sampling Cora\n", + "### Sampling Cora\n", "\n", "Next we use the [built-in Cora loader](https://neo4j.com/docs/graph-data-science-client/current/common-datasets/#_cora) to get the data into GDS.\n", "The nodes in the Cora dataset is represented by academic papers, and the relationships connecting them are citations.\n", @@ -109,7 +272,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": null, "id": "a575da60", "metadata": {}, "outputs": [], @@ -127,24 +290,25 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "id": "428ac7b8", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Metadata for our loaded Cora graph `G`: Graph(name=cora, node_count=2708, relationship_count=5429)\n", - "Node labels present in `G`: ['Paper']\n" - ] - } - ], + "outputs": [], "source": [ "print(f\"Metadata for our loaded Cora graph `G`: {G}\")\n", "print(f\"Node labels present in `G`: {G.node_labels()}\")" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "b6aceb0a", + "metadata": {}, + "outputs": [], + "source": [ + "G.visualize(color_property=\"subject\")" + ] + }, { "cell_type": "markdown", "id": "3e8b8a83", @@ -159,7 +323,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "id": "3d116738", "metadata": {}, "outputs": [], @@ -178,19 +342,10 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "id": "d66ea2d5", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Number of nodes in our sample: 406\n", - "Number of relationships in our sample: 532\n" - ] - } - ], + "outputs": [], "source": [ "print(f\"Number of nodes in our sample: {G_sample.node_count()}\")\n", "print(f\"Number of relationships in our sample: {G_sample.relationship_count()}\")" @@ -207,30 +362,10 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "id": "3d80d653", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "mutateMillis 0\n", - "nodePropertiesWritten 406\n", - "ranIterations 20\n", - "didConverge False\n", - "centralityDistribution {'min': 0.14999961853027344, 'max': 2.27294921...\n", - "postProcessingMillis 1\n", - "preProcessingMillis 0\n", - "computeMillis 7\n", - "configuration {'mutateProperty': 'rank', 'jobId': '5ca450ff-...\n", - "Name: 0, dtype: object" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "gds.pageRank.mutate(G_sample, mutateProperty=\"rank\")" ] @@ -240,7 +375,7 @@ "id": "722caa7b", "metadata": {}, "source": [ - "## Exporting the sampled Cora graph\n", + "### Exporting the sampled Cora graph\n", "\n", "We can now export the topology and node properties of our sampled graph that we want to visualize.\n", "\n", @@ -249,129 +384,10 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "id": "d3c76b25", "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - " | sourceNodeId | \n", - "targetNodeId | \n", - "relationshipType | \n", - "
---|---|---|---|
0 | \n", - "31336 | \n", - "31349 | \n", - "CITES | \n", - "
1 | \n", - "31336 | \n", - "686532 | \n", - "CITES | \n", - "
2 | \n", - "31336 | \n", - "1129442 | \n", - "CITES | \n", - "
3 | \n", - "31349 | \n", - "686532 | \n", - "CITES | \n", - "
4 | \n", - "31353 | \n", - "31336 | \n", - "CITES | \n", - "
... | \n", - "... | \n", - "... | \n", - "... | \n", - "
527 | \n", - "34961 | \n", - "31043 | \n", - "CITES | \n", - "
528 | \n", - "34961 | \n", - "22883 | \n", - "CITES | \n", - "
529 | \n", - "102879 | \n", - "9513 | \n", - "CITES | \n", - "
530 | \n", - "102884 | \n", - "9513 | \n", - "CITES | \n", - "
531 | \n", - "767763 | \n", - "1136631 | \n", - "CITES | \n", - "
532 rows × 3 columns
\n", - "\n", - " | nodeId | \n", - "rank | \n", - "subject | \n", - "
---|---|---|---|
0 | \n", - "164 | \n", - "0.245964 | \n", - "4.0 | \n", - "
1 | \n", - "434 | \n", - "0.158500 | \n", - "2.0 | \n", - "
2 | \n", - "1694 | \n", - "0.961240 | \n", - "5.0 | \n", - "
3 | \n", - "1949 | \n", - "0.224912 | \n", - "6.0 | \n", - "
4 | \n", - "1952 | \n", - "0.150000 | \n", - "6.0 | \n", - "
... | \n", - "... | \n", - "... | \n", - "... | \n", - "
401 | \n", - "1154103 | \n", - "0.319498 | \n", - "3.0 | \n", - "
402 | \n", - "1154124 | \n", - "0.627706 | \n", - "0.0 | \n", - "
403 | \n", - "1154169 | \n", - "0.154784 | \n", - "0.0 | \n", - "
404 | \n", - "1154251 | \n", - "0.187675 | \n", - "0.0 | \n", - "
405 | \n", - "1154276 | \n", - "0.277500 | \n", - "0.0 | \n", - "
406 rows × 3 columns
\n", - "