piccolbo/altair_recipes

View on GitHub
docs/test_barchart.html

Summary

Maintainability
Test Coverage

<div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">altair_recipes</span> <span class="k">as</span> <span class="nn">ar</span>
<span class="kn">from</span> <span class="nn">altair_recipes.common</span> <span class="kn">import</span> <span class="n">viz_reg_test</span>
<span class="kn">from</span> <span class="nn">altair_recipes.display_pweave</span> <span class="kn">import</span> <span class="n">show_test</span>
<span class="kn">from</span> <span class="nn">vega_datasets</span> <span class="kn">import</span> <span class="n">data</span>
</pre></div>

<h2>Barchart</h2>




<div class="highlight"><pre><span></span><span class="nd">@viz_reg_test</span>
<span class="k">def</span> <span class="nf">test_barchart_color</span><span class="p">():</span>
    <span class="n">source</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">barley</span><span class="p">()</span>
    <span class="k">return</span> <span class="n">ar</span><span class="o">.</span><span class="n">barchart</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="s2">&quot;year&quot;</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="s2">&quot;mean(yield)&quot;</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>


<span class="n">show_test</span><span class="p">(</span><span class="n">test_barchart_color</span><span class="p">)</span>
</pre></div>

<div class="highlight"><pre>
/Users/antonio/Library/Caches/pypoetry/virtualenvs/altair-recipes-
WhUvyqF4-py3.9/lib/python3.9/site-
packages/ipykernel/kernelbase.py:684: RuntimeWarning: coroutine
&#39;InProcessKernel._abort_queues&#39; was never awaited
  self._abort_queues()
RuntimeWarning: Enable tracemalloc to get the object allocation
traceback
</pre></div>


<script src="https://cdn.jsdelivr.net/npm/vega@3"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@2"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@3"></script>
 <div id="Aa5355e9698a3f021c77e010d205e9b089432794316023c0ea3272f6513d489a6"></div>
  <script type="text/javascript">
    var spec = {
  "$schema": "https://vega.github.io/schema/vega-lite/v4.17.0.json",
  "config": {
    "view": {
      "continuousHeight": 300,
      "continuousWidth": 400
    }
  },
  "data": {
    "name": "data-093ece8c35bb2d41094cfb6138ec810b"
  },
  "datasets": {
    "data-093ece8c35bb2d41094cfb6138ec810b": [
      {
        "site": "University Farm",
        "variety": "Manchuria",
        "year": 1931,
        "yield": 27.0
      },
      {
        "site": "Waseca",
        "variety": "Manchuria",
        "year": 1931,
        "yield": 48.86667
      },
      {
        "site": "Morris",
        "variety": "Manchuria",
        "year": 1931,
        "yield": 27.43334
      },
      {
        "site": "Crookston",
        "variety": "Manchuria",
        "year": 1931,
        "yield": 39.93333
      },
      {
        "site": "Grand Rapids",
        "variety": "Manchuria",
        "year": 1931,
        "yield": 32.96667
      },
      {
        "site": "Duluth",
        "variety": "Manchuria",
        "year": 1931,
        "yield": 28.96667
      },
      {
        "site": "University Farm",
        "variety": "Glabron",
        "year": 1931,
        "yield": 43.06666
      },
      {
        "site": "Waseca",
        "variety": "Glabron",
        "year": 1931,
        "yield": 55.2
      },
      {
        "site": "Morris",
        "variety": "Glabron",
        "year": 1931,
        "yield": 28.76667
      },
      {
        "site": "Crookston",
        "variety": "Glabron",
        "year": 1931,
        "yield": 38.13333
      },
      {
        "site": "Grand Rapids",
        "variety": "Glabron",
        "year": 1931,
        "yield": 29.13333
      },
      {
        "site": "Duluth",
        "variety": "Glabron",
        "year": 1931,
        "yield": 29.66667
      },
      {
        "site": "University Farm",
        "variety": "Svansota",
        "year": 1931,
        "yield": 35.13333
      },
      {
        "site": "Waseca",
        "variety": "Svansota",
        "year": 1931,
        "yield": 47.33333
      },
      {
        "site": "Morris",
        "variety": "Svansota",
        "year": 1931,
        "yield": 25.76667
      },
      {
        "site": "Crookston",
        "variety": "Svansota",
        "year": 1931,
        "yield": 40.46667
      },
      {
        "site": "Grand Rapids",
        "variety": "Svansota",
        "year": 1931,
        "yield": 29.66667
      },
      {
        "site": "Duluth",
        "variety": "Svansota",
        "year": 1931,
        "yield": 25.7
      },
      {
        "site": "University Farm",
        "variety": "Velvet",
        "year": 1931,
        "yield": 39.9
      },
      {
        "site": "Waseca",
        "variety": "Velvet",
        "year": 1931,
        "yield": 50.23333
      },
      {
        "site": "Morris",
        "variety": "Velvet",
        "year": 1931,
        "yield": 26.13333
      },
      {
        "site": "Crookston",
        "variety": "Velvet",
        "year": 1931,
        "yield": 41.33333
      },
      {
        "site": "Grand Rapids",
        "variety": "Velvet",
        "year": 1931,
        "yield": 23.03333
      },
      {
        "site": "Duluth",
        "variety": "Velvet",
        "year": 1931,
        "yield": 26.3
      },
      {
        "site": "University Farm",
        "variety": "Trebi",
        "year": 1931,
        "yield": 36.56666
      },
      {
        "site": "Waseca",
        "variety": "Trebi",
        "year": 1931,
        "yield": 63.8333
      },
      {
        "site": "Morris",
        "variety": "Trebi",
        "year": 1931,
        "yield": 43.76667
      },
      {
        "site": "Crookston",
        "variety": "Trebi",
        "year": 1931,
        "yield": 46.93333
      },
      {
        "site": "Grand Rapids",
        "variety": "Trebi",
        "year": 1931,
        "yield": 29.76667
      },
      {
        "site": "Duluth",
        "variety": "Trebi",
        "year": 1931,
        "yield": 33.93333
      },
      {
        "site": "University Farm",
        "variety": "No. 457",
        "year": 1931,
        "yield": 43.26667
      },
      {
        "site": "Waseca",
        "variety": "No. 457",
        "year": 1931,
        "yield": 58.1
      },
      {
        "site": "Morris",
        "variety": "No. 457",
        "year": 1931,
        "yield": 28.7
      },
      {
        "site": "Crookston",
        "variety": "No. 457",
        "year": 1931,
        "yield": 45.66667
      },
      {
        "site": "Grand Rapids",
        "variety": "No. 457",
        "year": 1931,
        "yield": 32.16667
      },
      {
        "site": "Duluth",
        "variety": "No. 457",
        "year": 1931,
        "yield": 33.6
      },
      {
        "site": "University Farm",
        "variety": "No. 462",
        "year": 1931,
        "yield": 36.6
      },
      {
        "site": "Waseca",
        "variety": "No. 462",
        "year": 1931,
        "yield": 65.7667
      },
      {
        "site": "Morris",
        "variety": "No. 462",
        "year": 1931,
        "yield": 30.36667
      },
      {
        "site": "Crookston",
        "variety": "No. 462",
        "year": 1931,
        "yield": 48.56666
      },
      {
        "site": "Grand Rapids",
        "variety": "No. 462",
        "year": 1931,
        "yield": 24.93334
      },
      {
        "site": "Duluth",
        "variety": "No. 462",
        "year": 1931,
        "yield": 28.1
      },
      {
        "site": "University Farm",
        "variety": "Peatland",
        "year": 1931,
        "yield": 32.76667
      },
      {
        "site": "Waseca",
        "variety": "Peatland",
        "year": 1931,
        "yield": 48.56666
      },
      {
        "site": "Morris",
        "variety": "Peatland",
        "year": 1931,
        "yield": 29.86667
      },
      {
        "site": "Crookston",
        "variety": "Peatland",
        "year": 1931,
        "yield": 41.6
      },
      {
        "site": "Grand Rapids",
        "variety": "Peatland",
        "year": 1931,
        "yield": 34.7
      },
      {
        "site": "Duluth",
        "variety": "Peatland",
        "year": 1931,
        "yield": 32.0
      },
      {
        "site": "University Farm",
        "variety": "No. 475",
        "year": 1931,
        "yield": 24.66667
      },
      {
        "site": "Waseca",
        "variety": "No. 475",
        "year": 1931,
        "yield": 46.76667
      },
      {
        "site": "Morris",
        "variety": "No. 475",
        "year": 1931,
        "yield": 22.6
      },
      {
        "site": "Crookston",
        "variety": "No. 475",
        "year": 1931,
        "yield": 44.1
      },
      {
        "site": "Grand Rapids",
        "variety": "No. 475",
        "year": 1931,
        "yield": 19.7
      },
      {
        "site": "Duluth",
        "variety": "No. 475",
        "year": 1931,
        "yield": 33.06666
      },
      {
        "site": "University Farm",
        "variety": "Wisconsin No. 38",
        "year": 1931,
        "yield": 39.3
      },
      {
        "site": "Waseca",
        "variety": "Wisconsin No. 38",
        "year": 1931,
        "yield": 58.8
      },
      {
        "site": "Morris",
        "variety": "Wisconsin No. 38",
        "year": 1931,
        "yield": 29.46667
      },
      {
        "site": "Crookston",
        "variety": "Wisconsin No. 38",
        "year": 1931,
        "yield": 49.86667
      },
      {
        "site": "Grand Rapids",
        "variety": "Wisconsin No. 38",
        "year": 1931,
        "yield": 34.46667
      },
      {
        "site": "Duluth",
        "variety": "Wisconsin No. 38",
        "year": 1931,
        "yield": 31.6
      },
      {
        "site": "University Farm",
        "variety": "Manchuria",
        "year": 1932,
        "yield": 26.9
      },
      {
        "site": "Waseca",
        "variety": "Manchuria",
        "year": 1932,
        "yield": 33.46667
      },
      {
        "site": "Morris",
        "variety": "Manchuria",
        "year": 1932,
        "yield": 34.36666
      },
      {
        "site": "Crookston",
        "variety": "Manchuria",
        "year": 1932,
        "yield": 32.96667
      },
      {
        "site": "Grand Rapids",
        "variety": "Manchuria",
        "year": 1932,
        "yield": 22.13333
      },
      {
        "site": "Duluth",
        "variety": "Manchuria",
        "year": 1932,
        "yield": 22.56667
      },
      {
        "site": "University Farm",
        "variety": "Glabron",
        "year": 1932,
        "yield": 36.8
      },
      {
        "site": "Waseca",
        "variety": "Glabron",
        "year": 1932,
        "yield": 37.73333
      },
      {
        "site": "Morris",
        "variety": "Glabron",
        "year": 1932,
        "yield": 35.13333
      },
      {
        "site": "Crookston",
        "variety": "Glabron",
        "year": 1932,
        "yield": 26.16667
      },
      {
        "site": "Grand Rapids",
        "variety": "Glabron",
        "year": 1932,
        "yield": 14.43333
      },
      {
        "site": "Duluth",
        "variety": "Glabron",
        "year": 1932,
        "yield": 25.86667
      },
      {
        "site": "University Farm",
        "variety": "Svansota",
        "year": 1932,
        "yield": 27.43334
      },
      {
        "site": "Waseca",
        "variety": "Svansota",
        "year": 1932,
        "yield": 38.5
      },
      {
        "site": "Morris",
        "variety": "Svansota",
        "year": 1932,
        "yield": 35.03333
      },
      {
        "site": "Crookston",
        "variety": "Svansota",
        "year": 1932,
        "yield": 20.63333
      },
      {
        "site": "Grand Rapids",
        "variety": "Svansota",
        "year": 1932,
        "yield": 16.63333
      },
      {
        "site": "Duluth",
        "variety": "Svansota",
        "year": 1932,
        "yield": 22.23333
      },
      {
        "site": "University Farm",
        "variety": "Velvet",
        "year": 1932,
        "yield": 26.8
      },
      {
        "site": "Waseca",
        "variety": "Velvet",
        "year": 1932,
        "yield": 37.4
      },
      {
        "site": "Morris",
        "variety": "Velvet",
        "year": 1932,
        "yield": 38.83333
      },
      {
        "site": "Crookston",
        "variety": "Velvet",
        "year": 1932,
        "yield": 32.06666
      },
      {
        "site": "Grand Rapids",
        "variety": "Velvet",
        "year": 1932,
        "yield": 32.23333
      },
      {
        "site": "Duluth",
        "variety": "Velvet",
        "year": 1932,
        "yield": 22.46667
      },
      {
        "site": "University Farm",
        "variety": "Trebi",
        "year": 1932,
        "yield": 29.06667
      },
      {
        "site": "Waseca",
        "variety": "Trebi",
        "year": 1932,
        "yield": 49.2333
      },
      {
        "site": "Morris",
        "variety": "Trebi",
        "year": 1932,
        "yield": 46.63333
      },
      {
        "site": "Crookston",
        "variety": "Trebi",
        "year": 1932,
        "yield": 41.83333
      },
      {
        "site": "Grand Rapids",
        "variety": "Trebi",
        "year": 1932,
        "yield": 20.63333
      },
      {
        "site": "Duluth",
        "variety": "Trebi",
        "year": 1932,
        "yield": 30.6
      },
      {
        "site": "University Farm",
        "variety": "No. 457",
        "year": 1932,
        "yield": 26.43334
      },
      {
        "site": "Waseca",
        "variety": "No. 457",
        "year": 1932,
        "yield": 42.2
      },
      {
        "site": "Morris",
        "variety": "No. 457",
        "year": 1932,
        "yield": 43.53334
      },
      {
        "site": "Crookston",
        "variety": "No. 457",
        "year": 1932,
        "yield": 34.33333
      },
      {
        "site": "Grand Rapids",
        "variety": "No. 457",
        "year": 1932,
        "yield": 19.46667
      },
      {
        "site": "Duluth",
        "variety": "No. 457",
        "year": 1932,
        "yield": 22.7
      },
      {
        "site": "University Farm",
        "variety": "No. 462",
        "year": 1932,
        "yield": 25.56667
      },
      {
        "site": "Waseca",
        "variety": "No. 462",
        "year": 1932,
        "yield": 44.7
      },
      {
        "site": "Morris",
        "variety": "No. 462",
        "year": 1932,
        "yield": 47.0
      },
      {
        "site": "Crookston",
        "variety": "No. 462",
        "year": 1932,
        "yield": 30.53333
      },
      {
        "site": "Grand Rapids",
        "variety": "No. 462",
        "year": 1932,
        "yield": 19.9
      },
      {
        "site": "Duluth",
        "variety": "No. 462",
        "year": 1932,
        "yield": 22.5
      },
      {
        "site": "University Farm",
        "variety": "Peatland",
        "year": 1932,
        "yield": 28.06667
      },
      {
        "site": "Waseca",
        "variety": "Peatland",
        "year": 1932,
        "yield": 36.03333
      },
      {
        "site": "Morris",
        "variety": "Peatland",
        "year": 1932,
        "yield": 43.2
      },
      {
        "site": "Crookston",
        "variety": "Peatland",
        "year": 1932,
        "yield": 25.23333
      },
      {
        "site": "Grand Rapids",
        "variety": "Peatland",
        "year": 1932,
        "yield": 26.76667
      },
      {
        "site": "Duluth",
        "variety": "Peatland",
        "year": 1932,
        "yield": 31.36667
      },
      {
        "site": "University Farm",
        "variety": "No. 475",
        "year": 1932,
        "yield": 30.0
      },
      {
        "site": "Waseca",
        "variety": "No. 475",
        "year": 1932,
        "yield": 41.26667
      },
      {
        "site": "Morris",
        "variety": "No. 475",
        "year": 1932,
        "yield": 44.23333
      },
      {
        "site": "Crookston",
        "variety": "No. 475",
        "year": 1932,
        "yield": 32.13333
      },
      {
        "site": "Grand Rapids",
        "variety": "No. 475",
        "year": 1932,
        "yield": 15.23333
      },
      {
        "site": "Duluth",
        "variety": "No. 475",
        "year": 1932,
        "yield": 27.36667
      },
      {
        "site": "University Farm",
        "variety": "Wisconsin No. 38",
        "year": 1932,
        "yield": 38.0
      },
      {
        "site": "Waseca",
        "variety": "Wisconsin No. 38",
        "year": 1932,
        "yield": 58.16667
      },
      {
        "site": "Morris",
        "variety": "Wisconsin No. 38",
        "year": 1932,
        "yield": 47.16667
      },
      {
        "site": "Crookston",
        "variety": "Wisconsin No. 38",
        "year": 1932,
        "yield": 35.9
      },
      {
        "site": "Grand Rapids",
        "variety": "Wisconsin No. 38",
        "year": 1932,
        "yield": 20.66667
      },
      {
        "site": "Duluth",
        "variety": "Wisconsin No. 38",
        "year": 1932,
        "yield": 29.33333
      }
    ]
  },
  "encoding": {
    "color": {
      "field": "year",
      "type": "nominal"
    },
    "x": {
      "field": "year",
      "type": "nominal"
    },
    "y": {
      "aggregate": "mean",
      "field": "yield",
      "type": "quantitative"
    }
  },
  "height": 600,
  "mark": "bar",
  "width": 800
};
    var opt = {"renderer": "canvas", "actions": false};
    vegaEmbed("#Aa5355e9698a3f021c77e010d205e9b089432794316023c0ea3272f6513d489a6", spec, opt);
  </script>