<divid="unreleased-message"> You are reading an old version of the documentation (v3.0.2). For the latest version see <ahref="https://matplotlib.org/stable/gallery/units/evans_test.html">https://matplotlib.org/stable/gallery/units/evans_test.html</a></div>
<pclass="last">Click <aclass="reference internal" href="#sphx-glr-download-gallery-units-evans-test-py"><spanclass="std std-ref">here</span></a> to download the full example code</p>
<spanid="sphx-glr-gallery-units-evans-test-py"></span><h1>Evans test<aclass="headerlink" href="#evans-test" title="Permalink to this headline">¶</a></h1>
<p>A mockup "Foo" units class which supports conversion and different tick
formatting depending on the "unit". Here the "unit" is just a scalar
conversion factor, but this example shows that Matplotlib is entirely agnostic
<spanclass="k">return</span><ahref="../../api/units_api.html#matplotlib.units.AxisInfo" title="View documentation for matplotlib.units.AxisInfo"><spanclass="n">units</span><spanclass="o">.</span><spanclass="n">AxisInfo</span></a><spanclass="p">(</span>
<spanclass="n">majloc</span><spanclass="o">=</span><ahref="../../api/ticker_api.html#matplotlib.ticker.IndexLocator" title="View documentation for matplotlib.ticker.IndexLocator"><spanclass="n">ticker</span><spanclass="o">.</span><spanclass="n">IndexLocator</span></a><spanclass="p">(</span><spanclass="mi">8</span><spanclass="p">,</span><spanclass="mi">0</span><spanclass="p">),</span>
<spanclass="n">majfmt</span><spanclass="o">=</span><ahref="../../api/ticker_api.html#matplotlib.ticker.FormatStrFormatter" title="View documentation for matplotlib.ticker.FormatStrFormatter"><spanclass="n">ticker</span><spanclass="o">.</span><spanclass="n">FormatStrFormatter</span></a><spanclass="p">(</span><spanclass="s2">"VAL: </span><spanclass="si">%s</span><spanclass="s2">"</span><spanclass="p">),</span>
<spanclass="sd"> convert obj using unit. If obj is a sequence, return the</span>
<spanclass="sd"> converted sequence</span>
<spanclass="sd"> """</span>
<spanclass="k">if</span><ahref="../../api/units_api.html#matplotlib.units.ConversionInterface.is_numlike" title="View documentation for matplotlib.units.ConversionInterface.is_numlike"><spanclass="n">units</span><spanclass="o">.</span><spanclass="n">ConversionInterface</span><spanclass="o">.</span><spanclass="n">is_numlike</span></a><spanclass="p">(</span><spanclass="n">obj</span><spanclass="p">):</span>
<spanclass="k">if</span><ahref="../../api/cbook_api.html#matplotlib.cbook.iterable" title="View documentation for matplotlib.cbook.iterable"><spanclass="n">iterable</span></a><spanclass="p">(</span><spanclass="n">obj</span><spanclass="p">):</span>
<spanclass="s1">'return the default unit for x or None'</span>
<spanclass="k">if</span><ahref="../../api/cbook_api.html#matplotlib.cbook.iterable" title="View documentation for matplotlib.cbook.iterable"><spanclass="n">iterable</span></a><spanclass="p">(</span><spanclass="n">x</span><spanclass="p">):</span>
<spanclass="n">fig</span><spanclass="p">,</span><spanclass="p">(</span><spanclass="n">ax1</span><spanclass="p">,</span><spanclass="n">ax2</span><spanclass="p">)</span><spanclass="o">=</span><ahref="../../api/_as_gen/matplotlib.pyplot.subplots.html#matplotlib.pyplot.subplots" title="View documentation for matplotlib.pyplot.subplots"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">subplots</span></a><spanclass="p">(</span><spanclass="mi">1</span><spanclass="p">,</span><spanclass="mi">2</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.setp.html#matplotlib.pyplot.setp" title="View documentation for matplotlib.pyplot.setp"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">setp</span></a><spanclass="p">(</span><spanclass="n">ax2</span><spanclass="o">.</span><spanclass="n">get_xticklabels</span><spanclass="p">(),</span><spanclass="n">rotation</span><spanclass="o">=</span><spanclass="mi">30</span><spanclass="p">,</span><spanclass="n">ha</span><spanclass="o">=</span><spanclass="s1">'right'</span><spanclass="p">)</span>
<spanclass="c1"># plot without specifying units; will use the None branch for axisinfo</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.setp.html#matplotlib.pyplot.setp" title="View documentation for matplotlib.pyplot.setp"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">setp</span></a><spanclass="p">(</span><spanclass="n">ax1</span><spanclass="o">.</span><spanclass="n">get_xticklabels</span><spanclass="p">(),</span><spanclass="n">rotation</span><spanclass="o">=</span><spanclass="mi">30</span><spanclass="p">,</span><spanclass="n">ha</span><spanclass="o">=</span><spanclass="s1">'right'</span><spanclass="p">)</span>
<ahref="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="View documentation for matplotlib.pyplot.show"><spanclass="n">plt</span><spanclass="o">.</span><spanclass="n">show</span></a><spanclass="p">()</span>
</pre></div>
</div>
<divclass="sphx-glr-footer class sphx-glr-footer-example docutils container" id="sphx-glr-download-gallery-units-evans-test-py">