/usr/share/doc/pyxplot/html/sect0005.html is in pyxplot-doc 0.9.2-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | <!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" xml:lang="en" lang="en">
<head>
<meta name="generator" content="plasTeX" />
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
<title>PyXPlot Users' Guide: An introductory tour</title>
<link href="sect0006.html" title="License" rel="next" />
<link href="sect0004.html" title="The structure of this manual" rel="prev" />
<link href="ch-introduction.html" title="Introduction" rel="up" />
<link rel="stylesheet" href="styles/styles.css" />
</head>
<body>
<div class="navigation">
<table cellspacing="2" cellpadding="0" width="100%">
<tr>
<td><a href="sect0004.html" title="The structure of this manual"><img alt="Previous: The structure of this manual" border="0" src="icons/previous.gif" width="32" height="32" /></a></td>
<td><a href="ch-introduction.html" title="Introduction"><img alt="Up: Introduction" border="0" src="icons/up.gif" width="32" height="32" /></a></td>
<td><a href="sect0006.html" title="License"><img alt="Next: License" border="0" src="icons/next.gif" width="32" height="32" /></a></td>
<td class="navtitle" align="center">PyXPlot Users' Guide</td>
<td><a href="index.html" title="Table of Contents"><img border="0" alt="" src="icons/contents.gif" width="32" height="32" /></a></td>
<td><a href="sect0288.html" title="Index"><img border="0" alt="" src="icons/index.gif" width="32" height="32" /></a></td>
<td><img border="0" alt="" src="icons/blank.gif" width="32" height="32" /></td>
</tr>
</table>
</div>
<div class="breadcrumbs">
<span>
<span>
<a href="index.html">PyXPlot Users' Guide</a> <b>:</b>
</span>
</span><span>
<span>
<a href="sect0001.html">Introduction to PyXPlot</a> <b>:</b>
</span>
</span><span>
<span>
<a href="ch-introduction.html">Introduction</a> <b>:</b>
</span>
</span><span>
<span>
<b class="current">An introductory tour</b>
</span>
</span>
<hr />
</div>
<div><h1 id="a0000000006">1.4 An introductory tour</h1>
<p>This section provides an overview of the wide range of tasks for which Pyxplot can be used. Detailed explanations of the syntax of Pyxplot commands will follow in later chapters, but most of the examples here will work if entered directly at a Pyxplot command prompt. </p><p><b class="bf"><big class="large">The mathematical environment</big></b> </p><p>Pyxplot’s mathematical environment comes with many standard functions built-in. To see a list of them<a href="#a0000000290" class="footnote"><sup class="footnotemark">1</sup></a>, type </p><pre>
show functions
</pre><p>The <tt class="tt">show</tt> command is Pyxplot’s interactive documentation system; to obtain a list of things that can be shown type </p><pre>
show
</pre><p>Pyxplot is an object-orientated language, and its built-in functions live in a module called <tt class="tt">defaults</tt>. Its members may be listed by <tt class="tt">print</tt>ing the module object. </p><pre>
print defaults
</pre><p>Taking as an example the built-in function <tt class="tt">log10(x)</tt>, it can be evaluated as in almost any other programming language. The <tt class="tt">defaults</tt> module is special in that its functions are always accessible to the user’s namespace: </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">print log10(5)</b></tt><br /><tt class="ttfamily">0.69897</tt> </p><p>This function returns numerical data, but Pyxplot has other data types too. For example, the <tt class="tt">primeFactors</tt> function returns a list: </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">print primeFactors(1001)</b></tt><br /><tt class="ttfamily">[7, 11, 13]</tt> </p><p>The <tt class="tt">rgb(r,g,b)</tt> function returns a color object, which can be used in Pyxplot’s vector graphics commands: </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">print rgb(1,1,0)</b></tt><br /><tt class="ttfamily">rgb(1,1,0)</tt> </p><p>and the <tt class="tt">time.fromUnix(t)</tt> function returns a date object from a Unix time: </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">print time.fromUnix(946684800)</b></tt><br /><tt class="ttfamily">Sat 2000 Jan 1 00:00:00 UTC</tt> </p><p>Many commonly-used physical constants are built into Pyxplot’s physics module, <tt class="tt">phy</tt>. For example, the speed of light: </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">print phy.c</b></tt><br /><tt class="ttfamily">299792.46 km/s</tt> </p><p>Numbers in Pyxplot have <b class="bf">physical units</b>, and hence the speed of light is displayed in km/s. If you would rather know how many miles light travels in a year, you can change the display unit, here making use of the fact that the variable <tt class="tt">ans</tt> is always set to the result of the last calculation: </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">print phy.c</b></tt><br /><tt class="ttfamily">299792.46 km/s</tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">set unit preferred miles/year</b></tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">print ans</b></tt><br /><tt class="ttfamily">5.87849967e+12 mi/yr</tt> </p><p>It is easy to use Pyxplot as a <b class="bf">desktop calculator</b> to solve many problems which would conventionally need careful conversion between physical units. For example: </p><ul class="itemize">
<li><p>What is <img src="images/img-0004.png" alt="$80^\circ $" style="vertical-align:0px;
width:25px;
height:13px" class="math gen" />F in Celsius? </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">print 80*unit(oF) / unit(oC)</b></tt><br /><tt class="ttfamily">26.666667</tt> </p></li><li><p>How long does it take for light to travel from the Sun to the Earth?<a href="#a0000000291" class="footnote"><sup class="footnotemark">2</sup></a> </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">print unit(AU) / phy.c</b></tt><br /><tt class="ttfamily">499.00478 s</tt> </p></li><li><p>What wavelength of light corresponds to the ionisation energy of hydrogen (13.6 eV)?<a href="#a0000000292" class="footnote"><sup class="footnotemark">3</sup></a> </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">print phy.c * phy.h / (13.6 * unit(eV))</b></tt><br /><tt class="ttfamily">91.164844 nm</tt> </p></li><li><p>What is the escape velocity of the Earth?<a href="#a0000000293" class="footnote"><sup class="footnotemark">4</sup></a> </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">print sqrt(2 * phy.G * unit(Mearth) / unit(Rearth))</b></tt><br /><tt class="ttfamily">11.186605 km/s</tt> </p></li>
</ul><p><b class="bf"><big class="large">Graph plotting</big></b> </p><p>The simplest way to plot a graph in Pyxplot is simply to follow the <tt class="tt">plot</tt> command with the name of a function to be plotted, e.g.: </p><pre>
plot sin(x)
</pre><p>If a data file is to be plotted, its filename is put in place of a named function. In this example the fifth column of a data file is plotted against the second, including only those data points where the fourth column is larger than two: </p><pre>
plot 'data.dat' using 2:5 select $4>2
</pre><p>In the example below, three Bessel functions are plotted over specified horizontal and vertical ranges: </p><pre>
plot [0:10][-0.5:1] besselJ(0,x), besselJ(1,x), besselJ(2,x)
</pre><center>
<img src="images/img-0006.png" alt="\includegraphics[width=8cm]{examples/eps/ex_intro_bessel}" style="width:8cm" /> </center><p>With a little additional configuration, it is possible to produce three-dimensional plots like this (this example is taken from Section <a href="ex-surface-sinc.html">1.14.1</a>; see Example <a href="ex-surface-sinc.html">1.14.1</a>): </p><center>
<img src="images/img-0009.png" alt="\includegraphics[width=8cm]{examples/eps/ex_surface_sinc}" style="width:8cm" /> </center><p>It is also possible to produce colormaps with custom color scales; this is documented in full in Section <a href="sec-colormaps.html">1.12</a>. Pyxplot includes functions for converting wavelengths of light into colors; they are used here to create a color map of the electromagnetic spectrum: </p><center>
<img src="images/img-0012.png" alt="\includegraphics[width=7cm]{examples/eps/ex_spectrum_1}" style="width:7cm" /> </center><p>This pair of images demonstrates RGB color mixing (see Example <a href="sec-colmap_custom.html">1.12.1</a>): </p><center>
<img src="images/img-0015.png" alt="\includegraphics[width=6cm]{examples/eps/ex_spectrum_colmix1}" style="width:6cm" />
<img src="images/img-0018.png" alt="\includegraphics[width=6cm]{examples/eps/ex_spectrum_colmix2}" style="width:6cm" /> </center><p><b class="bf"><big class="large">Generating data tables</big></b> </p><p>Pyxplot can output tables of data to disk, using a similar syntax to that used for plotting graphs. The data can either be sampled from functions, or read in from another data file: </p><pre>
tabulate tan(x)
</pre><p>A common application of the <tt class="tt">tabulate</tt> command is filter or re-format the contents of data files. For example, the command below takes only the third and seventh columns out of a data file, and converts the latter from degrees into radians: </p><pre>
tabulate 'data.dat' using 3:$7*unit(deg)/unit(rad)
</pre><p>The same effect could be achieved by setting radians as the default unit of angle: </p><pre>
set unit of angle radians
tabulate 'data.dat' using 3:$7*unit(deg)
</pre><p>More sophisticated data processing is also possible; this example produces a histogram of the values in the fourth column of a datafile, and then outputs that histogram as a new data file: </p><pre>
histogram h() 'data.dat' using 4
tabulate h(x)
</pre><p><b class="bf"><big class="large">Solving equations</big></b> </p><p>Pyxplot can solve systems of equations numerically; the following example evaluates <img src="images/img-0020.png" alt="$\int _{0\, \mathrm{s}}^{2\, \mathrm{s}} x^2\, \mathrm{d}x$" style="vertical-align:-6px;
width:71px;
height:25px" class="math gen" />: </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">print int_dx(x**2,0*unit(s),2*unit(s))</b></tt><br /><tt class="ttfamily">2.6666667 s**3</tt> </p><p>The <tt class="tt">solve</tt> command can be used to solve systems of simultaneous equations, such as this system with two variables: </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">solve x+y=1 , 2*x+3*y=7 via x,y</b></tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">print "x=%s; y=%s"%(x,y)</b></tt><br /><tt class="ttfamily">x=-4; y=5</tt> </p><p>The <tt class="tt">minimise</tt> and <tt class="tt">maximise</tt> commands find the extrema of functions; here they are used to find the minimum of the function <img src="images/img-0021.png" alt="$\cos (x)$" style="vertical-align:-4px;
width:47px;
height:18px" class="math gen" /> closest to <img src="images/img-0022.png" alt="$x=0.5$" style="vertical-align:0px;
width:56px;
height:13px" class="math gen" />: </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">x=0.5</b></tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">minimise cos(x) via x</b></tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">print x</b></tt><br /><tt class="ttfamily">3.1415927</tt> </p><p>All of the examples shown so far have used only real numbers, but Pyxplot can also perform algebra on complex numbers. By default, evaluation of <tt class="tt">sqrt(-1)</tt> throws an error – the emergence of complex numbers is often an indication that a calculation has gone wrong – but complex arithmetic can be enabled by typing<a name="a0000000294" id="a0000000294"></a> </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">set numerics complex</b></tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">print sqrt(-1)</b></tt><br /><tt class="ttfamily">i</tt> </p><p>Many of the mathematical functions which are built into Pyxplot can take complex arguments, for example </p><p> <tt class="ttfamily">pyxplot> <b class="bfseries">set numerics complex</b></tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">print exp(2+3*i)</b></tt><br /><tt class="ttfamily">(-7.3151101+1.0427437i)</tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">print sin(i)</b></tt><br /><tt class="ttfamily">1.1752012i</tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">print arg(2+3*i)</b></tt><br /><tt class="ttfamily">0.98279372</tt><br /><tt class="ttfamily">pyxplot> <b class="bfseries">print Re(2+3*i)</b></tt><br /><tt class="ttfamily">2</tt> </p><p><b class="bf"><big class="large">Vector graphics</big></b> </p><p>Pyxplot’s graph-plotting canvas can also be used for drawing general vector graphics, using simple commands such as: </p><pre>
box from -8,-4 to 8,4 with fillcolor green
text "Pyxplot" at 2,3
arrow from 0,0 to -4,2
line from -5,0 to 5,0
</pre><p>These commands are described in detail in Chapter <a href="ch-vector_graphics.html">3</a>. They interface neatly to the vector data type in Pyxplot’s mathematical environment, to ease geometric construction. Thus, it is quite possible for mathematically-minded users to multiply transformation matrices with position vectors on the graphics canvas to calculate where objects should be drawn. The following example uses a rotation matrix to draw a big arrow at angle <img src="images/img-0023.png" alt="$\theta $" style="vertical-align:0px;
width:9px;
height:12px" class="math gen" /> to the vertical: </p><pre>
rotate(a) = matrix( [[cos(a),-sin(a)], \
[sin(a), cos(a)] ] )
pos = vector(0,5)*unit(cm)
theta = 30*unit(deg)
arrow from 0,0 to rotate(theta)*pos with linewidth 3
</pre></div>
<div id="footnotes">
<p><b>Footnotes</b></p>
<ol>
<li id="a0000000290">See also Chapter <a href="ch-function_list.html">2</a>.</li><li id="a0000000291">The astronomical unit (AU) is a unit used by astronomers, equal to the average distance of the Earth from the Sun.</li><li id="a0000000292">The electron volt (eV) is a unit of energy used by physicists.</li><li id="a0000000293">The Earth radius and Earth mass are defined as units in Pyxplot.</li>
</ol>
</div>
<div class="navigation">
<table cellspacing="2" cellpadding="0" width="100%">
<tr>
<td><a href="sect0004.html" title="The structure of this manual"><img alt="Previous: The structure of this manual" border="0" src="icons/previous.gif" width="32" height="32" /></a></td>
<td><a href="ch-introduction.html" title="Introduction"><img alt="Up: Introduction" border="0" src="icons/up.gif" width="32" height="32" /></a></td>
<td><a href="sect0006.html" title="License"><img alt="Next: License" border="0" src="icons/next.gif" width="32" height="32" /></a></td>
<td class="navtitle" align="center">PyXPlot Users' Guide</td>
<td><a href="index.html" title="Table of Contents"><img border="0" alt="" src="icons/contents.gif" width="32" height="32" /></a></td>
<td><a href="sect0288.html" title="Index"><img border="0" alt="" src="icons/index.gif" width="32" height="32" /></a></td>
<td><img border="0" alt="" src="icons/blank.gif" width="32" height="32" /></td>
</tr>
</table>
</div>
<script language="javascript" src="icons/imgadjust.js" type="text/javascript"></script>
</body>
</html>
|