{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Table widgets\n", "\n", "In order to control interactive plots, sometimes we need to vary certain parameters which depend on the data stored in the table. Therefore, table object has several widgets, which can be used for that purpose.\n", "\n", "The table we are going to use as an example is:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "import ubermagtable as ut\n", "\n", "# Sample OOMMF .odt file\n", "dirname = os.path.join(\"..\", \"ubermagtable\", \"tests\", \"test_sample\")\n", "odtfile = os.path.join(dirname, \"oommf-new-file2.odt\")\n", "\n", "table = ut.Table.fromfile(odtfile, x=\"t\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Slider\n", "\n", "Slider widget allows us to restrict the time values shown in an interactive plot. Slider widget is:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "348c4ac778bd4279af25ca083e0d34a0", "version_major": 2, "version_minor": 0 }, "text/plain": [ "SelectionRangeSlider(description='t (ps):', index=(0, 199), options=((1.0, 1e-12), (2.0, 2e-12), (3.0, 3e-12),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "table.slider()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The minimum value of the slider is the minimum time value, whereas the maximum value is the maximum time value. The steps on the slider correspond to the time step in data.\n", "\n", "Widget description is generated by default, and can be changed by passing `description` argument." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0a902569d29145febb0e8580b488900a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "SelectionRangeSlider(description='my slider', index=(0, 199), options=((1.0, 1e-12), (2.0, 2e-12), (3.0, 3e-12…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "table.slider(description=\"my slider\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Similar to plots, we can change the multiplier:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "435594b3eb794ddfb4e243cf0e24a328", "version_major": 2, "version_minor": 0 }, "text/plain": [ "SelectionRangeSlider(description='t (ps):', index=(0, 199), options=((1.0, 1e-12), (2.0, 2e-12), (3.0, 3e-12),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "table.slider(multiplier=1e-12)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We now get the values in picoseconds and the units are shown in the widget description.\n", "\n", "Slider is based on [ipywidgets.SelectionSlider](https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20List.html#SelectionSlider), so any keyword arguments accepted by it can be passed." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2465e3154649491c9a276190b62dc15a", "version_major": 2, "version_minor": 0 }, "text/plain": [ "SelectionRangeSlider(description='t (ps):', index=(0, 199), options=((1.0, 1e-12), (2.0, 2e-12), (3.0, 3e-12),…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "table.slider(orientation=\"vertical\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can get a slider for any variable by passing it via `x`:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "34f5424734b04199a60046f707618ae0", "version_major": 2, "version_minor": 0 }, "text/plain": [ "SelectionRangeSlider(description='mx:', index=(0, 199), options=((1.0, 1e-12), (2.0, 2e-12), (3.0, 3e-12), (4.…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "table.slider(x=\"mx\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Value selector\n", "\n", "A simple widget, which allows us to select the columns from data table can be obtained using `selector`." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "55f5c0fdd22e466c9ade31ed1288d282", "version_major": 2, "version_minor": 0 }, "text/plain": [ "SelectMultiple(description='y-axis:', index=(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18)…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "table.selector()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This returns a selection widget with all data columns present in the table. This method is based on `ipywidgets.SelectMultiple`, so any keyword argument accepted by it can be passed." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": { "0a902569d29145febb0e8580b488900a": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "SelectionRangeSliderModel", "state": { "_model_name": "SelectionRangeSliderModel", "_options_labels": [ "1.0", "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8.0", "9.0", "10.0", "11.0", "12.0", "13.0", "14.0", "15.0", "16.0", "17.0", "18.0", "19.0", "20.0", "21.0", "22.0", "23.0", "24.0", "25.0", "26.0", "27.0", "28.0", "29.0", "30.0", "31.0", "32.0", "33.0", "34.0", "35.0", "36.0", "37.0", "38.0", "39.0", "40.0", "41.0", "42.0", "43.0", "44.0", "45.0", "46.0", "47.0", "48.0", "49.0", "50.0", "51.0", "52.0", "53.0", "54.0", "55.0", "56.0", "57.0", "58.0", "59.0", "60.0", "61.0", "62.0", "63.0", "64.0", "65.0", "66.0", "67.0", "68.0", "69.0", "70.0", "71.0", "72.0", "73.0", "74.0", "75.0", "76.0", "77.0", "78.0", "79.0", "80.0", "81.0", "82.0", "83.0", "84.0", "85.0", "86.0", "87.0", "88.0", "89.0", "90.0", "91.0", "92.0", "93.0", "94.0", "95.0", "96.0", "97.0", "98.0", "99.0", "100.0", "101.0", "102.0", "103.0", "104.0", "105.0", "106.0", "107.0", "108.0", "109.0", "110.0", "111.0", "112.0", "113.0", "114.0", "115.0", "116.0", "117.0", "118.0", "119.0", "120.0", "121.0", "122.0", "123.0", "124.0", "125.0", "126.0", "127.0", "128.0", "129.0", "130.0", "131.0", "132.0", "133.0", "134.0", "135.0", "136.0", "137.0", "138.0", "139.0", "140.0", "141.0", "142.0", "143.0", "144.0", "145.0", "146.0", "147.0", "148.0", "149.0", "150.0", "151.0", "152.0", "153.0", "154.0", "155.0", "156.0", "157.0", "158.0", "159.0", "160.0", "161.0", "162.0", "163.0", "164.0", "165.0", "166.0", "167.0", "168.0", "169.0", "170.0", "171.0", "172.0", "173.0", "174.0", "175.0", "176.0", "177.0", "178.0", "179.0", "180.0", "181.0", "182.0", "183.0", "184.0", "185.0", "186.0", "187.0", "188.0", "189.0", "190.0", "191.0", "192.0", "193.0", "194.0", "195.0", "196.0", "197.0", "198.0", "199.0", "200.0" ], "_view_name": "SelectionRangeSliderView", "description": "my slider", "index": [ 0, 199 ], "layout": "IPY_MODEL_eca5eef8fc844a82ad7e135b1de3f4f7", "style": "IPY_MODEL_f19c3ba55f31463faf8b5a59548873da" } }, "0d5d38481b35460293fb9e6ab964b412": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "0fae275ca26948c0b9145748ff9237cf": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "1634f122f215430686e46d883105b98e": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "2465e3154649491c9a276190b62dc15a": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "SelectionRangeSliderModel", "state": { "_model_name": "SelectionRangeSliderModel", "_options_labels": [ "1.0", "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8.0", "9.0", "10.0", "11.0", "12.0", "13.0", "14.0", "15.0", "16.0", "17.0", "18.0", "19.0", "20.0", "21.0", "22.0", "23.0", "24.0", "25.0", "26.0", "27.0", "28.0", "29.0", "30.0", "31.0", "32.0", "33.0", "34.0", "35.0", "36.0", "37.0", "38.0", "39.0", "40.0", "41.0", "42.0", "43.0", "44.0", "45.0", "46.0", "47.0", "48.0", "49.0", "50.0", "51.0", "52.0", "53.0", "54.0", "55.0", "56.0", "57.0", "58.0", "59.0", "60.0", "61.0", "62.0", "63.0", "64.0", "65.0", "66.0", "67.0", "68.0", "69.0", "70.0", "71.0", "72.0", "73.0", "74.0", "75.0", "76.0", "77.0", "78.0", "79.0", "80.0", "81.0", "82.0", "83.0", "84.0", "85.0", "86.0", "87.0", "88.0", "89.0", "90.0", "91.0", "92.0", "93.0", "94.0", "95.0", "96.0", "97.0", "98.0", "99.0", "100.0", "101.0", "102.0", "103.0", "104.0", "105.0", "106.0", "107.0", "108.0", "109.0", "110.0", "111.0", "112.0", "113.0", "114.0", "115.0", "116.0", "117.0", "118.0", "119.0", "120.0", "121.0", "122.0", "123.0", "124.0", "125.0", "126.0", "127.0", "128.0", "129.0", "130.0", "131.0", "132.0", "133.0", "134.0", "135.0", "136.0", "137.0", "138.0", "139.0", "140.0", "141.0", "142.0", "143.0", "144.0", "145.0", "146.0", "147.0", "148.0", "149.0", "150.0", "151.0", "152.0", "153.0", "154.0", "155.0", "156.0", "157.0", "158.0", "159.0", "160.0", "161.0", "162.0", "163.0", "164.0", "165.0", "166.0", "167.0", "168.0", "169.0", "170.0", "171.0", "172.0", "173.0", "174.0", "175.0", "176.0", "177.0", "178.0", "179.0", "180.0", "181.0", "182.0", "183.0", "184.0", "185.0", "186.0", "187.0", "188.0", "189.0", "190.0", "191.0", "192.0", "193.0", "194.0", "195.0", "196.0", "197.0", "198.0", "199.0", "200.0" ], "_view_name": "SelectionRangeSliderView", "description": "t (ps):", "index": [ 0, 199 ], "layout": "IPY_MODEL_c3b46aaa299540128d5a3faf4c181859", "orientation": "vertical", "style": "IPY_MODEL_0fae275ca26948c0b9145748ff9237cf" } }, "348c4ac778bd4279af25ca083e0d34a0": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "SelectionRangeSliderModel", "state": { "_model_name": "SelectionRangeSliderModel", "_options_labels": [ "1.0", "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8.0", "9.0", "10.0", "11.0", "12.0", "13.0", "14.0", "15.0", "16.0", "17.0", "18.0", "19.0", "20.0", "21.0", "22.0", "23.0", "24.0", "25.0", "26.0", "27.0", "28.0", "29.0", "30.0", "31.0", "32.0", "33.0", "34.0", "35.0", "36.0", "37.0", "38.0", "39.0", "40.0", "41.0", "42.0", "43.0", "44.0", "45.0", "46.0", "47.0", "48.0", "49.0", "50.0", "51.0", "52.0", "53.0", "54.0", "55.0", "56.0", "57.0", "58.0", "59.0", "60.0", "61.0", "62.0", "63.0", "64.0", "65.0", "66.0", "67.0", "68.0", "69.0", "70.0", "71.0", "72.0", "73.0", "74.0", "75.0", "76.0", "77.0", "78.0", "79.0", "80.0", "81.0", "82.0", "83.0", "84.0", "85.0", "86.0", "87.0", "88.0", "89.0", "90.0", "91.0", "92.0", "93.0", "94.0", "95.0", "96.0", "97.0", "98.0", "99.0", "100.0", "101.0", "102.0", "103.0", "104.0", "105.0", "106.0", "107.0", "108.0", "109.0", "110.0", "111.0", "112.0", "113.0", "114.0", "115.0", "116.0", "117.0", "118.0", "119.0", "120.0", "121.0", "122.0", "123.0", "124.0", "125.0", "126.0", "127.0", "128.0", "129.0", "130.0", "131.0", "132.0", "133.0", "134.0", "135.0", "136.0", "137.0", "138.0", "139.0", "140.0", "141.0", "142.0", "143.0", "144.0", "145.0", "146.0", "147.0", "148.0", "149.0", "150.0", "151.0", "152.0", "153.0", "154.0", "155.0", "156.0", "157.0", "158.0", "159.0", "160.0", "161.0", "162.0", "163.0", "164.0", "165.0", "166.0", "167.0", "168.0", "169.0", "170.0", "171.0", "172.0", "173.0", "174.0", "175.0", "176.0", "177.0", "178.0", "179.0", "180.0", "181.0", "182.0", "183.0", "184.0", "185.0", "186.0", "187.0", "188.0", "189.0", "190.0", "191.0", "192.0", "193.0", "194.0", "195.0", "196.0", "197.0", "198.0", "199.0", "200.0" ], "_view_name": "SelectionRangeSliderView", "description": "t (ps):", "index": [ 0, 199 ], "layout": "IPY_MODEL_a6c2503473e64430993d575e2147a86f", "style": "IPY_MODEL_f5238305712947f2b53220d13fb69b64" } }, "34f5424734b04199a60046f707618ae0": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "SelectionRangeSliderModel", "state": { "_model_name": "SelectionRangeSliderModel", "_options_labels": [ "1.0", "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8.0", "9.0", "10.0", "11.0", "12.0", "13.0", "14.0", "15.0", "16.0", "17.0", "18.0", "19.0", "20.0", "21.0", "22.0", "23.0", "24.0", "25.0", "26.0", "27.0", "28.0", "29.0", "30.0", "31.0", "32.0", "33.0", "34.0", "35.0", "36.0", "37.0", "38.0", "39.0", "40.0", "41.0", "42.0", "43.0", "44.0", "45.0", "46.0", "47.0", "48.0", "49.0", "50.0", "51.0", "52.0", "53.0", "54.0", "55.0", "56.0", "57.0", "58.0", "59.0", "60.0", "61.0", "62.0", "63.0", "64.0", "65.0", "66.0", "67.0", "68.0", "69.0", "70.0", "71.0", "72.0", "73.0", "74.0", "75.0", "76.0", "77.0", "78.0", "79.0", "80.0", "81.0", "82.0", "83.0", "84.0", "85.0", "86.0", "87.0", "88.0", "89.0", "90.0", "91.0", "92.0", "93.0", "94.0", "95.0", "96.0", "97.0", "98.0", "99.0", "100.0", "101.0", "102.0", "103.0", "104.0", "105.0", "106.0", "107.0", "108.0", "109.0", "110.0", "111.0", "112.0", "113.0", "114.0", "115.0", "116.0", "117.0", "118.0", "119.0", "120.0", "121.0", "122.0", "123.0", "124.0", "125.0", "126.0", "127.0", "128.0", "129.0", "130.0", "131.0", "132.0", "133.0", "134.0", "135.0", "136.0", "137.0", "138.0", "139.0", "140.0", "141.0", "142.0", "143.0", "144.0", "145.0", "146.0", "147.0", "148.0", "149.0", "150.0", "151.0", "152.0", "153.0", "154.0", "155.0", "156.0", "157.0", "158.0", "159.0", "160.0", "161.0", "162.0", "163.0", "164.0", "165.0", "166.0", "167.0", "168.0", "169.0", "170.0", "171.0", "172.0", "173.0", "174.0", "175.0", "176.0", "177.0", "178.0", "179.0", "180.0", "181.0", "182.0", "183.0", "184.0", "185.0", "186.0", "187.0", "188.0", "189.0", "190.0", "191.0", "192.0", "193.0", "194.0", "195.0", "196.0", "197.0", "198.0", "199.0", "200.0" ], "_view_name": "SelectionRangeSliderView", "description": "mx:", "index": [ 0, 199 ], "layout": "IPY_MODEL_573e6a2895704302bc43e8e819f532fa", "style": "IPY_MODEL_f805af2e0bc64dd0ae892410be049522" } }, "3bfd46a8e5b14034b02f1eaca5ade8ae": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "435594b3eb794ddfb4e243cf0e24a328": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "SelectionRangeSliderModel", "state": { "_model_name": "SelectionRangeSliderModel", "_options_labels": [ "1.0", "2.0", "3.0", "4.0", "5.0", "6.0", "7.0", "8.0", "9.0", "10.0", "11.0", "12.0", "13.0", "14.0", "15.0", "16.0", "17.0", "18.0", "19.0", "20.0", "21.0", "22.0", "23.0", "24.0", "25.0", "26.0", "27.0", "28.0", "29.0", "30.0", "31.0", "32.0", "33.0", "34.0", "35.0", "36.0", "37.0", "38.0", "39.0", "40.0", "41.0", "42.0", "43.0", "44.0", "45.0", "46.0", "47.0", "48.0", "49.0", "50.0", "51.0", "52.0", "53.0", "54.0", "55.0", "56.0", "57.0", "58.0", "59.0", "60.0", "61.0", "62.0", "63.0", "64.0", "65.0", "66.0", "67.0", "68.0", "69.0", "70.0", "71.0", "72.0", "73.0", "74.0", "75.0", "76.0", "77.0", "78.0", "79.0", "80.0", "81.0", "82.0", "83.0", "84.0", "85.0", "86.0", "87.0", "88.0", "89.0", "90.0", "91.0", "92.0", "93.0", "94.0", "95.0", "96.0", "97.0", "98.0", "99.0", "100.0", "101.0", "102.0", "103.0", "104.0", "105.0", "106.0", "107.0", "108.0", "109.0", "110.0", "111.0", "112.0", "113.0", "114.0", "115.0", "116.0", "117.0", "118.0", "119.0", "120.0", "121.0", "122.0", "123.0", "124.0", "125.0", "126.0", "127.0", "128.0", "129.0", "130.0", "131.0", "132.0", "133.0", "134.0", "135.0", "136.0", "137.0", "138.0", "139.0", "140.0", "141.0", "142.0", "143.0", "144.0", "145.0", "146.0", "147.0", "148.0", "149.0", "150.0", "151.0", "152.0", "153.0", "154.0", "155.0", "156.0", "157.0", "158.0", "159.0", "160.0", "161.0", "162.0", "163.0", "164.0", "165.0", "166.0", "167.0", "168.0", "169.0", "170.0", "171.0", "172.0", "173.0", "174.0", "175.0", "176.0", "177.0", "178.0", "179.0", "180.0", "181.0", "182.0", "183.0", "184.0", "185.0", "186.0", "187.0", "188.0", "189.0", "190.0", "191.0", "192.0", "193.0", "194.0", "195.0", "196.0", "197.0", "198.0", "199.0", "200.0" ], "_view_name": "SelectionRangeSliderView", "description": "t (ps):", "index": [ 0, 199 ], "layout": "IPY_MODEL_0d5d38481b35460293fb9e6ab964b412", "style": "IPY_MODEL_3bfd46a8e5b14034b02f1eaca5ade8ae" } }, "55f5c0fdd22e466c9ade31ed1288d282": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "SelectMultipleModel", "state": { "_options_labels": [ "E", "E_calc_count", "max_dmdt", "dE/dt", "delta_E", "average_u", "E_exchange", "max_spin_ang_exchange", "stage_max_spin_ang_exchange", "run_max_spin_ang_exchange", "E_dmi", "E_uniaxialanisotropy", "iteration", "stage_iteration", "stage", "mx", "my", "mz", "last_time_step" ], "description": "y-axis:", "index": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ], "layout": "IPY_MODEL_b7ebba4284b44f32a75add2fe9b39ed4", "rows": 5, "style": "IPY_MODEL_1634f122f215430686e46d883105b98e" } }, "573e6a2895704302bc43e8e819f532fa": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "a6c2503473e64430993d575e2147a86f": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "b7ebba4284b44f32a75add2fe9b39ed4": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "c3b46aaa299540128d5a3faf4c181859": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "eca5eef8fc844a82ad7e135b1de3f4f7": { "model_module": "@jupyter-widgets/base", "model_module_version": "1.2.0", "model_name": "LayoutModel", "state": {} }, "f19c3ba55f31463faf8b5a59548873da": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "f5238305712947f2b53220d13fb69b64": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } }, "f805af2e0bc64dd0ae892410be049522": { "model_module": "@jupyter-widgets/controls", "model_module_version": "1.5.0", "model_name": "DescriptionStyleModel", "state": { "description_width": "" } } }, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }