Visualization (AEN 4.0)
=======================

.. raw:: html

    <div class="section" id="plotting">
    <h2>Plotting<a class="headerlink" href="#plotting" title="Permalink to this headline">¶</a></h2>
    <p>Anaconda Enterprise Notebooks&#8217;s workbench application supports two
    methods of plotting. One is plotting with Jupyter or the Jupyter
    Notebook using matplotlib. The second is Bokeh, our custom interactive
    plotting library.</p>
    </div>
    <div class="section" id="matplotlib">
    <h2>Matplotlib<a class="headerlink" href="#matplotlib" title="Permalink to this headline">¶</a></h2>
    <p><a class="reference external" href="http://matplotlib.org/">Matplotlib</a> is a Python 2D plotting library
    that produces publication-quality figures in a variety of hardcopy
    formats and interactive environments across platforms.</p>
    <p>To use matplotlib in Anaconda Enterprise Notebooks, you have two
    options. You can either open a new terminal tab with <em>Jupyter w/
    Matplotlib</em> selected...</p>
    <p>or open a New Notebook.</p>
    <p>Anaconda Enterprise Notebooks&#8217;s Jupyter Notebook comes with matplotlib
    already installed, so you don&#8217;t need to worry about installing it
    yourself or starting up Jupyter Notebook with the &#8211;pylab option.</p>
    <p>In fact, the following example should execute and create a plot with
    either of the Anaconda Enterprise Notebooks options for using
    Matplotlib.</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">x</span> <span class="o">=</span> <span class="n">linspace</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">3</span><span class="o">*</span><span class="n">pi</span><span class="p">,</span> <span class="mi">500</span><span class="p">)</span>
    <span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
    <span class="n">title</span><span class="p">(</span><span class="s1">&#39;A simple chirp&#39;</span><span class="p">);</span>
    </pre></div>
    </div>
    <p>You can find a <a class="reference external" href="http://matplotlib.org/gallery.html">gallery</a>,
    <a class="reference external" href="http://matplotlib.org/examples/index.html">examples</a>,
    <a class="reference external" href="http://matplotlib.org/contents.html">documentation</a>, and a <a class="reference external" href="http://matplotlib.org/api/pyplot_summary.html">list of
    plotting commands</a> on
    the <a class="reference external" href="http://matplotlib.org/">matplotlib website</a>.</p>
    </div>
    <div class="section" id="bokeh">
    <h2>Bokeh<a class="headerlink" href="#bokeh" title="Permalink to this headline">¶</a></h2>
    <p>In your <em>Examples</em> folder in the file browser, you&#8217;ll find a file,
    webplot.py, which has been generated for you using your Anaconda
    Enterprise Notebooks plotting API keys. Current functionality is limited
    to line plots and scatter plots. The interface is similar to matplotlib.</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">webplot</span> <span class="k">import</span> <span class="n">p</span>
    </pre></div>
    </div>
    <p>This line will import the plotting client which can plot to your web
    browser. p.plot is the main function for plotting data; it resembles the
    matplotlib.plot command:</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">p</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">y</span><span class="p">)</span>             <span class="c1"># plots y as a lineplot</span>
    <span class="n">p</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>          <span class="c1"># plots y as a line plot with respect ot x</span>
    <span class="n">p</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="s1">&#39;green&#39;</span><span class="p">)</span> <span class="c1"># using a green line</span>
    </pre></div>
    </div>
    <p>Similar to matplotlib, <em>y</em> can be a 2D array, in which case each column
    is plotted. We default to having subsequent plotting commands render to
    the last completed plot. You can create a new plot by calling p.figure.
    We also support matplotlib conventions for toggling the hold mode.</p>
    <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">p</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>          <span class="c1"># subsequent commands plot to a new plot</span>
    <span class="n">p</span><span class="o">.</span><span class="n">hold</span><span class="p">(</span><span class="s1">&#39;on&#39;</span><span class="p">)</span>        <span class="c1"># default to plotting to the current plot</span>
    <span class="n">p</span><span class="o">.</span><span class="n">hold</span><span class="p">(</span><span class="s1">&#39;off&#39;</span><span class="p">)</span>       <span class="c1"># default to plotting to new plot</span>
    <span class="n">p</span><span class="o">.</span><span class="n">hold</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>        <span class="c1"># default to plotting to the current plot</span>
    <span class="n">p</span><span class="o">.</span><span class="n">hold</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>       <span class="c1"># default to plotting to new plot</span>
    </pre></div>
    </div>
    <p>A key feature of plotting in Anaconda Enterprise Notebooks is
    interactivity. Clicking on the <em>Pan</em> and <em>Select</em> tools will allow you
    to pan and select the plot using the mouse. The mouse wheel will also
    allow you to zoom in and out. For advanced users, shift + mouse will pan
    and ctrl + mouse will select.</p>
    <p>In Anaconda Enterprise Notebooks&#8217;s plotting library, we introduce the
    notion of a data source. A data source is a collection of columns which
    are joined into records. Interactivity is much more powerful when you
    link plots to data sources. Selecting on a data source will render that
    selection in each plot or table which is viewing it.</p>
    <p><img alt="image0" src="../../../_images/ae-notebooks/4.0/user/visualization_bokeh1.png" /> <img alt="image1" src="../../../_images/ae-notebooks/4.0/user/visualization_bokeh2.png" /></p>
    <div class="highlight-default"><div class="highlight"><pre><span></span><span class="sd">&quot;&quot;&quot;</span>
    <span class="sd">Create a data source, and then 2 line plots which point at that data source.</span>
    <span class="sd">Selections will propagate across plots. Finally, create a table which views</span>
    <span class="sd">the data source</span>
    <span class="sd">&quot;&quot;&quot;</span>
    <span class="n">source</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">make_source</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="n">y</span><span class="p">,</span> <span class="n">z</span><span class="o">=</span><span class="n">z</span><span class="p">)</span>
    <span class="n">p</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="n">data_source</span><span class="o">=</span><span class="n">source</span><span class="p">)</span>
    <span class="n">p</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>
    <span class="n">p</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="s1">&#39;z&#39;</span><span class="p">,</span> <span class="n">data_source</span><span class="o">=</span><span class="n">source</span><span class="p">)</span>
    <span class="n">p</span><span class="o">.</span><span class="n">table</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="s1">&#39;z&#39;</span><span class="p">])</span>
    </pre></div>
    </div>
    <div class="section" id="other-interesting-options">
    <h3>Other interesting options<a class="headerlink" href="#other-interesting-options" title="Permalink to this headline">¶</a></h3>
    <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">p</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">300</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="mi">300</span><span class="p">)</span>
    </pre></div>
    </div>
    <p>You can pass width or height into each plot specified in pixels.
    p.scatter(x, y) p.scatter has the same syntax as p.plot, however, it
    will generate a scatter plot (which is basically the same thing, except
    without connecting the dots). p.plot_dates(x, y) p.plot_dates will
    treat the x-axis as a date axis. We currently expect dates to be
    milliseconds since the epoch.</p>
    </div>
    <div class="section" id="id2">
    <h3>Examples<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
    <p>Your Anaconda Enterprise Notebooks account comes preloaded with a number
    of examples included in the ~scripts/examples directory.</p>
    </div>
    </div>
    <div class="section" id="plots">
    <h2>Plots<a class="headerlink" href="#plots" title="Permalink to this headline">¶</a></h2>
    </div>
