Skip to content

Commit 330d0e0

Browse files
committed
python range slider doc
1 parent 42d2fb6 commit 330d0e0

File tree

2 files changed

+437
-0
lines changed

2 files changed

+437
-0
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
---
2+
permalink: python/range-slider
3+
description: Create graphs with range sliders and range selectors in Python with Plotly.
4+
title: Python Range Slider and Selectors | plotly
5+
has_thumbnail: true
6+
thumbnail: /images/range.png
7+
layout: user-guide
8+
name: Range Slider and Selector
9+
language: python
10+
display_as: chart_type
11+
has_thumbnail: true
12+
page_type: example_index
13+
order: 4
14+
---
15+
{% raw %}
16+
<div class="cell border-box-sizing text_cell rendered">
17+
<div class="prompt input_prompt">
18+
</div>
19+
<div class="inner_cell">
20+
<div class="text_cell_render border-box-sizing rendered_html">
21+
<h1 id="Range-Sliders-and-Selectors-in-Python">Range Sliders and Selectors in Python<a class="anchor-link" href="#Range-Sliders-and-Selectors-in-Python">&#182;</a></h1>
22+
</div>
23+
</div>
24+
</div>
25+
<div class="cell border-box-sizing text_cell rendered">
26+
<div class="prompt input_prompt">
27+
</div>
28+
<div class="inner_cell">
29+
<div class="text_cell_render border-box-sizing rendered_html">
30+
<p>Now you can implement range sliders and range selectors in your Plotly graphs with python!!!<br></p>
31+
32+
</div>
33+
</div>
34+
</div>
35+
<div class="cell border-box-sizing text_cell rendered">
36+
<div class="prompt input_prompt">
37+
</div>
38+
<div class="inner_cell">
39+
<div class="text_cell_render border-box-sizing rendered_html">
40+
<p>New to our python API?<br>
41+
Learn about API authentication here: <a href="https://plot.ly/python/getting-started">https://plot.ly/python/getting-started</a> <br>
42+
Find your api_key here: <a href="https://plot.ly/settings/api">https://plot.ly/settings/api</a></p>
43+
44+
</div>
45+
</div>
46+
</div>
47+
<div class="cell border-box-sizing code_cell rendered">
48+
<div class="input">
49+
<div class="prompt input_prompt">In&nbsp;[2]:</div>
50+
<div class="inner_cell">
51+
<div class="input_area">
52+
<div class=" highlight hl-ipython2"><pre><span class="kn">import</span> <span class="nn">plotly</span>
53+
<span class="kn">import</span> <span class="nn">plotly.plotly</span> <span class="kn">as</span> <span class="nn">py</span>
54+
<span class="kn">import</span> <span class="nn">plotly.graph_objs</span> <span class="kn">as</span> <span class="nn">go</span>
55+
56+
<span class="n">plotly</span><span class="o">.</span><span class="n">__version__</span>
57+
</pre></div>
58+
59+
</div>
60+
</div>
61+
</div>
62+
63+
<div class="output_wrapper">
64+
<div class="output">
65+
66+
67+
<div class="output_area"><div class="prompt output_prompt">Out[2]:</div>
68+
69+
70+
<div class="output_text output_subarea output_execute_result">
71+
<pre>&apos;1.9.7&apos;</pre>
72+
</div>
73+
74+
</div>
75+
76+
</div>
77+
</div>
78+
79+
</div>
80+
<div class="cell border-box-sizing text_cell rendered">
81+
<div class="prompt input_prompt">
82+
</div>
83+
<div class="inner_cell">
84+
<div class="text_cell_render border-box-sizing rendered_html">
85+
<p>Note: range sliders and range selectors are available in version <b>1.9.7+</b><br>
86+
Run <code>pip install plotly --upgrade</code> to update your Plotly version</p>
87+
88+
</div>
89+
</div>
90+
</div>
91+
<div class="cell border-box-sizing text_cell rendered">
92+
<div class="prompt input_prompt">
93+
</div>
94+
<div class="inner_cell">
95+
<div class="text_cell_render border-box-sizing rendered_html">
96+
<h5 id="Import-Data">Import Data<a class="anchor-link" href="#Import-Data">&#182;</a></h5>
97+
</div>
98+
</div>
99+
</div>
100+
<div class="cell border-box-sizing code_cell rendered">
101+
<div class="input">
102+
<div class="prompt input_prompt">In&nbsp;[4]:</div>
103+
<div class="inner_cell">
104+
<div class="input_area">
105+
<div class=" highlight hl-ipython2"><pre><span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>
106+
<span class="kn">import</span> <span class="nn">pandas.io.data</span> <span class="kn">as</span> <span class="nn">web</span>
107+
108+
<span class="n">df</span> <span class="o">=</span> <span class="n">web</span><span class="o">.</span><span class="n">DataReader</span><span class="p">(</span><span class="s">&quot;aapl&quot;</span><span class="p">,</span> <span class="s">&#39;yahoo&#39;</span><span class="p">,</span>
109+
<span class="n">datetime</span><span class="p">(</span><span class="mi">2007</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span>
110+
<span class="n">datetime</span><span class="p">(</span><span class="mi">2009</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
111+
</pre></div>
112+
113+
</div>
114+
</div>
115+
</div>
116+
117+
</div>
118+
<div class="cell border-box-sizing text_cell rendered">
119+
<div class="prompt input_prompt">
120+
</div>
121+
<div class="inner_cell">
122+
<div class="text_cell_render border-box-sizing rendered_html">
123+
<h5 id="Create-a-Graph-with-Range-Selectors-and-a-Range-Slider">Create a Graph with Range Selectors and a Range Slider<a class="anchor-link" href="#Create-a-Graph-with-Range-Selectors-and-a-Range-Slider">&#182;</a></h5>
124+
</div>
125+
</div>
126+
</div>
127+
<div class="cell border-box-sizing code_cell rendered">
128+
<div class="input">
129+
<div class="prompt input_prompt">In&nbsp;[5]:</div>
130+
<div class="inner_cell">
131+
<div class="input_area">
132+
<div class=" highlight hl-ipython2"><pre><span class="n">trace</span> <span class="o">=</span> <span class="n">go</span><span class="o">.</span><span class="n">Scatter</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">df</span><span class="o">.</span><span class="n">index</span><span class="p">,</span>
133+
<span class="n">y</span><span class="o">=</span><span class="n">df</span><span class="o">.</span><span class="n">High</span><span class="p">)</span>
134+
135+
<span class="n">data</span> <span class="o">=</span> <span class="p">[</span><span class="n">trace</span><span class="p">]</span>
136+
137+
<span class="n">layout</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span>
138+
<span class="n">title</span><span class="o">=</span><span class="s">&#39;Time series with range slider and selectors&#39;</span><span class="p">,</span>
139+
<span class="n">xaxis</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span>
140+
<span class="n">rangeselector</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span>
141+
<span class="n">buttons</span><span class="o">=</span><span class="nb">list</span><span class="p">([</span>
142+
<span class="nb">dict</span><span class="p">(</span><span class="n">count</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
143+
<span class="n">label</span><span class="o">=</span><span class="s">&#39;1m&#39;</span><span class="p">,</span>
144+
<span class="n">step</span><span class="o">=</span><span class="s">&#39;month&#39;</span><span class="p">,</span>
145+
<span class="n">stepmode</span><span class="o">=</span><span class="s">&#39;backward&#39;</span><span class="p">),</span>
146+
<span class="nb">dict</span><span class="p">(</span><span class="n">count</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span>
147+
<span class="n">label</span><span class="o">=</span><span class="s">&#39;6m&#39;</span><span class="p">,</span>
148+
<span class="n">step</span><span class="o">=</span><span class="s">&#39;month&#39;</span><span class="p">,</span>
149+
<span class="n">stepmode</span><span class="o">=</span><span class="s">&#39;backward&#39;</span><span class="p">),</span>
150+
<span class="nb">dict</span><span class="p">(</span><span class="n">count</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
151+
<span class="n">label</span><span class="o">=</span><span class="s">&#39;YTD&#39;</span><span class="p">,</span>
152+
<span class="n">step</span><span class="o">=</span><span class="s">&#39;year&#39;</span><span class="p">,</span>
153+
<span class="n">stepmode</span><span class="o">=</span><span class="s">&#39;todate&#39;</span><span class="p">),</span>
154+
<span class="nb">dict</span><span class="p">(</span><span class="n">count</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
155+
<span class="n">label</span><span class="o">=</span><span class="s">&#39;1y&#39;</span><span class="p">,</span>
156+
<span class="n">step</span><span class="o">=</span><span class="s">&#39;year&#39;</span><span class="p">,</span>
157+
<span class="n">stepmode</span><span class="o">=</span><span class="s">&#39;backward&#39;</span><span class="p">),</span>
158+
<span class="nb">dict</span><span class="p">(</span><span class="n">step</span><span class="o">=</span><span class="s">&#39;all&#39;</span><span class="p">)</span>
159+
<span class="p">])</span>
160+
<span class="p">),</span>
161+
<span class="n">rangeslider</span><span class="o">=</span><span class="nb">dict</span><span class="p">(),</span>
162+
<span class="nb">type</span><span class="o">=</span><span class="s">&#39;date&#39;</span>
163+
<span class="p">)</span>
164+
<span class="p">)</span>
165+
166+
<span class="n">fig</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span> <span class="n">layout</span><span class="o">=</span><span class="n">layout</span><span class="p">)</span>
167+
<span class="n">py</span><span class="o">.</span><span class="n">iplot</span><span class="p">(</span><span class="n">fig</span><span class="p">)</span>
168+
</pre></div>
169+
170+
</div>
171+
</div>
172+
</div>
173+
174+
<div class="output_wrapper">
175+
<div class="output">
176+
177+
178+
<div class="output_area"><div class="prompt output_prompt">Out[5]:</div>
179+
180+
<div class="output_html rendered_html output_subarea output_execute_result">
181+
<iframe id="igraph" scrolling="no" style="border:none;" seamless="seamless" src="https://plot.ly/~chelsea_lyn/11483.embed" height="525px" width="100%"></iframe>
182+
</div>
183+
184+
</div>
185+
186+
</div>
187+
</div>
188+
189+
</div>{% endraw %}

0 commit comments

Comments
 (0)