piccolbo/altair_recipes

View on GitHub
docs/test_areaplot.html

Summary

Maintainability
Test Coverage

<div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">altair</span> <span class="k">as</span> <span class="nn">alt</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>Areaplot</h2>




<div class="highlight"><pre><span></span><span class="nd">@viz_reg_test</span>
<span class="k">def</span> <span class="nf">test_areaplot</span><span class="p">():</span>
    <span class="k">return</span> <span class="n">alt</span><span class="o">.</span><span class="n">vconcat</span><span class="p">(</span>
        <span class="o">*</span><span class="nb">map</span><span class="p">(</span>
            <span class="k">lambda</span> <span class="n">stack</span><span class="p">:</span> <span class="n">ar</span><span class="o">.</span><span class="n">areaplot</span><span class="p">(</span>
                <span class="n">data</span><span class="o">.</span><span class="n">iowa_electricity</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;net_generation&quot;</span><span class="p">,</span>
                <span class="n">color</span><span class="o">=</span><span class="s2">&quot;source&quot;</span><span class="p">,</span>
                <span class="n">stack</span><span class="o">=</span><span class="n">stack</span><span class="p">,</span>
            <span class="p">),</span>
            <span class="n">ar</span><span class="o">.</span><span class="n">StackType</span><span class="p">,</span>
        <span class="p">)</span>
    <span class="p">)</span>


<span class="n">show_test</span><span class="p">(</span><span class="n">test_areaplot</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="Aaa3635b937cd3d236f03124c3d7667292b9eb1aa621b835191af49423c283dd5"></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
    }
  },
  "datasets": {
    "data-bb61008ba0c766c5601afa5323d12ad4": [
      {
        "net_generation": 35361,
        "source": "Fossil Fuels",
        "year": "2001-01-01T00:00:00"
      },
      {
        "net_generation": 35991,
        "source": "Fossil Fuels",
        "year": "2002-01-01T00:00:00"
      },
      {
        "net_generation": 36234,
        "source": "Fossil Fuels",
        "year": "2003-01-01T00:00:00"
      },
      {
        "net_generation": 36205,
        "source": "Fossil Fuels",
        "year": "2004-01-01T00:00:00"
      },
      {
        "net_generation": 36883,
        "source": "Fossil Fuels",
        "year": "2005-01-01T00:00:00"
      },
      {
        "net_generation": 37014,
        "source": "Fossil Fuels",
        "year": "2006-01-01T00:00:00"
      },
      {
        "net_generation": 41389,
        "source": "Fossil Fuels",
        "year": "2007-01-01T00:00:00"
      },
      {
        "net_generation": 42734,
        "source": "Fossil Fuels",
        "year": "2008-01-01T00:00:00"
      },
      {
        "net_generation": 38620,
        "source": "Fossil Fuels",
        "year": "2009-01-01T00:00:00"
      },
      {
        "net_generation": 42750,
        "source": "Fossil Fuels",
        "year": "2010-01-01T00:00:00"
      },
      {
        "net_generation": 39361,
        "source": "Fossil Fuels",
        "year": "2011-01-01T00:00:00"
      },
      {
        "net_generation": 37379,
        "source": "Fossil Fuels",
        "year": "2012-01-01T00:00:00"
      },
      {
        "net_generation": 34873,
        "source": "Fossil Fuels",
        "year": "2013-01-01T00:00:00"
      },
      {
        "net_generation": 35250,
        "source": "Fossil Fuels",
        "year": "2014-01-01T00:00:00"
      },
      {
        "net_generation": 32319,
        "source": "Fossil Fuels",
        "year": "2015-01-01T00:00:00"
      },
      {
        "net_generation": 28437,
        "source": "Fossil Fuels",
        "year": "2016-01-01T00:00:00"
      },
      {
        "net_generation": 29329,
        "source": "Fossil Fuels",
        "year": "2017-01-01T00:00:00"
      },
      {
        "net_generation": 3853,
        "source": "Nuclear Energy",
        "year": "2001-01-01T00:00:00"
      },
      {
        "net_generation": 4574,
        "source": "Nuclear Energy",
        "year": "2002-01-01T00:00:00"
      },
      {
        "net_generation": 3988,
        "source": "Nuclear Energy",
        "year": "2003-01-01T00:00:00"
      },
      {
        "net_generation": 4929,
        "source": "Nuclear Energy",
        "year": "2004-01-01T00:00:00"
      },
      {
        "net_generation": 4538,
        "source": "Nuclear Energy",
        "year": "2005-01-01T00:00:00"
      },
      {
        "net_generation": 5095,
        "source": "Nuclear Energy",
        "year": "2006-01-01T00:00:00"
      },
      {
        "net_generation": 4519,
        "source": "Nuclear Energy",
        "year": "2007-01-01T00:00:00"
      },
      {
        "net_generation": 5282,
        "source": "Nuclear Energy",
        "year": "2008-01-01T00:00:00"
      },
      {
        "net_generation": 4679,
        "source": "Nuclear Energy",
        "year": "2009-01-01T00:00:00"
      },
      {
        "net_generation": 4451,
        "source": "Nuclear Energy",
        "year": "2010-01-01T00:00:00"
      },
      {
        "net_generation": 5215,
        "source": "Nuclear Energy",
        "year": "2011-01-01T00:00:00"
      },
      {
        "net_generation": 4347,
        "source": "Nuclear Energy",
        "year": "2012-01-01T00:00:00"
      },
      {
        "net_generation": 5321,
        "source": "Nuclear Energy",
        "year": "2013-01-01T00:00:00"
      },
      {
        "net_generation": 4152,
        "source": "Nuclear Energy",
        "year": "2014-01-01T00:00:00"
      },
      {
        "net_generation": 5243,
        "source": "Nuclear Energy",
        "year": "2015-01-01T00:00:00"
      },
      {
        "net_generation": 4703,
        "source": "Nuclear Energy",
        "year": "2016-01-01T00:00:00"
      },
      {
        "net_generation": 5214,
        "source": "Nuclear Energy",
        "year": "2017-01-01T00:00:00"
      },
      {
        "net_generation": 1437,
        "source": "Renewables",
        "year": "2001-01-01T00:00:00"
      },
      {
        "net_generation": 1963,
        "source": "Renewables",
        "year": "2002-01-01T00:00:00"
      },
      {
        "net_generation": 1885,
        "source": "Renewables",
        "year": "2003-01-01T00:00:00"
      },
      {
        "net_generation": 2102,
        "source": "Renewables",
        "year": "2004-01-01T00:00:00"
      },
      {
        "net_generation": 2724,
        "source": "Renewables",
        "year": "2005-01-01T00:00:00"
      },
      {
        "net_generation": 3364,
        "source": "Renewables",
        "year": "2006-01-01T00:00:00"
      },
      {
        "net_generation": 3870,
        "source": "Renewables",
        "year": "2007-01-01T00:00:00"
      },
      {
        "net_generation": 5070,
        "source": "Renewables",
        "year": "2008-01-01T00:00:00"
      },
      {
        "net_generation": 8560,
        "source": "Renewables",
        "year": "2009-01-01T00:00:00"
      },
      {
        "net_generation": 10308,
        "source": "Renewables",
        "year": "2010-01-01T00:00:00"
      },
      {
        "net_generation": 11795,
        "source": "Renewables",
        "year": "2011-01-01T00:00:00"
      },
      {
        "net_generation": 14949,
        "source": "Renewables",
        "year": "2012-01-01T00:00:00"
      },
      {
        "net_generation": 16476,
        "source": "Renewables",
        "year": "2013-01-01T00:00:00"
      },
      {
        "net_generation": 17452,
        "source": "Renewables",
        "year": "2014-01-01T00:00:00"
      },
      {
        "net_generation": 19091,
        "source": "Renewables",
        "year": "2015-01-01T00:00:00"
      },
      {
        "net_generation": 21241,
        "source": "Renewables",
        "year": "2016-01-01T00:00:00"
      },
      {
        "net_generation": 21933,
        "source": "Renewables",
        "year": "2017-01-01T00:00:00"
      }
    ]
  },
  "vconcat": [
    {
      "data": {
        "name": "data-bb61008ba0c766c5601afa5323d12ad4"
      },
      "encoding": {
        "color": {
          "field": "source",
          "type": "nominal"
        },
        "x": {
          "field": "year",
          "type": "temporal"
        },
        "y": {
          "field": "net_generation",
          "type": "quantitative"
        }
      },
      "height": 600,
      "mark": {
        "opacity": 1,
        "type": "area"
      },
      "width": 800
    },
    {
      "data": {
        "name": "data-bb61008ba0c766c5601afa5323d12ad4"
      },
      "encoding": {
        "color": {
          "field": "source",
          "type": "nominal"
        },
        "x": {
          "field": "year",
          "type": "temporal"
        },
        "y": {
          "field": "net_generation",
          "stack": true,
          "type": "quantitative"
        }
      },
      "height": 600,
      "mark": {
        "opacity": 1,
        "type": "area"
      },
      "width": 800
    },
    {
      "data": {
        "name": "data-bb61008ba0c766c5601afa5323d12ad4"
      },
      "encoding": {
        "color": {
          "field": "source",
          "type": "nominal"
        },
        "x": {
          "field": "year",
          "type": "temporal"
        },
        "y": {
          "field": "net_generation",
          "stack": false,
          "type": "quantitative"
        }
      },
      "height": 600,
      "mark": {
        "opacity": 1,
        "type": "area"
      },
      "width": 800
    },
    {
      "data": {
        "name": "data-bb61008ba0c766c5601afa5323d12ad4"
      },
      "encoding": {
        "color": {
          "field": "source",
          "type": "nominal"
        },
        "x": {
          "field": "year",
          "type": "temporal"
        },
        "y": {
          "field": "net_generation",
          "stack": "normalize",
          "type": "quantitative"
        }
      },
      "height": 600,
      "mark": {
        "opacity": 1,
        "type": "area"
      },
      "width": 800
    }
  ]
};
    var opt = {"renderer": "canvas", "actions": false};
    vegaEmbed("#Aaa3635b937cd3d236f03124c3d7667292b9eb1aa621b835191af49423c283dd5", spec, opt);
  </script>