piccolbo/altair_recipes

View on GitHub
docs/test_qqplot.html

Summary

Maintainability
Test Coverage

<div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">altair_recipes</span> <span class="kn">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">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="kn">as</span> <span class="nn">pd</span>
</pre></div>

<h2>Qqplot</h2>




<div class="highlight"><pre><span></span><span class="nd">@viz_reg_test</span>
<span class="k">def</span> <span class="nf">test_qqplot</span><span class="p">():</span>

    <span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span>
        <span class="p">{</span>
            <span class="s2">&quot;Trial A&quot;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mi">1000</span><span class="p">),</span>
            <span class="s2">&quot;Trial B&quot;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1000</span><span class="p">),</span>
            <span class="s2">&quot;Trial C&quot;</span><span class="p">:</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">uniform</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1000</span><span class="p">),</span>
        <span class="p">}</span>
    <span class="p">)</span>
    <span class="k">return</span> <span class="n">ar</span><span class="o">.</span><span class="n">qqplot</span><span class="p">(</span><span class="n">df</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="s2">&quot;Trial A&quot;</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="s2">&quot;Trial C&quot;</span><span class="p">)</span>


<span class="n">show_test</span><span class="p">(</span><span class="n">test_qqplot</span><span class="p">)</span>
</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="Aab5df9aaf88714854c4b109f20b25d88a062eb789fc6a11d855326bc357ae6b6"></div>
  <script type="text/javascript">
    var spec = {
  "$schema": "https://vega.github.io/schema/vega-lite/v4.0.0.json",
  "config": {
    "view": {
      "continuousHeight": 300,
      "continuousWidth": 400
    }
  },
  "data": {
    "name": "data-b8273988ef2ec76a844283085462412b"
  },
  "datasets": {
    "data-b8273988ef2ec76a844283085462412b": [
      {
        "Trial A": -2.4369144438399415,
        "Trial B": -4.994612860227619,
        "Trial C": 2.0000359814573976
      },
      {
        "Trial A": -1.8913823584176275,
        "Trial B": -4.115117219484954,
        "Trial C": 2.012905968552615
      },
      {
        "Trial A": -1.6382214730376587,
        "Trial B": -3.8389636949558894,
        "Trial C": 2.0264369165144847
      },
      {
        "Trial A": -1.475452031201066,
        "Trial B": -3.741117756804753,
        "Trial C": 2.033178598980945
      },
      {
        "Trial A": -1.3815404369206232,
        "Trial B": -3.648093037088218,
        "Trial C": 2.037555154272211
      },
      {
        "Trial A": -1.306520851679441,
        "Trial B": -3.592112408178179,
        "Trial C": 2.0460261542233322
      },
      {
        "Trial A": -1.2570898463644404,
        "Trial B": -3.510284266815725,
        "Trial C": 2.058268016049005
      },
      {
        "Trial A": -1.1936298568583465,
        "Trial B": -3.447092744074487,
        "Trial C": 2.0663331498526207
      },
      {
        "Trial A": -1.1361360735487138,
        "Trial B": -3.3813167136750257,
        "Trial C": 2.0765412724400876
      },
      {
        "Trial A": -1.078733705460635,
        "Trial B": -3.317223618695942,
        "Trial C": 2.085389061050226
      },
      {
        "Trial A": -1.0393138602864103,
        "Trial B": -3.2418214737509365,
        "Trial C": 2.095469155089508
      },
      {
        "Trial A": -0.9809943945764118,
        "Trial B": -3.1730594970647035,
        "Trial C": 2.1076936901521552
      },
      {
        "Trial A": -0.9448175990807367,
        "Trial B": -3.117270995338771,
        "Trial C": 2.120313553526658
      },
      {
        "Trial A": -0.9187480554306312,
        "Trial B": -3.0642216256247106,
        "Trial C": 2.1341897380076578
      },
      {
        "Trial A": -0.8799132397729272,
        "Trial B": -3.0238129209283255,
        "Trial C": 2.141898454720125
      },
      {
        "Trial A": -0.8392416285518239,
        "Trial B": -2.9982902884113893,
        "Trial C": 2.1536542510380707
      },
      {
        "Trial A": -0.7974824587952207,
        "Trial B": -2.9680987490633823,
        "Trial C": 2.166357995175801
      },
      {
        "Trial A": -0.765376076229312,
        "Trial B": -2.9266929132350263,
        "Trial C": 2.1747143376863765
      },
      {
        "Trial A": -0.7368809561981855,
        "Trial B": -2.880385682412133,
        "Trial C": 2.185435577500729
      },
      {
        "Trial A": -0.7134238910825409,
        "Trial B": -2.8543663081372914,
        "Trial C": 2.194287915725944
      },
      {
        "Trial A": -0.6894316370113888,
        "Trial B": -2.8218055253413628,
        "Trial C": 2.202373045064307
      },
      {
        "Trial A": -0.6652675366845268,
        "Trial B": -2.799949082258891,
        "Trial C": 2.208852863374114
      },
      {
        "Trial A": -0.6429642887967418,
        "Trial B": -2.774331135909289,
        "Trial C": 2.2161481761403667
      },
      {
        "Trial A": -0.6133371094964394,
        "Trial B": -2.739982068653338,
        "Trial C": 2.2253789662176913
      },
      {
        "Trial A": -0.5921499857239554,
        "Trial B": -2.710138921660906,
        "Trial C": 2.2313999818330643
      },
      {
        "Trial A": -0.5587360474878964,
        "Trial B": -2.653849783817006,
        "Trial C": 2.2413418007463424
      },
      {
        "Trial A": -0.5448209682581813,
        "Trial B": -2.618436752837389,
        "Trial C": 2.2525676270979833
      },
      {
        "Trial A": -0.5264908509704033,
        "Trial B": -2.590751301524492,
        "Trial C": 2.261998978404745
      },
      {
        "Trial A": -0.5090332348699347,
        "Trial B": -2.562340989038924,
        "Trial C": 2.269481492807089
      },
      {
        "Trial A": -0.47299742186967775,
        "Trial B": -2.522802559224539,
        "Trial C": 2.2827276190334778
      },
      {
        "Trial A": -0.43497330033362974,
        "Trial B": -2.492949723973032,
        "Trial C": 2.2940483197507975
      },
      {
        "Trial A": -0.41492546091641813,
        "Trial B": -2.46745718047581,
        "Trial C": 2.302625875893029
      },
      {
        "Trial A": -0.4001861264333253,
        "Trial B": -2.433457336078389,
        "Trial C": 2.3096471946179156
      },
      {
        "Trial A": -0.37400935830751475,
        "Trial B": -2.4049625068751026,
        "Trial C": 2.321583832625976
      },
      {
        "Trial A": -0.3593857375873009,
        "Trial B": -2.391598763629867,
        "Trial C": 2.337186819772668
      },
      {
        "Trial A": -0.33389080386888126,
        "Trial B": -2.355351697752375,
        "Trial C": 2.3477507005081657
      },
      {
        "Trial A": -0.3184444893640525,
        "Trial B": -2.3293199669152838,
        "Trial C": 2.353726142354061
      },
      {
        "Trial A": -0.30778571678148653,
        "Trial B": -2.306595894937778,
        "Trial C": 2.3721699292560414
      },
      {
        "Trial A": -0.29219491876269915,
        "Trial B": -2.280398368094956,
        "Trial C": 2.3847888872290537
      },
      {
        "Trial A": -0.2789877154411734,
        "Trial B": -2.261018671882341,
        "Trial C": 2.3904268350223803
      },
      {
        "Trial A": -0.24937756995432703,
        "Trial B": -2.2132611814972023,
        "Trial C": 2.400765226172514
      },
      {
        "Trial A": -0.23542264366075827,
        "Trial B": -2.183253788108098,
        "Trial C": 2.408148604407038
      },
      {
        "Trial A": -0.2100864359370011,
        "Trial B": -2.1576685676363847,
        "Trial C": 2.420145909391252
      },
      {
        "Trial A": -0.18257460558977834,
        "Trial B": -2.134429340148572,
        "Trial C": 2.429255310208175
      },
      {
        "Trial A": -0.16812595425809054,
        "Trial B": -2.1063103207542357,
        "Trial C": 2.4362618771431697
      },
      {
        "Trial A": -0.14477504992181384,
        "Trial B": -2.0859931020467446,
        "Trial C": 2.444121333412517
      },
      {
        "Trial A": -0.1175183757559567,
        "Trial B": -2.0603220155855997,
        "Trial C": 2.4578019318912823
      },
      {
        "Trial A": -0.09423888864962152,
        "Trial B": -2.0355063567571867,
        "Trial C": 2.4711385723105534
      },
      {
        "Trial A": -0.08683398219190522,
        "Trial B": -2.015258178441197,
        "Trial C": 2.493722697695651
      },
      {
        "Trial A": -0.061039497262392675,
        "Trial B": -1.988256814320642,
        "Trial C": 2.5033448089118915
      },
      {
        "Trial A": -0.0464224278397022,
        "Trial B": -1.973938006459452,
        "Trial C": 2.512200353291913
      },
      {
        "Trial A": -0.03343507025727943,
        "Trial B": -1.9605215463049204,
        "Trial C": 2.524109549939258
      },
      {
        "Trial A": -0.013102423021740299,
        "Trial B": -1.939435117111706,
        "Trial C": 2.534938792779913
      },
      {
        "Trial A": 0.0094747593931018,
        "Trial B": -1.914569459855854,
        "Trial C": 2.5433719657090297
      },
      {
        "Trial A": 0.024933633559200967,
        "Trial B": -1.9010853381749793,
        "Trial C": 2.5519037179339232
      },
      {
        "Trial A": 0.04139331730536122,
        "Trial B": -1.8763917347558754,
        "Trial C": 2.565453366736584
      },
      {
        "Trial A": 0.06587859544001189,
        "Trial B": -1.8495754620902263,
        "Trial C": 2.5696014894063826
      },
      {
        "Trial A": 0.08496210076619706,
        "Trial B": -1.8348317138289323,
        "Trial C": 2.580748744372928
      },
      {
        "Trial A": 0.12442885914230642,
        "Trial B": -1.8072143206989963,
        "Trial C": 2.5888397093679973
      },
      {
        "Trial A": 0.1423891991042543,
        "Trial B": -1.7890281189860076,
        "Trial C": 2.6001707237349168
      },
      {
        "Trial A": 0.15769708513220632,
        "Trial B": -1.7735573327809937,
        "Trial C": 2.6109173972913804
      },
      {
        "Trial A": 0.18047375201656052,
        "Trial B": -1.7533053879438194,
        "Trial C": 2.6213667698230996
      },
      {
        "Trial A": 0.19854056535422993,
        "Trial B": -1.7185316961109671,
        "Trial C": 2.6309573653468004
      },
      {
        "Trial A": 0.22215578680661474,
        "Trial B": -1.6925621356500877,
        "Trial C": 2.6376021033436667
      },
      {
        "Trial A": 0.24230353612782451,
        "Trial B": -1.6640937109422824,
        "Trial C": 2.6498298296130445
      },
      {
        "Trial A": 0.25670187195330324,
        "Trial B": -1.6208627448967814,
        "Trial C": 2.6628564221641566
      },
      {
        "Trial A": 0.28170601540622814,
        "Trial B": -1.5946375895558222,
        "Trial C": 2.6692012484878913
      },
      {
        "Trial A": 0.296247756224481,
        "Trial B": -1.5747166760451066,
        "Trial C": 2.678785159827484
      },
      {
        "Trial A": 0.31283487864113557,
        "Trial B": -1.5433338258824063,
        "Trial C": 2.6864066889398046
      },
      {
        "Trial A": 0.32391913216643087,
        "Trial B": -1.5204927015757086,
        "Trial C": 2.6941181749048453
      },
      {
        "Trial A": 0.3438117562533562,
        "Trial B": -1.4905372063842464,
        "Trial C": 2.698821974475019
      },
      {
        "Trial A": 0.3622912083507978,
        "Trial B": -1.4651041777351235,
        "Trial C": 2.706525841971249
      },
      {
        "Trial A": 0.3824632488102992,
        "Trial B": -1.453832166912274,
        "Trial C": 2.7134513537393756
      },
      {
        "Trial A": 0.41690349747596517,
        "Trial B": -1.4303821201338298,
        "Trial C": 2.7213827827847985
      },
      {
        "Trial A": 0.4463396580324131,
        "Trial B": -1.3969207817271982,
        "Trial C": 2.728256012684301
      },
      {
        "Trial A": 0.4855604815107186,
        "Trial B": -1.3745199449883623,
        "Trial C": 2.739170084050378
      },
      {
        "Trial A": 0.5149858072625565,
        "Trial B": -1.3312740483440122,
        "Trial C": 2.751648646235723
      },
      {
        "Trial A": 0.5442778954188026,
        "Trial B": -1.2832033728299301,
        "Trial C": 2.7602059439533555
      },
      {
        "Trial A": 0.5676187934569731,
        "Trial B": -1.2349696593083799,
        "Trial C": 2.768540150022338
      },
      {
        "Trial A": 0.6135387352987887,
        "Trial B": -1.2220919748287713,
        "Trial C": 2.7857774621071822
      },
      {
        "Trial A": 0.6307174330880927,
        "Trial B": -1.1734320027330343,
        "Trial C": 2.7980680197411028
      },
      {
        "Trial A": 0.657560172810755,
        "Trial B": -1.1241084131874137,
        "Trial C": 2.805526551006588
      },
      {
        "Trial A": 0.6912971217622259,
        "Trial B": -1.109003921506581,
        "Trial C": 2.814891335461529
      },
      {
        "Trial A": 0.7213708608630324,
        "Trial B": -1.072146052952357,
        "Trial C": 2.82705743869972
      },
      {
        "Trial A": 0.7495667807316155,
        "Trial B": -1.0369500525693165,
        "Trial C": 2.8361075994228253
      },
      {
        "Trial A": 0.7613433317326798,
        "Trial B": -0.9975790422262645,
        "Trial C": 2.842312618809302
      },
      {
        "Trial A": 0.8100539449382854,
        "Trial B": -0.958234322365527,
        "Trial C": 2.8502796207621954
      },
      {
        "Trial A": 0.8520762322738499,
        "Trial B": -0.8961910554436373,
        "Trial C": 2.8624613806104673
      },
      {
        "Trial A": 0.8773955005538852,
        "Trial B": -0.8503380656632349,
        "Trial C": 2.8709355815748823
      },
      {
        "Trial A": 0.913869706761107,
        "Trial B": -0.7427226468376311,
        "Trial C": 2.880409984170912
      },
      {
        "Trial A": 0.9852748408803716,
        "Trial B": -0.6926676641916504,
        "Trial C": 2.8950308942001715
      },
      {
        "Trial A": 1.0504562823723589,
        "Trial B": -0.6305043089246006,
        "Trial C": 2.9032419082752168
      },
      {
        "Trial A": 1.0942948649003732,
        "Trial B": -0.5847753912784951,
        "Trial C": 2.9077960662962052
      },
      {
        "Trial A": 1.164107897252608,
        "Trial B": -0.5254539300122861,
        "Trial C": 2.919426717062799
      },
      {
        "Trial A": 1.2146921534242476,
        "Trial B": -0.4255130984152997,
        "Trial C": 2.929849549396285
      },
      {
        "Trial A": 1.3280963264158567,
        "Trial B": -0.36755724333093387,
        "Trial C": 2.9413935739415806
      },
      {
        "Trial A": 1.3945291804632705,
        "Trial B": -0.26307086346654457,
        "Trial C": 2.9586299816154518
      },
      {
        "Trial A": 1.517051559474109,
        "Trial B": -0.17773929422093618,
        "Trial C": 2.972162478857637
      },
      {
        "Trial A": 1.61753003798583,
        "Trial B": 0.023697761654997408,
        "Trial C": 2.9795596762499392
      },
      {
        "Trial A": 1.8160769957796565,
        "Trial B": 0.24407054634211894,
        "Trial C": 2.9898285147701054
      }
    ]
  },
  "encoding": {
    "x": {
      "field": "Trial A",
      "type": "quantitative"
    },
    "y": {
      "field": "Trial C",
      "type": "quantitative"
    }
  },
  "height": 600,
  "mark": "point",
  "width": 800
};
    var opt = {"renderer": "canvas", "actions": false};
    vegaEmbed("#Aab5df9aaf88714854c4b109f20b25d88a062eb789fc6a11d855326bc357ae6b6", spec, opt);
  </script>