pyqtgraph/documentation/build/html/functions.html
2012-03-01 21:55:32 -05:00

341 lines
22 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pyqtgraphs Helper Functions &mdash; pyqtgraph v1.8 documentation</title>
<link rel="stylesheet" href="_static/default.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '',
VERSION: '1.8',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="top" title="pyqtgraph v1.8 documentation" href="index.html" />
<link rel="up" title="API Reference" href="apireference.html" />
<link rel="next" title="Pyqtgraphs Graphics Items" href="graphicsItems/index.html" />
<link rel="prev" title="API Reference" href="apireference.html" />
</head>
<body>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="graphicsItems/index.html" title="Pyqtgraphs Graphics Items"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="apireference.html" title="API Reference"
accesskey="P">previous</a> |</li>
<li><a href="index.html">pyqtgraph v1.8 documentation</a> &raquo;</li>
<li><a href="apireference.html" accesskey="U">API Reference</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="pyqtgraph-s-helper-functions">
<h1>Pyqtgraph&#8217;s Helper Functions<a class="headerlink" href="#pyqtgraph-s-helper-functions" title="Permalink to this headline"></a></h1>
<div class="section" id="simple-data-display-functions">
<h2>Simple Data Display Functions<a class="headerlink" href="#simple-data-display-functions" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt id="pyqtgraph.plot">
<tt class="descclassname">pyqtgraph.</tt><tt class="descname">plot</tt><big>(</big><em>*args</em>, <em>**kargs</em><big>)</big><a class="reference internal" href="_modules/pyqtgraph.html#plot"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyqtgraph.plot" title="Permalink to this definition"></a></dt>
<dd><div class="line-block">
<div class="line">Create and return a PlotWindow (this is just a window with PlotWidget inside), plot data in it.</div>
<div class="line">Accepts a <em>title</em> argument to set the title of the window.</div>
<div class="line">All other arguments are used to plot data. (see <a class="reference internal" href="graphicsItems/plotitem.html#pyqtgraph.PlotItem.plot" title="pyqtgraph.PlotItem.plot"><tt class="xref py py-func docutils literal"><span class="pre">PlotItem.plot()</span></tt></a>)</div>
</div>
</dd></dl>
<dl class="function">
<dt id="pyqtgraph.image">
<tt class="descclassname">pyqtgraph.</tt><tt class="descname">image</tt><big>(</big><em>*args</em>, <em>**kargs</em><big>)</big><a class="reference internal" href="_modules/pyqtgraph.html#image"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyqtgraph.image" title="Permalink to this definition"></a></dt>
<dd><div class="line-block">
<div class="line">Create and return an ImageWindow (this is just a window with ImageView widget inside), show image data inside.</div>
<div class="line">Will show 2D or 3D image data.</div>
<div class="line">Accepts a <em>title</em> argument to set the title of the window.</div>
<div class="line">All other arguments are used to show data. (see <a class="reference internal" href="widgets/imageview.html#pyqtgraph.ImageView.setImage" title="pyqtgraph.ImageView.setImage"><tt class="xref py py-func docutils literal"><span class="pre">ImageView.setImage()</span></tt></a>)</div>
</div>
</dd></dl>
</div>
<div class="section" id="color-pen-and-brush-functions">
<h2>Color, Pen, and Brush Functions<a class="headerlink" href="#color-pen-and-brush-functions" title="Permalink to this headline"></a></h2>
<p>Qt uses the classes QColor, QPen, and QBrush to determine how to draw lines and fill shapes. These classes are highly capable but somewhat awkward to use. Pyqtgraph offers the functions <a class="reference internal" href="#pyqtgraph.mkColor" title="pyqtgraph.mkColor"><tt class="xref py py-func docutils literal"><span class="pre">mkColor()</span></tt></a>, <a class="reference internal" href="#pyqtgraph.mkPen" title="pyqtgraph.mkPen"><tt class="xref py py-func docutils literal"><span class="pre">mkPen()</span></tt></a>, and <a class="reference internal" href="#pyqtgraph.mkBrush" title="pyqtgraph.mkBrush"><tt class="xref py py-func docutils literal"><span class="pre">mkBrush()</span></tt></a> to simplify the process of creating these classes. In most cases, however, it will be unnecessary to call these functions directly&#8211;any function or method that accepts <em>pen</em> or <em>brush</em> arguments will make use of these functions for you. For example, the following three lines all have the same effect:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">pg</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">xdata</span><span class="p">,</span> <span class="n">ydata</span><span class="p">,</span> <span class="n">pen</span><span class="o">=</span><span class="s">&#39;r&#39;</span><span class="p">)</span>
<span class="n">pg</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">xdata</span><span class="p">,</span> <span class="n">ydata</span><span class="p">,</span> <span class="n">pen</span><span class="o">=</span><span class="n">pg</span><span class="o">.</span><span class="n">mkPen</span><span class="p">(</span><span class="s">&#39;r&#39;</span><span class="p">))</span>
<span class="n">pg</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">xdata</span><span class="p">,</span> <span class="n">ydata</span><span class="p">,</span> <span class="n">pen</span><span class="o">=</span><span class="n">QPen</span><span class="p">(</span><span class="n">QColor</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)))</span>
</pre></div>
</div>
<dl class="function">
<dt id="pyqtgraph.mkColor">
<tt class="descclassname">pyqtgraph.</tt><tt class="descname">mkColor</tt><big>(</big><em>*args</em><big>)</big><a class="headerlink" href="#pyqtgraph.mkColor" title="Permalink to this definition"></a></dt>
<dd><p>Convenience function for constructing QColor from a variety of argument types. Accepted arguments are:</p>
<table border="1" class="docutils">
<colgroup>
<col width="25%" />
<col width="75%" />
</colgroup>
<tbody valign="top">
<tr><td>&#8216;c&#8217;</td>
<td>one of: r, g, b, c, m, y, k, w</td>
</tr>
<tr><td>R, G, B, [A]</td>
<td>integers 0-255</td>
</tr>
<tr><td>(R, G, B, [A])</td>
<td>tuple of integers 0-255</td>
</tr>
<tr><td>float</td>
<td>greyscale, 0.0-1.0</td>
</tr>
<tr><td>int</td>
<td>see <a class="reference internal" href="#pyqtgraph.intColor" title="pyqtgraph.intColor"><tt class="xref py py-func docutils literal"><span class="pre">intColor()</span></tt></a></td>
</tr>
<tr><td>(int, hues)</td>
<td>see <a class="reference internal" href="#pyqtgraph.intColor" title="pyqtgraph.intColor"><tt class="xref py py-func docutils literal"><span class="pre">intColor()</span></tt></a></td>
</tr>
<tr><td>&#8220;RGB&#8221;</td>
<td>hexadecimal strings; may begin with &#8216;#&#8217;</td>
</tr>
<tr><td>&#8220;RGBA&#8221;</td>
<td>&nbsp;</td>
</tr>
<tr><td>&#8220;RRGGBB&#8221;</td>
<td>&nbsp;</td>
</tr>
<tr><td>&#8220;RRGGBBAA&#8221;</td>
<td>&nbsp;</td>
</tr>
<tr><td>QColor</td>
<td>QColor instance; makes a copy.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="function">
<dt id="pyqtgraph.mkPen">
<tt class="descclassname">pyqtgraph.</tt><tt class="descname">mkPen</tt><big>(</big><em>*args</em>, <em>**kargs</em><big>)</big><a class="headerlink" href="#pyqtgraph.mkPen" title="Permalink to this definition"></a></dt>
<dd><p>Convenience function for constructing QPen.</p>
<p>Examples:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">mkPen</span><span class="p">(</span><span class="n">color</span><span class="p">)</span>
<span class="n">mkPen</span><span class="p">(</span><span class="n">color</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="n">mkPen</span><span class="p">(</span><span class="n">cosmetic</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mf">4.5</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s">&#39;r&#39;</span><span class="p">)</span>
<span class="n">mkPen</span><span class="p">({</span><span class="s">&#39;color&#39;</span><span class="p">:</span> <span class="s">&quot;FF0&quot;</span><span class="p">,</span> <span class="n">width</span><span class="p">:</span> <span class="mi">2</span><span class="p">})</span>
<span class="n">mkPen</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span> <span class="c"># (no pen)</span>
</pre></div>
</div>
<p>In these examples, <em>color</em> may be replaced with any arguments accepted by <a class="reference internal" href="#pyqtgraph.mkColor" title="pyqtgraph.mkColor"><tt class="xref py py-func docutils literal"><span class="pre">mkColor()</span></tt></a></p>
</dd></dl>
<dl class="function">
<dt id="pyqtgraph.mkBrush">
<tt class="descclassname">pyqtgraph.</tt><tt class="descname">mkBrush</tt><big>(</big><em>*args</em><big>)</big><a class="headerlink" href="#pyqtgraph.mkBrush" title="Permalink to this definition"></a></dt>
<dd><div class="line-block">
<div class="line">Convenience function for constructing Brush.</div>
<div class="line">This function always constructs a solid brush and accepts the same arguments as <a class="reference internal" href="#pyqtgraph.mkColor" title="pyqtgraph.mkColor"><tt class="xref py py-func docutils literal"><span class="pre">mkColor()</span></tt></a></div>
<div class="line">Calling mkBrush(None) returns an invisible brush.</div>
</div>
</dd></dl>
<dl class="function">
<dt id="pyqtgraph.hsvColor">
<tt class="descclassname">pyqtgraph.</tt><tt class="descname">hsvColor</tt><big>(</big><em>h</em>, <em>s=1.0</em>, <em>v=1.0</em>, <em>a=1.0</em><big>)</big><a class="headerlink" href="#pyqtgraph.hsvColor" title="Permalink to this definition"></a></dt>
<dd><p>Generate a QColor from HSVa values.</p>
</dd></dl>
<dl class="function">
<dt id="pyqtgraph.intColor">
<tt class="descclassname">pyqtgraph.</tt><tt class="descname">intColor</tt><big>(</big><em>index</em>, <em>hues=9</em>, <em>values=1</em>, <em>maxValue=255</em>, <em>minValue=150</em>, <em>maxHue=360</em>, <em>minHue=0</em>, <em>sat=255</em>, <em>alpha=255</em>, <em>**kargs</em><big>)</big><a class="headerlink" href="#pyqtgraph.intColor" title="Permalink to this definition"></a></dt>
<dd><p>Creates a QColor from a single index. Useful for stepping through a predefined list of colors.</p>
<p>The argument <em>index</em> determines which color from the set will be returned. All other arguments determine what the set of predefined colors will be</p>
<p>Colors are chosen by cycling across hues while varying the value (brightness).
By default, this selects from a list of 9 hues.</p>
</dd></dl>
<dl class="function">
<dt id="pyqtgraph.colorTuple">
<tt class="descclassname">pyqtgraph.</tt><tt class="descname">colorTuple</tt><big>(</big><em>c</em><big>)</big><a class="headerlink" href="#pyqtgraph.colorTuple" title="Permalink to this definition"></a></dt>
<dd><p>Return a tuple (R,G,B,A) from a QColor</p>
</dd></dl>
<dl class="function">
<dt id="pyqtgraph.colorStr">
<tt class="descclassname">pyqtgraph.</tt><tt class="descname">colorStr</tt><big>(</big><em>c</em><big>)</big><a class="headerlink" href="#pyqtgraph.colorStr" title="Permalink to this definition"></a></dt>
<dd><p>Generate a hex string code from a QColor</p>
</dd></dl>
</div>
<div class="section" id="data-slicing">
<h2>Data Slicing<a class="headerlink" href="#data-slicing" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt id="pyqtgraph.affineSlice">
<tt class="descclassname">pyqtgraph.</tt><tt class="descname">affineSlice</tt><big>(</big><em>data</em>, <em>shape</em>, <em>origin</em>, <em>vectors</em>, <em>axes</em>, <em>**kargs</em><big>)</big><a class="headerlink" href="#pyqtgraph.affineSlice" title="Permalink to this definition"></a></dt>
<dd><p>Take a slice of any orientation through an array. This is useful for extracting sections of multi-dimensional arrays such as MRI images for viewing as 1D or 2D data.</p>
<p>The slicing axes are aribtrary; they do not need to be orthogonal to the original data or even to each other. It is possible to use this function to extract arbitrary linear, rectangular, or parallelepiped shapes from within larger datasets.</p>
<p>For a graphical interface to this function, see <tt class="xref py py-func docutils literal"><span class="pre">ROI.getArrayRegion()</span></tt></p>
<p>Arguments:</p>
<blockquote>
<div class="line-block">
<div class="line"><em>data</em> (ndarray): the original dataset</div>
<div class="line"><em>shape</em>: the shape of the slice to take (Note the return value may have more dimensions than len(shape))</div>
<div class="line"><em>origin</em>: the location in the original dataset that will become the origin in the sliced data.</div>
<div class="line"><em>vectors</em>: list of unit vectors which point in the direction of the slice axes</div>
</div>
<ul class="simple">
<li>each vector must have the same length as <em>axes</em></li>
<li>If the vectors are not unit length, the result will be scaled.</li>
<li>If the vectors are not orthogonal, the result will be sheared.</li>
</ul>
<p><em>axes</em>: the axes in the original dataset which correspond to the slice <em>vectors</em></p>
</blockquote>
<p>Example: start with a 4D fMRI data set, take a diagonal-planar slice out of the last 3 axes</p>
<blockquote>
<ul class="simple">
<li>data = array with dims (time, x, y, z) = (100, 40, 40, 40)</li>
<li>The plane to pull out is perpendicular to the vector (x,y,z) = (1,1,1)</li>
<li>The origin of the slice will be at (x,y,z) = (40, 0, 0)</li>
<li>We will slice a 20x20 plane from each timepoint, giving a final shape (100, 20, 20)</li>
</ul>
</blockquote>
<p>The call for this example would look like:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">affineSlice</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">shape</span><span class="o">=</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span><span class="mi">20</span><span class="p">),</span> <span class="n">origin</span><span class="o">=</span><span class="p">(</span><span class="mi">40</span><span class="p">,</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="n">vectors</span><span class="o">=</span><span class="p">((</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">)),</span> <span class="n">axes</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">))</span>
</pre></div>
</div>
<p>Note the following must be true:</p>
<blockquote>
<div class="line-block">
<div class="line">len(shape) == len(vectors) </div>
<div class="line">len(origin) == len(axes) == len(vectors[0])</div>
</div>
</blockquote>
</dd></dl>
</div>
<div class="section" id="si-unit-conversion-functions">
<h2>SI Unit Conversion Functions<a class="headerlink" href="#si-unit-conversion-functions" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt id="pyqtgraph.siFormat">
<tt class="descclassname">pyqtgraph.</tt><tt class="descname">siFormat</tt><big>(</big><em>x</em>, <em>precision=3</em>, <em>suffix=''</em>, <em>space=True</em>, <em>error=None</em>, <em>minVal=1e-25</em>, <em>allowUnicode=True</em><big>)</big><a class="headerlink" href="#pyqtgraph.siFormat" title="Permalink to this definition"></a></dt>
<dd><p>Return the number x formatted in engineering notation with SI prefix.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">siFormat</span><span class="p">(</span><span class="mf">0.0001</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s">&#39;V&#39;</span><span class="p">)</span> <span class="c"># returns &quot;100 μV&quot;</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="pyqtgraph.siScale">
<tt class="descclassname">pyqtgraph.</tt><tt class="descname">siScale</tt><big>(</big><em>x</em>, <em>minVal=1e-25</em>, <em>allowUnicode=True</em><big>)</big><a class="headerlink" href="#pyqtgraph.siScale" title="Permalink to this definition"></a></dt>
<dd><p>Return the recommended scale factor and SI prefix string for x.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">siScale</span><span class="p">(</span><span class="mf">0.0001</span><span class="p">)</span> <span class="c"># returns (1e6, &#39;μ&#39;)</span>
<span class="c"># This indicates that the number 0.0001 is best represented as 0.0001 * 1e6 = 100 μUnits</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="pyqtgraph.siEval">
<tt class="descclassname">pyqtgraph.</tt><tt class="descname">siEval</tt><big>(</big><em>s</em><big>)</big><a class="headerlink" href="#pyqtgraph.siEval" title="Permalink to this definition"></a></dt>
<dd><p>Convert a value written in SI notation to its equivalent prefixless value</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">siEval</span><span class="p">(</span><span class="s">&quot;100 μV&quot;</span><span class="p">)</span> <span class="c"># returns 0.0001</span>
</pre></div>
</div>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Pyqtgraph&#8217;s Helper Functions</a><ul>
<li><a class="reference internal" href="#simple-data-display-functions">Simple Data Display Functions</a></li>
<li><a class="reference internal" href="#color-pen-and-brush-functions">Color, Pen, and Brush Functions</a></li>
<li><a class="reference internal" href="#data-slicing">Data Slicing</a></li>
<li><a class="reference internal" href="#si-unit-conversion-functions">SI Unit Conversion Functions</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="apireference.html"
title="previous chapter">API Reference</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="graphicsItems/index.html"
title="next chapter">Pyqtgraph&#8217;s Graphics Items</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/functions.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" size="18" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="graphicsItems/index.html" title="Pyqtgraphs Graphics Items"
>next</a> |</li>
<li class="right" >
<a href="apireference.html" title="API Reference"
>previous</a> |</li>
<li><a href="index.html">pyqtgraph v1.8 documentation</a> &raquo;</li>
<li><a href="apireference.html" >API Reference</a> &raquo;</li>
</ul>
</div>
<div class="footer">
&copy; Copyright 2011, Luke Campagnola.
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.1.
</div>
</body>
</html>