diff --git a/doc/interactive_sizing_options.ipynb b/doc/interactive_sizing_options.ipynb new file mode 100644 index 0000000..734a4a7 --- /dev/null +++ b/doc/interactive_sizing_options.ipynb @@ -0,0 +1,1592 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "e10bab62", + "metadata": {}, + "outputs": [], + "source": [ + "import datamapplot" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "775cffd6", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import requests\n", + "import io\n", + "\n", + "base_url = \"https://github.com/TutteInstitute/datamapplot\"\n", + "data_map_file = requests.get(\n", + " f\"{base_url}/raw/main/examples/arxiv_ml_data_map.npy\"\n", + ")\n", + "arxivml_data_map = np.load(io.BytesIO(data_map_file.content))\n", + "arxivml_label_layers = []\n", + "for layer_num in range(5):\n", + " label_file = requests.get(\n", + " f\"{base_url}/raw/interactive/examples/arxiv_ml_layer{layer_num}_cluster_labels.npy\"\n", + " )\n", + " arxivml_label_layers.append(np.load(io.BytesIO(label_file.content), allow_pickle=True))" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "f38a1caa", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plot = datamapplot.create_interactive_plot(\n", + " arxivml_data_map,\n", + " arxivml_label_layers[0],\n", + " arxivml_label_layers[2],\n", + " arxivml_label_layers[4],\n", + ")\n", + "plot" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "78cf0189", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plot = datamapplot.create_interactive_plot(\n", + " arxivml_data_map,\n", + " arxivml_label_layers[0],\n", + " arxivml_label_layers[2],\n", + " arxivml_label_layers[4],\n", + " min_fontsize=14,\n", + " max_fontsize=14,\n", + ")\n", + "plot" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "f28bbc94", + "metadata": {}, + "outputs": [], + "source": [ + "hover_data_file = requests.get(\n", + " f\"{base_url}/raw/interactive/examples/arxiv_ml_hover_data.npy\"\n", + ")\n", + "arxiv_hover_data = np.load(io.BytesIO(hover_data_file.content), allow_pickle=True)\n", + "arxiv_marker_size_array = np.asarray([len(x) for x in arxiv_hover_data], dtype=np.float32)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "fdadbbcc", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plot = datamapplot.create_interactive_plot(\n", + " arxivml_data_map,\n", + " arxivml_label_layers[0],\n", + " arxivml_label_layers[2],\n", + " arxivml_label_layers[4],\n", + " min_fontsize=14,\n", + " max_fontsize=14,\n", + " marker_size_array=arxiv_marker_size_array,\n", + ")\n", + "plot" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "fb120f24", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plot = datamapplot.create_interactive_plot(\n", + " arxivml_data_map,\n", + " arxivml_label_layers[0],\n", + " arxivml_label_layers[2],\n", + " arxivml_label_layers[4],\n", + " min_fontsize=14,\n", + " max_fontsize=14,\n", + " marker_size_array=[len(x) for x in arxiv_hover_data],\n", + " point_radius_min_pixels=1,\n", + " point_radius_max_pixels=8,\n", + ")\n", + "plot" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "74e0e3e8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plot = datamapplot.create_interactive_plot(\n", + " arxivml_data_map,\n", + " arxivml_label_layers[0],\n", + " arxivml_label_layers[2],\n", + " arxivml_label_layers[4],\n", + " min_fontsize=14,\n", + " max_fontsize=14,\n", + " marker_size_array=[len(x) for x in arxiv_hover_data],\n", + " point_radius_min_pixels=1,\n", + " point_line_width=0,\n", + ")\n", + "plot" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "89f04852", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plot = datamapplot.create_interactive_plot(\n", + " arxivml_data_map,\n", + " arxivml_label_layers[0],\n", + " arxivml_label_layers[2],\n", + " arxivml_label_layers[4],\n", + " min_fontsize=14,\n", + " max_fontsize=14,\n", + " text_collision_size_scale=2,\n", + ")\n", + "plot" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "04a6403a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plot = datamapplot.create_interactive_plot(\n", + " arxivml_data_map,\n", + " arxivml_label_layers[0],\n", + " arxivml_label_layers[2],\n", + " arxivml_label_layers[4],\n", + " min_fontsize=14,\n", + " max_fontsize=14,\n", + " initial_zoom_fraction=0.5,\n", + ")\n", + "plot" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1e08b307", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:datamapplot]", + "language": "python", + "name": "conda-env-datamapplot-py" + }, + "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.10.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/doc/wikipedia_marker_size_array.npy b/doc/wikipedia_marker_size_array.npy new file mode 100644 index 0000000..c79c2d6 Binary files /dev/null and b/doc/wikipedia_marker_size_array.npy differ diff --git a/examples/plot_interactive_wikipedia.py b/examples/plot_interactive_wikipedia.py new file mode 100644 index 0000000..3c3a6c2 --- /dev/null +++ b/examples/plot_interactive_wikipedia.py @@ -0,0 +1,35 @@ +import numpy as np +import datamapplot + +wikipedia_data_map = np.load("/Users/leland/PycharmProjects/datamapplot/examples/wikipedia_layered_data_map.npy") +wikipedia_label_layers = [] +for i in range(6): + wikipedia_label_layers.append( + np.load(f"/Users/leland/PycharmProjects/datamapplot/examples/wikipedia_layer{i}_cluster_labels.npy", allow_pickle=True) + ) +wikipedia_hover_text = [ + x.strip() + for x in open( + "/Users/leland/PycharmProjects/datamapplot/examples/wikipedia_large_hover_text.txt", + mode="r" + ) +] +wikipedia_marker_size_array = np.load("../doc/wikipedia_marker_size_array.npy") + +plot = datamapplot.create_interactive_plot( + wikipedia_data_map, + wikipedia_label_layers[0], + wikipedia_label_layers[1], + wikipedia_label_layers[3], + wikipedia_label_layers[5], + hover_text = wikipedia_hover_text, + title="Map of Wikipedia", + sub_title="Paragraphs from articles on Simple Wikipedia embedded with Cohere embed", + logo="https://asset.brandfetch.io/idfDTLvPCK/idyv4d98RT.png", + font_family="Marcellus SC", + background_color="#eae6de", + marker_size_array=wikipedia_marker_size_array, + cluster_boundary_polygons=True, + initial_zoom_fraction=0.4, +) +plot \ No newline at end of file