{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "525390a4-967a-493c-ac98-6f0b54c20aa4", "metadata": {}, "outputs": [], "source": [ "import IPython\n", "from IPython.display import IFrame" ] }, { "cell_type": "code", "execution_count": 2, "id": "843d218e-8f25-4dde-8b13-6b8359b616ba", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "node1\tlabel\tnode2\tweight\n", "Alice\tfriend\tSusan\t0.9\n", "Susan\tfriend\tJohn\t0.3\n", "John\tfriend\tClaudia\t\n", "Ulrich\tfriend\tJohn\t\n", "Fritz\tfriend\tUlrich\t\n", "Fritz\tfriend\tAlice\t\n", "Alice\tborn\tUSA\t\n", "Susan\tborn\tUSA\t\n", "John\tborn\tUSA\t\n", "Claudia\tborn\tGermany\t\n", "Ulrich\tborn\tGermany\t\n", "Fritz\tborn\tGermany\t\n", "Alice\tlives\tGermany\t\n", "Susan\tlives\tUSA\t\n", "John\tlives\tBrazil\t\n", "Claudia\tlives\tGermany\t\n", "Ulrich\tlives\tBrazil\t\n", "Fritz\tlives\tGermany\t" ] } ], "source": [ "!kgtk cat -i example.tsv" ] }, { "cell_type": "code", "execution_count": 3, "id": "476ccf1f-728c-4125-866b-769d83e13499", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "id\tnode;label\tis_country\ttype\tdegree\ttype_missing\tpopulation\n", "Alice\t‘Alice’@en\t0\thuman\t4\t\t\n", "Susan\t‘Susan’@en\t0\thuman\t4\t\t\n", "John\t‘John’@en\t0\thuman\t4\t\t\n", "Claudia\t‘Claudia’@en\t0\thuman\t3\t\t\n", "Ulrich\t‘Ulrich’@en\t0\thuman\t4\t\t\n", "Fritz\t‘Fritz’@en\t0\thuman\t4\t\t\n", "USA\t‘USA’@en\t1\tcountry\t5\tcountry\t300\n", "Germany\t‘Germany’@en\t1\tcountry\t5\tcountry\t50\n", "Brazil\t‘Brazil’@en\t1\tcountry\t2\tcountry\t200" ] } ], "source": [ "!kgtk cat -i example_node.tsv" ] }, { "cell_type": "markdown", "id": "1943a773-357e-4a49-98f2-93e1abfe5abc", "metadata": {}, "source": [ "## 1. Default" ] }, { "cell_type": "code", "execution_count": 4, "id": "e123aa20-10c3-4777-aa7d-cf7d1feb79f6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "node1;label not in edge file\n", "node2;label not in edge file\n", "No label;label col in edge file\n" ] } ], "source": [ "!kgtk visualize-force-graph -i example.tsv -o default.html" ] }, { "cell_type": "code", "execution_count": 5, "id": "df1ec2ee-205c-4247-ba8e-e687794f3c06", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IPython.display.HTML(filename='default.html')" ] }, { "cell_type": "code", "execution_count": 6, "id": "24fe39af-fa73-4e4b-ad9b-5ae279cdd189", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IFrame(src='default.html', width=300, height=300)" ] }, { "cell_type": "markdown", "id": "4088adfc-1eae-4be2-a534-2c8768b6454f", "metadata": {}, "source": [ "## 2. Show countries" ] }, { "cell_type": "code", "execution_count": 7, "id": "a6a8f1eb-8635-48d0-9b18-e6745206cc7e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No label;label col in edge file\n" ] } ], "source": [ "!kgtk visualize-force-graph -i example.tsv \\\n", "--node-file example_node.tsv \\\n", "--node-color-column is_country \\\n", "--node-color-style categorical \\\n", "-o show_countries.html" ] }, { "cell_type": "code", "execution_count": 8, "id": "ac733e96-469a-426d-988b-eeed5402d64f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IFrame(src='show_countries.html', width=300, height=300)" ] }, { "cell_type": "markdown", "id": "988029db-5fe5-4c22-8e55-4dcb25ee0afc", "metadata": {}, "source": [ "## 3. Show Types" ] }, { "cell_type": "code", "execution_count": 9, "id": "cd4c0ab1-a1bc-43d8-ad5e-8e10e4c6d58c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No label;label col in edge file\n" ] } ], "source": [ "!kgtk visualize-force-graph -i example.tsv \\\n", "--node-file example_node.tsv \\\n", "--node-color-column type \\\n", "--node-color-style categorical \\\n", "-o show_types.html" ] }, { "cell_type": "code", "execution_count": 10, "id": "b6cc05da-d365-45c8-ace2-a8976ac6001b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IFrame(src='show_types.html', width=300, height=300)" ] }, { "cell_type": "markdown", "id": "16070fc8-5c25-405e-8a20-039792aca284", "metadata": {}, "source": [ "## 4. Handle Missing Values" ] }, { "cell_type": "code", "execution_count": 11, "id": "7a900dbe-f086-465e-9b80-6f2fdff6ba3c", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No label;label col in edge file\n" ] } ], "source": [ "!kgtk visualize-force-graph -i example.tsv \\\n", "--node-file example_node.tsv \\\n", "--node-color-column type_missing \\\n", "--node-color-style categorical \\\n", "-o show_types_missing.html" ] }, { "cell_type": "code", "execution_count": 12, "id": "ee2cf81b-8b6c-409c-85e3-b6d0e48158c3", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IFrame(src='show_types_missing.html', width=300, height=300)" ] }, { "cell_type": "markdown", "id": "40faeaef-2786-4563-acd0-7ba4f5b40664", "metadata": {}, "source": [ "## 5. Show color gradient" ] }, { "cell_type": "code", "execution_count": 13, "id": "501faf2f-6892-4299-b757-e68f32d3912e", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No label;label col in edge file\n" ] } ], "source": [ "!kgtk visualize-force-graph -i example.tsv \\\n", "--node-file example_node.tsv \\\n", "--node-color-column degree \\\n", "--node-color-style gradient \\\n", "--node-color-scale linear \\\n", "-o show_color_gradient.html" ] }, { "cell_type": "code", "execution_count": 14, "id": "3f0076a7-574b-4c63-8274-86fd53a5c1db", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IFrame(src='show_color_gradient.html', width=300, height=300)" ] }, { "cell_type": "markdown", "id": "7aae1af1-de8f-44e1-8399-0a5a61944eda", "metadata": {}, "source": [ "## 6. Show edge color" ] }, { "cell_type": "code", "execution_count": 15, "id": "391e277e-c3f9-404a-ad3d-043010525268", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "node1;label not in edge file\n", "node2;label not in edge file\n", "No label;label col in edge file\n" ] } ], "source": [ "!kgtk visualize-force-graph -i example.tsv \\\n", "--edge-color-column label \\\n", "--edge-color-style categorical \\\n", "-o show_edge_color.html" ] }, { "cell_type": "code", "execution_count": 16, "id": "5a41b2bc-5f39-4e29-aed5-a00c8a3b71f7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IFrame(src='show_edge_color.html', width=300, height=300)" ] }, { "cell_type": "markdown", "id": "dc70c035-6270-4207-917c-21a46e508458", "metadata": {}, "source": [ "## 7. Show edge and node color" ] }, { "cell_type": "code", "execution_count": 17, "id": "e9a1e202-1802-41d8-b2bf-b0d7f4118f2d", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No label;label col in edge file\n" ] } ], "source": [ "!kgtk visualize-force-graph -i example.tsv \\\n", "--edge-color-column label \\\n", "--edge-color-style categorical \\\n", "--node-file example_node.tsv \\\n", "--node-color-column degree \\\n", "--node-color-style gradient \\\n", "--node-color-scale linear \\\n", "-o show_edge_node_color.html" ] }, { "cell_type": "code", "execution_count": 18, "id": "6229b61f-17ae-4e9b-a852-1a7b615d1ca9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IFrame(src='show_edge_node_color.html', width=300, height=300)" ] }, { "cell_type": "markdown", "id": "0826f327-29a8-4c7f-b26c-4699826e5906", "metadata": {}, "source": [ "## 8. Node Size" ] }, { "cell_type": "code", "execution_count": 19, "id": "bd716610-4928-4fde-a88d-c1ceb40a91eb", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No label;label col in edge file\n" ] } ], "source": [ "!kgtk visualize-force-graph -i example.tsv \\\n", "--node-file example_node.tsv \\\n", "--node-size-column population \\\n", "--node-size-minimum 2.0 \\\n", "--node-size-maximum 4.0 \\\n", "--node-size-default 1.0 \\\n", "--node-size-scale log \\\n", "-o node_size_linear.html" ] }, { "cell_type": "code", "execution_count": 20, "id": "77e5a6ba-6d83-4f03-9687-a9c34f77affd", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IFrame(src='node_size_linear.html', width=300, height=300)" ] }, { "cell_type": "code", "execution_count": 21, "id": "5e5f6cb4-cb7c-49a8-9435-000883700f40", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No label;label col in edge file\n" ] } ], "source": [ "!kgtk visualize-force-graph -i example.tsv \\\n", "--node-file example_node.tsv \\\n", "--node-size-column population \\\n", "--node-size-minimum 2.0 \\\n", "--node-size-maximum 4.0 \\\n", "--node-size-default 1.0 \\\n", "--node-size-scale log \\\n", "-o node_size_log.html" ] }, { "cell_type": "code", "execution_count": 22, "id": "e9f41d3e-19d6-4637-8170-505789e52f5f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IFrame(src='node_size_log.html', width=300, height=300)" ] }, { "cell_type": "markdown", "id": "e47d687e-1766-4574-9758-94cb46b6df87", "metadata": {}, "source": [ "## 9. Edge thickness" ] }, { "cell_type": "code", "execution_count": 23, "id": "7361e2a2-cf94-46e5-a955-b8562676c836", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "node1;label not in edge file\n", "node2;label not in edge file\n", "No label;label col in edge file\n" ] } ], "source": [ "!kgtk visualize-force-graph -i example.tsv \\\n", "--edge-width-column weight \\\n", "--edge-width-minimum 2.0 \\\n", "--edge-width-maximum 4.0 \\\n", "--edge-width-default 1.0 \\\n", "--edge-width-scale linear \\\n", "-o show_edge_thickness.html" ] }, { "cell_type": "code", "execution_count": 24, "id": "cc223e73-70ec-4129-b5ed-7510ad619e2e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "IFrame(src='show_edge_thickness.html', width=300, height=300)" ] }, { "cell_type": "code", "execution_count": null, "id": "6c085a9a-69fe-4ec9-8fcf-859410a717d0", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "4f43a7a3-34c0-4c35-a700-e16a0ca28e02", "metadata": {}, "outputs": [], "source": [] } ], "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.8.8" } }, "nbformat": 4, "nbformat_minor": 5 }