|
23 | 23 | "metadata": {},
|
24 | 24 | "outputs": [],
|
25 | 25 | "source": [
|
26 |
| - "sc = Sidecar(title='Sidecar Output')\n", |
| 26 | + "from bokeh.io import push_notebook, show, output_notebook\n", |
| 27 | + "from bokeh.resources import INLINE\n", |
| 28 | + "from bokeh.layouts import row\n", |
| 29 | + "from bokeh.plotting import figure\n", |
| 30 | + "output_notebook(resources=INLINE)\n", |
| 31 | + "opts = dict(plot_width=250, plot_height=250, min_border=0)" |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "cell_type": "code", |
| 36 | + "execution_count": null, |
| 37 | + "metadata": {}, |
| 38 | + "outputs": [], |
| 39 | + "source": [ |
| 40 | + "p1 = figure(**opts)\n", |
| 41 | + "r1 = p1.circle([1,2,3], [4,5,6], size=20)\n", |
| 42 | + "\n", |
| 43 | + "p2 = figure(**opts)\n", |
| 44 | + "r2 = p2.circle([1,2,3], [4,5,6], size=20)" |
| 45 | + ] |
| 46 | + }, |
| 47 | + { |
| 48 | + "cell_type": "code", |
| 49 | + "execution_count": null, |
| 50 | + "metadata": {}, |
| 51 | + "outputs": [], |
| 52 | + "source": [ |
| 53 | + "sr = Sidecar(title='Main Sidecar')\n", |
| 54 | + "with sr:\n", |
| 55 | + " # get a handle to update the shown cell with\n", |
| 56 | + " t = show(row(p1, p2), notebook_handle=True)" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "code", |
| 61 | + "execution_count": null, |
| 62 | + "metadata": {}, |
| 63 | + "outputs": [], |
| 64 | + "source": [ |
| 65 | + "r1.glyph.fill_color = \"white\"\n", |
| 66 | + "push_notebook(handle=t)" |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + "cell_type": "code", |
| 71 | + "execution_count": null, |
| 72 | + "metadata": {}, |
| 73 | + "outputs": [], |
| 74 | + "source": [ |
| 75 | + "sc = Sidecar(title='Right Sidecar', anchor='right')\n", |
27 | 76 | "sl = IntSlider(description='Some slider')\n",
|
28 | 77 | "with sc:\n",
|
29 | 78 | " display(sl)"
|
|
34 | 83 | "execution_count": null,
|
35 | 84 | "metadata": {},
|
36 | 85 | "outputs": [],
|
37 |
| - "source": [] |
| 86 | + "source": [ |
| 87 | + "import plotly\n", |
| 88 | + "import plotly.graph_objs as go\n", |
| 89 | + "import plotly.tools as tls\n", |
| 90 | + "from IPython.display import display\n", |
| 91 | + "\n", |
| 92 | + "import pandas as pd\n", |
| 93 | + "# dataset = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/diabetes.csv')\n", |
| 94 | + "dataset = pd.read_csv('diabetes.csv')\n", |
| 95 | + "\n", |
| 96 | + "subplot = tls.make_subplots(2, 2, print_grid=False)\n", |
| 97 | + "f2 = go.FigureWidget(subplot)\n", |
| 98 | + "\n", |
| 99 | + "sl = Sidecar(title='Main Sidecar')\n", |
| 100 | + "with sl:\n", |
| 101 | + " display(f2)" |
| 102 | + ] |
| 103 | + }, |
| 104 | + { |
| 105 | + "cell_type": "code", |
| 106 | + "execution_count": null, |
| 107 | + "metadata": {}, |
| 108 | + "outputs": [], |
| 109 | + "source": [ |
| 110 | + "# Use add_trace method with optional row/col parameters\n", |
| 111 | + "f2.add_trace(go.Scatter(x=dataset['Age'], y=dataset['Pregnancies'], mode='markers'), row=1, col=1)\n", |
| 112 | + "\n", |
| 113 | + "# Use add_traces with optional rows/cols parameters\n", |
| 114 | + "f2.add_traces([\n", |
| 115 | + " go.Scatter(x=dataset['Age'], y=dataset['BMI'], mode='markers'),\n", |
| 116 | + " go.Scatter(x=dataset['Age'], y=dataset['SkinThickness'], mode='markers')],\n", |
| 117 | + " rows=[1, 2], cols=[2, 1]\n", |
| 118 | + ")\n", |
| 119 | + "\n", |
| 120 | + "# Use add_scatter with optional row/col parameters\n", |
| 121 | + "f2.add_scatter(x=dataset['Age'], y=dataset['BloodPressure'], mode='markers', row=2, col=2)\n", |
| 122 | + "\n", |
| 123 | + "f2.layout.title = 'Age and Diabetes Factors'" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "code", |
| 128 | + "execution_count": null, |
| 129 | + "metadata": {}, |
| 130 | + "outputs": [], |
| 131 | + "source": [ |
| 132 | + "import numpy as np\n", |
| 133 | + "data = [dict(\n", |
| 134 | + " visible = False,\n", |
| 135 | + " line=dict(color='#00CED1', width=6),\n", |
| 136 | + " name = '𝜈 = '+str(step),\n", |
| 137 | + " x = np.arange(0,10,0.01),\n", |
| 138 | + " y = np.sin(step*np.arange(0,10,0.01))) for step in np.arange(0,5,0.1)]\n", |
| 139 | + "data[10]['visible'] = True\n", |
| 140 | + "\n", |
| 141 | + "steps = []\n", |
| 142 | + "for i in range(len(data)):\n", |
| 143 | + " step = dict(\n", |
| 144 | + " method = 'restyle', \n", |
| 145 | + " args = ['visible', [False] * len(data)],\n", |
| 146 | + " )\n", |
| 147 | + " step['args'][1][i] = True # Toggle i'th trace to \"visible\"\n", |
| 148 | + " steps.append(step)\n", |
| 149 | + "\n", |
| 150 | + "sliders = [dict(\n", |
| 151 | + " active = 10,\n", |
| 152 | + " currentvalue = {\"prefix\": \"Frequency: \"},\n", |
| 153 | + " pad = {\"t\": 50},\n", |
| 154 | + " steps = steps\n", |
| 155 | + ")]\n", |
| 156 | + "\n", |
| 157 | + "layout = dict(sliders=sliders)\n", |
| 158 | + "\n", |
| 159 | + "go.FigureWidget(data, layout)" |
| 160 | + ] |
38 | 161 | }
|
39 | 162 | ],
|
40 | 163 | "metadata": {
|
41 | 164 | "kernelspec": {
|
42 |
| - "display_name": "Python 3", |
| 165 | + "display_name": "Python [default]", |
43 | 166 | "language": "python",
|
44 | 167 | "name": "python3"
|
45 | 168 | },
|
|
53 | 176 | "name": "python",
|
54 | 177 | "nbconvert_exporter": "python",
|
55 | 178 | "pygments_lexer": "ipython3",
|
56 |
| - "version": "3.6.4" |
| 179 | + "version": "3.6.5" |
57 | 180 | }
|
58 | 181 | },
|
59 | 182 | "nbformat": 4,
|
|
0 commit comments