|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "import numpy as np\n", |
| 10 | + "import napari\n", |
| 11 | + "from napari_matplotlib import FeaturesHistogramWidget\n", |
| 12 | + "import matplotlib.pyplot as plt" |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "code", |
| 17 | + "execution_count": 24, |
| 18 | + "metadata": {}, |
| 19 | + "outputs": [], |
| 20 | + "source": [ |
| 21 | + "n_points = 1000\n", |
| 22 | + "random_points = np.random.random((n_points, 3)) * 10\n", |
| 23 | + "random_points2 = np.random.random((n_points, 3)) * 10\n", |
| 24 | + "random_vectors = random_points2 - random_points\n", |
| 25 | + "\n", |
| 26 | + "vectors = np.stack([random_points, random_vectors], axis=1)\n", |
| 27 | + "feature1 = np.random.random(n_points)\n", |
| 28 | + "feature2 = np.random.normal(size=n_points)" |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "code", |
| 33 | + "execution_count": 25, |
| 34 | + "metadata": {}, |
| 35 | + "outputs": [], |
| 36 | + "source": [ |
| 37 | + "viewer = napari.Viewer()" |
| 38 | + ] |
| 39 | + }, |
| 40 | + { |
| 41 | + "cell_type": "code", |
| 42 | + "execution_count": 26, |
| 43 | + "metadata": {}, |
| 44 | + "outputs": [ |
| 45 | + { |
| 46 | + "data": { |
| 47 | + "text/plain": [ |
| 48 | + "<Vectors layer 'vectors1' at 0x1ec34e98130>" |
| 49 | + ] |
| 50 | + }, |
| 51 | + "execution_count": 26, |
| 52 | + "metadata": {}, |
| 53 | + "output_type": "execute_result" |
| 54 | + } |
| 55 | + ], |
| 56 | + "source": [ |
| 57 | + "viewer.add_points(\n", |
| 58 | + " random_points,\n", |
| 59 | + " properties={\"feature1\": feature1, \"feature2\": feature2},\n", |
| 60 | + " name=\"points1\",\n", |
| 61 | + " face_color=\"feature1\",\n", |
| 62 | + " size=1,\n", |
| 63 | + ")\n", |
| 64 | + "\n", |
| 65 | + "viewer.add_vectors(\n", |
| 66 | + " vectors,\n", |
| 67 | + " properties={\"feature1\": feature1, \"feature2\": feature2},\n", |
| 68 | + " name=\"vectors1\",\n", |
| 69 | + " edge_width=1,\n", |
| 70 | + " edge_color=\"feature1\",\n", |
| 71 | + ")" |
| 72 | + ] |
| 73 | + }, |
| 74 | + { |
| 75 | + "cell_type": "code", |
| 76 | + "execution_count": 27, |
| 77 | + "metadata": {}, |
| 78 | + "outputs": [ |
| 79 | + { |
| 80 | + "data": { |
| 81 | + "text/plain": [ |
| 82 | + "<napari._qt.widgets.qt_viewer_dock_widget.QtViewerDockWidget at 0x1ec387349d0>" |
| 83 | + ] |
| 84 | + }, |
| 85 | + "execution_count": 27, |
| 86 | + "metadata": {}, |
| 87 | + "output_type": "execute_result" |
| 88 | + } |
| 89 | + ], |
| 90 | + "source": [ |
| 91 | + "widget = FeaturesHistogramWidget(viewer)\n", |
| 92 | + "viewer.window.add_dock_widget(widget)" |
| 93 | + ] |
| 94 | + }, |
| 95 | + { |
| 96 | + "cell_type": "code", |
| 97 | + "execution_count": 19, |
| 98 | + "metadata": {}, |
| 99 | + "outputs": [ |
| 100 | + { |
| 101 | + "data": { |
| 102 | + "text/plain": [ |
| 103 | + "'feature1'" |
| 104 | + ] |
| 105 | + }, |
| 106 | + "execution_count": 19, |
| 107 | + "metadata": {}, |
| 108 | + "output_type": "execute_result" |
| 109 | + } |
| 110 | + ], |
| 111 | + "source": [ |
| 112 | + "widget.x_axis_key" |
| 113 | + ] |
| 114 | + }, |
| 115 | + { |
| 116 | + "cell_type": "code", |
| 117 | + "execution_count": 36, |
| 118 | + "metadata": {}, |
| 119 | + "outputs": [], |
| 120 | + "source": [ |
| 121 | + "widget.viewer.layers[widget.layers[0].name].refresh_colors(True)\n", |
| 122 | + "widget.viewer.layers[0].properties\n", |
| 123 | + "widget.viewer.layers[widget.layers[0].name].refresh_colors(True)" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "code", |
| 128 | + "execution_count": 33, |
| 129 | + "metadata": {}, |
| 130 | + "outputs": [ |
| 131 | + { |
| 132 | + "data": { |
| 133 | + "text/plain": [ |
| 134 | + "True" |
| 135 | + ] |
| 136 | + }, |
| 137 | + "execution_count": 33, |
| 138 | + "metadata": {}, |
| 139 | + "output_type": "execute_result" |
| 140 | + } |
| 141 | + ], |
| 142 | + "source": [ |
| 143 | + "widget.viewer.layers[1]._update_properties" |
| 144 | + ] |
| 145 | + }, |
| 146 | + { |
| 147 | + "cell_type": "code", |
| 148 | + "execution_count": 40, |
| 149 | + "metadata": {}, |
| 150 | + "outputs": [], |
| 151 | + "source": [ |
| 152 | + "widget.viewer.layers[0].edge_color = \"feature2\"" |
| 153 | + ] |
| 154 | + }, |
| 155 | + { |
| 156 | + "cell_type": "code", |
| 157 | + "execution_count": null, |
| 158 | + "metadata": {}, |
| 159 | + "outputs": [], |
| 160 | + "source": [] |
| 161 | + } |
| 162 | + ], |
| 163 | + "metadata": { |
| 164 | + "kernelspec": { |
| 165 | + "display_name": "stress", |
| 166 | + "language": "python", |
| 167 | + "name": "python3" |
| 168 | + }, |
| 169 | + "language_info": { |
| 170 | + "codemirror_mode": { |
| 171 | + "name": "ipython", |
| 172 | + "version": 3 |
| 173 | + }, |
| 174 | + "file_extension": ".py", |
| 175 | + "mimetype": "text/x-python", |
| 176 | + "name": "python", |
| 177 | + "nbconvert_exporter": "python", |
| 178 | + "pygments_lexer": "ipython3", |
| 179 | + "version": "3.9.18" |
| 180 | + }, |
| 181 | + "orig_nbformat": 4 |
| 182 | + }, |
| 183 | + "nbformat": 4, |
| 184 | + "nbformat_minor": 2 |
| 185 | +} |
0 commit comments