{ "cells": [ { "cell_type": "markdown", "id": "ffaf3148-442e-4879-87a4-0253b5c186f2", "metadata": {}, "source": [ "# Drawing Graph Edges Using `geom_segment()` and `geom_curve()`\n", "\n", "Beyond merely connecting two points on a chart, the `geom_segment()` and `geom_curve()` geometries\n", "can, with some fine-tuning, help to visualize graph-like data.\n", "\n", "Use aesthetics `size_start/end` and `stroke_start/end` to allow `segment/curve`\n", "to take into account the size of the point from which it starts/ends and to avoid drawing over it.\n", "\n", "Utilize the `spacer` parameter for further manual fine-tuning." ] }, { "cell_type": "code", "execution_count": 1, "id": "b4297632-5b34-42bd-9472-1ccff49ba27e", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "9895b4ed-7d29-41ab-b051-27c82629f81c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "id": "a942c867-0036-4483-a355-5a9d982bc459", "metadata": {}, "outputs": [], "source": [ "x = [-1, 0, 1]\n", "y = [-1, 1, -1]\n", "shape = [1, 16, 21]\n", "size = [1, 2, 3]\n", "stroke = [1, 0, 2]\n", "\n", "vertices_data = {\n", " 'x': x,\n", " 'y': y,\n", " 'shape': shape,\n", " 'size': size,\n", " 'stroke': stroke,\n", "}" ] }, { "cell_type": "code", "execution_count": 4, "id": "730b5140-0ed3-4296-8be3-d6eb016e8c13", "metadata": {}, "outputs": [], "source": [ "vertices_layer = geom_point(aes('x', 'y', size='size', shape='shape', stroke='stroke'),\n", " color='#4575b4', fill='#abd9e9')\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "a08e6134-6d72-4863-9bde-2d03af0cea25", "metadata": {}, "outputs": [ { "data": { "text/html": [ " \n", " " ], "text/plain": [ "\n", " | from | \n", "to | \n", "relation | \n", "node | \n", "x | \n", "y | \n", "node_to | \n", "x_to | \n", "y_to | \n", "
---|---|---|---|---|---|---|---|---|---|
0 | \n", "Animals | \n", "Living\\nThings | \n", "is | \n", "Animals | \n", "-1 | \n", "0 | \n", "Living\\nThings | \n", "0 | \n", "1 | \n", "
1 | \n", "Plants | \n", "Living\\nThings | \n", "is | \n", "Plants | \n", "1 | \n", "0 | \n", "Living\\nThings | \n", "0 | \n", "1 | \n", "
2 | \n", "Dogs | \n", "Animals | \n", "is | \n", "Dogs | \n", "-2 | \n", "-1 | \n", "Animals | \n", "-1 | \n", "0 | \n", "
3 | \n", "Cows | \n", "Animals | \n", "is | \n", "Cows | \n", "0 | \n", "-1 | \n", "Animals | \n", "-1 | \n", "0 | \n", "
4 | \n", "Cows | \n", "Herbs | \n", "eat | \n", "Cows | \n", "0 | \n", "-1 | \n", "Herbs | \n", "2 | \n", "-1 | \n", "
5 | \n", "Herbs | \n", "Plants | \n", "is | \n", "Herbs | \n", "2 | \n", "-1 | \n", "Plants | \n", "1 | \n", "0 | \n", "