{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# EXTRA STUFF: Day 8" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, import our usual things:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import ipywidgets\n", "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import bqplot.pyplot as bplt\n", "# also:\n", "import bqplot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Load data:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "planets = pd.read_csv('https://jnaiman.github.io/csci-p-14110_su2020/lesson08/planets_2020.06.22_10.10.17.csv', \n", " sep=\",\", comment=\"#\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's take a quick look:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
rowidpl_hostnamepl_letterpl_namepl_discmethodpl_controvflagpl_pnumpl_orbperpl_orbpererr1pl_orbpererr2...st_bmyst_bmyerrst_bmylimst_m1st_m1errst_m1limst_c1st_c1errst_c1limst_colorn
0111 Comb11 Com bRadial Velocity01326.0300000.320000-0.320000...NaNNaNNaNNaNNaNNaNNaNNaNNaN7.0
1211 UMib11 UMi bRadial Velocity01516.2199703.200000-3.200000...NaNNaNNaNNaNNaNNaNNaNNaNNaN5.0
2314 Andb14 And bRadial Velocity01185.8400000.230000-0.230000...NaNNaNNaNNaNNaNNaNNaNNaNNaN7.0
3414 Herb14 Her bRadial Velocity011773.4000202.500000-2.500000...0.5370.0010.00.3660.0020.00.4380.0060.09.0
4516 Cyg Bb16 Cyg B bRadial Velocity01798.5000001.000000-1.000000...0.4180.0030.00.2220.0030.00.3510.0030.017.0
..................................................................
41594160tau Gembtau Gem bRadial Velocity01305.5000000.100000-0.100000...NaNNaNNaNNaNNaNNaNNaNNaNNaN7.0
41604161ups Andbups And bRadial Velocity034.6170330.000023-0.000023...NaNNaNNaNNaNNaNNaNNaNNaNNaN8.0
41614162ups Andcups And cRadial Velocity03241.2580000.064000-0.064000...NaNNaNNaNNaNNaNNaNNaNNaNNaN8.0
41624163ups Anddups And dRadial Velocity031276.4600000.570000-0.570000...NaNNaNNaNNaNNaNNaNNaNNaNNaN8.0
41634164xi Aqlbxi Aql bRadial Velocity01136.7500000.250000-0.250000...NaNNaNNaNNaNNaNNaNNaNNaNNaN9.0
\n", "

4164 rows × 356 columns

\n", "
" ], "text/plain": [ " rowid pl_hostname pl_letter pl_name pl_discmethod \\\n", "0 1 11 Com b 11 Com b Radial Velocity \n", "1 2 11 UMi b 11 UMi b Radial Velocity \n", "2 3 14 And b 14 And b Radial Velocity \n", "3 4 14 Her b 14 Her b Radial Velocity \n", "4 5 16 Cyg B b 16 Cyg B b Radial Velocity \n", "... ... ... ... ... ... \n", "4159 4160 tau Gem b tau Gem b Radial Velocity \n", "4160 4161 ups And b ups And b Radial Velocity \n", "4161 4162 ups And c ups And c Radial Velocity \n", "4162 4163 ups And d ups And d Radial Velocity \n", "4163 4164 xi Aql b xi Aql b Radial Velocity \n", "\n", " pl_controvflag pl_pnum pl_orbper pl_orbpererr1 pl_orbpererr2 ... \\\n", "0 0 1 326.030000 0.320000 -0.320000 ... \n", "1 0 1 516.219970 3.200000 -3.200000 ... \n", "2 0 1 185.840000 0.230000 -0.230000 ... \n", "3 0 1 1773.400020 2.500000 -2.500000 ... \n", "4 0 1 798.500000 1.000000 -1.000000 ... \n", "... ... ... ... ... ... ... \n", "4159 0 1 305.500000 0.100000 -0.100000 ... \n", "4160 0 3 4.617033 0.000023 -0.000023 ... \n", "4161 0 3 241.258000 0.064000 -0.064000 ... \n", "4162 0 3 1276.460000 0.570000 -0.570000 ... \n", "4163 0 1 136.750000 0.250000 -0.250000 ... \n", "\n", " st_bmy st_bmyerr st_bmylim st_m1 st_m1err st_m1lim st_c1 \\\n", "0 NaN NaN NaN NaN NaN NaN NaN \n", "1 NaN NaN NaN NaN NaN NaN NaN \n", "2 NaN NaN NaN NaN NaN NaN NaN \n", "3 0.537 0.001 0.0 0.366 0.002 0.0 0.438 \n", "4 0.418 0.003 0.0 0.222 0.003 0.0 0.351 \n", "... ... ... ... ... ... ... ... \n", "4159 NaN NaN NaN NaN NaN NaN NaN \n", "4160 NaN NaN NaN NaN NaN NaN NaN \n", "4161 NaN NaN NaN NaN NaN NaN NaN \n", "4162 NaN NaN NaN NaN NaN NaN NaN \n", "4163 NaN NaN NaN NaN NaN NaN NaN \n", "\n", " st_c1err st_c1lim st_colorn \n", "0 NaN NaN 7.0 \n", "1 NaN NaN 5.0 \n", "2 NaN NaN 7.0 \n", "3 0.006 0.0 9.0 \n", "4 0.003 0.0 17.0 \n", "... ... ... ... \n", "4159 NaN NaN 7.0 \n", "4160 NaN NaN 8.0 \n", "4161 NaN NaN 8.0 \n", "4162 NaN NaN 8.0 \n", "4163 NaN NaN 9.0 \n", "\n", "[4164 rows x 356 columns]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "planets" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Heatmap dashboard" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's make a 2D histogram showing how the NASA planets are distributed across these 2 parameters.\n", "\n", "First, looking at the plots of the individual distributions, we can make some guesses for bins along each parameter:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "ecc = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can also do this with NumPy:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "ecc = np.arange(0.0, 1.1, step=0.1) # start, stop, step => note step+stop there!" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ])" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ecc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And semi-major axis:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "sa = np.arange(0.0, 50+5, step=5)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 0., 5., 10., 15., 20., 25., 30., 35., 40., 45., 50.])" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sa" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's also use NumPy to make a 2D histogram with these bins:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "myHist, xedges, yedges = np.histogram2d(planets['pl_orbeccen'], planets['pl_orbsmax'], \n", " bins=[ecc,sa])" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 0., 5., 10., 15., 20., 25., 30., 35., 40., 45., 50.])" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "yedges" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[596., 14., 0., 0., 0., 0., 0., 0., 0., 0.],\n", " [261., 6., 1., 1., 0., 0., 0., 0., 0., 0.],\n", " [158., 6., 2., 0., 0., 0., 0., 0., 0., 0.],\n", " [ 80., 5., 1., 0., 0., 0., 0., 0., 0., 0.],\n", " [ 49., 2., 2., 1., 0., 0., 0., 0., 0., 0.],\n", " [ 43., 4., 0., 0., 0., 0., 0., 0., 0., 0.],\n", " [ 20., 2., 0., 0., 0., 0., 0., 0., 0., 0.],\n", " [ 15., 4., 0., 0., 1., 0., 0., 0., 0., 0.],\n", " [ 9., 2., 0., 1., 0., 0., 0., 0., 0., 0.],\n", " [ 3., 0., 0., 0., 0., 0., 0., 0., 0., 0.]])" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "myHist" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We see that we mostly have entries between 0-25 AU, so we can update our binning:" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "sa = np.arange(0.0, 24+4, step=4)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "myHist, xedges, yedges = np.histogram2d(planets['pl_orbeccen'], planets['pl_orbsmax'], \n", " bins=[ecc,sa])" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 0., 4., 8., 12., 16., 20., 24.])" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "yedges" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[592., 16., 2., 0., 0., 0.],\n", " [257., 10., 1., 0., 1., 0.],\n", " [154., 8., 4., 0., 0., 0.],\n", " [ 78., 6., 1., 1., 0., 0.],\n", " [ 46., 4., 2., 1., 1., 0.],\n", " [ 38., 9., 0., 0., 0., 0.],\n", " [ 17., 5., 0., 0., 0., 0.],\n", " [ 14., 5., 0., 0., 0., 1.],\n", " [ 9., 2., 0., 0., 1., 0.],\n", " [ 3., 0., 0., 0., 0., 0.]])" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "myHist" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "xedges & yedges give the bin *edges* but we want the centers:" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "xcenter = (xedges[:-1] + xedges[1:]) / 2\n", "ycenter = (yedges[:-1] + yedges[1:]) / 2" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "myLabel = ipywidgets.Label()# make label" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Function to print out data values:" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "def get_data_value(change): # redefine this function to now use myHist, not data\n", " i,j = change['owner'].selected[0]\n", " v = myHist[i,j] # grab data value\n", " myLabel.value = 'Value of data = ' + str(v) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Put all together:" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "8bccf96c9cf549fbaae6cb520feb55c4", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(Label(value=''), Figure(axes=[ColorAxis(scale=ColorScale()), Axis(scale=LinearScale()), Axis(or…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = bplt.figure(padding_y=0.0) # set up a figure object\n", "\n", "# use bqplot's plt interface to plot:\n", "heat_map = bplt.gridheatmap(myHist, row=xcenter, column=ycenter, interactions={'click':'select'})\n", "\n", "# hook heat_maps selected value to the label \n", "heat_map.observe(get_data_value, 'selected')\n", "\n", "# show both the fig and label in a vertical box\n", "ipywidgets.VBox([myLabel,fig])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can change the color scale as well:" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "305bbefabd364d62b3efd514735b839f", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(Label(value=''), Figure(axes=[ColorAxis(scale=ColorScale(scheme='Reds')), Axis(scale=LinearScal…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = bplt.figure(padding_y=0.0) # set up a figure object\n", "\n", "# add in color:\n", "col_sc = bqplot.ColorScale(scheme='Reds') \n", "\n", "# use bqplot's plt interface to plot:\n", "heat_map = bplt.gridheatmap(myHist, row=xcenter, column=ycenter, interactions={'click':'select'},\n", " scales={'color':col_sc})\n", "\n", "# hook heat_maps selected value to the label \n", "heat_map.observe(get_data_value, 'selected')\n", "\n", "# show both the fig and label in a vertical box\n", "ipywidgets.VBox([myLabel,fig])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "However, doing things like adding in x/y labels is somewhat familiar, but we call fig.axes instead of ax[#] to set axis labels. You can check out what fig.axes[0], fig.axes[1], fig.axes[2] is by:" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[ColorAxis(scale=ColorScale(scheme='Reds')),\n", " Axis(scale=LinearScale(), side='bottom'),\n", " Axis(orientation='vertical', scale=LinearScale(), side='left')]" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fig.axes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So, it looks like the 0th axes is color, the 1th one is the horizontal axis and the 2th is the vertical axes. We can change x/y labels as follows:" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "59e82053ba2142f2b3ab0e2b1c4579a9", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(Label(value=''), Figure(axes=[ColorAxis(scale=ColorScale(scheme='Reds'), side='top'), Axis(labe…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig = bplt.figure(padding_y=0.0) # set up a figure object\n", "bplt.scales(scales={'color':bqplot.ColorScale(scheme='Reds')})\n", "\n", "# use bqplot's plt interface to plot:\n", "heat_map = bplt.gridheatmap(myHist, row=xcenter, column=ycenter, interactions={'click':'select'})\n", "\n", "# hook heat_maps selected value to the label \n", "heat_map.observe(get_data_value, 'selected')\n", "\n", "# change labels\n", "fig.axes[0].side = 'top' # so it doesn't overlap with scale\n", "fig.axes[1].label = 'semi-major axes in AU' # xaxes label\n", "fig.axes[2].label = 'eccentricity' # yaxes label\n", "\n", "# show both the fig and label in a vertical box\n", "ipywidgets.VBox([myLabel,fig])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's generate our line plot -- this will use the $r(\\theta)$ equation to plot orbits:" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "86c0dcee66954313810d3e34c0d33d61", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Figure(axes=[Axis(label='x in AU', scale=LinearScale()), Axis(label='y in AU', orientation='vertical', scale=L…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig_lines = bplt.figure(padding_y=0.0) # set up a figure object\n", "\n", "# use bqplot's plt interface to plot:\n", "lines = bplt.plot([],[]) # empty to start\n", "\n", "# change labels\n", "fig_lines.axes[0].label = 'x in AU' # xaxes label\n", "fig_lines.axes[1].label = 'y in AU' # yaxes label\n", "\n", "fig_lines # empty plot of x/y" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, lets first put all of our plots in the alighment we want, keeping in mind that the x/y plot of the analytical trajectory won't be updated when we click anything yet:" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "99f84a4148d3498d87fc4349eeb782bf", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(Label(value=''), HBox(children=(Figure(axes=[ColorAxis(scale=ColorScale(scheme='Reds'), side='t…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "ipywidgets.VBox([myLabel,ipywidgets.HBox([fig,fig_lines])])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Oh but it looks squished, lets try messing with the layout:" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "75671422ba664c2987d66c46bda2001c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(Label(value=''), HBox(children=(Figure(axes=[ColorAxis(scale=ColorScale(scheme='Reds'), side='t…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig.layout.min_width='500px'\n", "fig_lines.layout.min_width='500px'\n", "ipywidgets.VBox([myLabel,ipywidgets.HBox([fig,fig_lines])])\n", "\n", "#figOut = ipywidgets.VBox([myLabel,ipywidgets.HBox([fig,fig_lines])])\n", "#figOut.layout.min_width='1000px'\n", "#figOut" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To make this interactive first we need to update our `get_data_value` function to *also* update our lines plot when the heatmap plot is selected:" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "theta = np.arange(0, 2*np.pi, 0.001) # theta array\n", "\n", "def get_data_value(change): # redefine this function to now use myHist, not data\n", " # 1. Update the label\n", " i,j = change['owner'].selected[0]\n", " v = myHist[i,j] # grab data value\n", " myLabel.value = 'Value of data = ' + str(v) \n", " # 2. Update the x/y values in our lines plot\n", " a = ycenter[j] # semi major axis based on bins in heatmap\n", " ecc = xcenter[i] # eccentricity for bins on heatmap\n", " r = a*(1-ecc**2)/(1+ecc*np.cos(theta)) # calculate r(theta)\n", " x = r*np.cos(theta) # translate into x/y\n", " y = r*np.sin(theta)\n", " lines.x = x\n", " lines.y = y" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally before we plot, we have to re-hook this back into our heatmap figure:" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "heat_map.observe(get_data_value, 'selected')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now use the orientation of our plots we had above to re-plot with new interactivity:" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "8b8bc530ed8f44cebcaa5e2608d7b448", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(Label(value=''), HBox(children=(Figure(axes=[ColorAxis(scale=ColorScale(scheme='Reds'), side='t…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "ipywidgets.VBox([myLabel,ipywidgets.HBox([fig,fig_lines])])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we want to keep the x/y range static when we plot, we can re-do our trajectory plot with:" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b4be4b1611364f9185459070bc2f24c9", "version_major": 2, "version_minor": 0 }, "text/plain": [ "Figure(axes=[Axis(label='x in AU', scale=LinearScale(max=30.0, min=-30.0)), Axis(label='y in AU', orientation=…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig_lines = bplt.figure(padding_y=0.0) # set up a figure object\n", "\n", "# use bqplot's plt interface to plot:\n", "lines = bplt.plot([],[]) # empty to start\n", "\n", "# set x/y lim in the bqplot way\n", "bplt.set_lim(-30,30,'x')\n", "bplt.set_lim(-30,30, 'y')\n", "\n", "# change labels\n", "fig_lines.axes[0].label = 'x in AU' # xaxes label\n", "fig_lines.axes[1].label = 'y in AU' # yaxes label\n", "\n", "# to be sure:\n", "fig_lines.layout.min_width='500px'\n", "\n", "\n", "fig_lines # empty plot of x/y" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And finally put it all together:" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "fbddebe0d36d449bb31a7fa90a087c01", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(Label(value=''), HBox(children=(Figure(axes=[ColorAxis(scale=ColorScale(scheme='Reds'), side='t…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "ipywidgets.VBox([myLabel,ipywidgets.HBox([fig,fig_lines])])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "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.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }