[scitools.wiki] push by h...@simula.no - updates on 2013-12-29 08:21 GMT

1 view
Skip to first unread message

scit...@googlecode.com

unread,
Dec 29, 2013, 3:21:20 AM12/29/13
to scitoo...@googlegroups.com
Revision: 2da3ae921749
Branch: default
Author: "Hans Petter Langtangen <h...@simula.no>"
Date: Sun Dec 29 08:20:59 2013 UTC
Log: updates
http://code.google.com/p/scitools/source/detail?r=2da3ae921749&repo=wiki

Modified:
/EasyvizDocumentation.wiki

=======================================
--- /EasyvizDocumentation.wiki Fri Sep 10 10:37:59 2010 UTC
+++ /EasyvizDocumentation.wiki Sun Dec 29 08:20:59 2013 UTC
@@ -1,13 +1,12 @@
#summary Easyviz Documentation
-#labels Featured
-<wiki:toc max_depth="4" />

-<wiki:comment> TITLE: Easyviz Documentation </wiki:comment>
-<wiki:comment> AUTHOR: H. P. Langtangen at Simula Research Laboratory and
Univ. of Oslo </wiki:comment>
-<wiki:comment> AUTHOR: J. H. Ring at Simula Research Laboratory and Univ.
of Oslo </wiki:comment>
-<wiki:comment> DATE: Aug 08, 2008 </wiki:comment>
+By *H. P. Langtangen* and *J. H. Ring*

+==== Aug 31, 2012 ====

+<wiki: toc max_depth="2" />
+
+

== Easyviz ==

@@ -34,7 +33,7 @@
annoying for plotting. Easyviz was therefore also made to ease the
switch between Python and Matlab.

-If you encounter problems with using Easyviz, please visit the
+If you encounter problems with using Easyviz, please visit the
*Troubleshooting* chapter and the *Installation* chapter at the
end of the documentation.

@@ -43,31 +42,24 @@
The present documentation is available in a number of formats:


- * [https://scitools.googlecode.com/svn/trunk/doc/easyviz/easyviz.pdf PDF]
- * [http://www.simula.no/~hpl/easyviz/easyviz.html Plain HTML]
- * [http://www.simula.no/~hpl/easyviz/easyviz_sphinx_html/html/index.html
Sphinx HTML]
- * [https://scitools.googlecode.com/svn/trunk/doc/easyviz/easyviz.txt
Plain text]
+ * [https://scitools.googlecode.com/hg/doc/easyviz/easyviz.pdf PDF]
+ * [https://scitools.googlecode.com/hg/doc/easyviz/easyviz.html Plain
HTML]
+ *
[https://scitools.googlecode.com/hg/doc/easyviz/easyviz_sphinx_html/index.html
Sphinx HTML]
+ * [https://scitools.googlecode.com/hg/doc/easyviz/easyviz.txt Plain text]
* [http://code.google.com/p/scitools/wiki/EasyvizDocumentation Wiki]
- * [https://scitools.googlecode.com/svn/trunk/doc/easyviz/easyviz.do.txt
Doconce source]
+ * [https://scitools.googlecode.com/hg/doc/easyviz/easyviz.do.txt Doconce
source]

-The documentation is written in the [http://code.google.com/p/doconce
Doconce]
-format and can be translated into a number of different formats (reST,
-Sphinx, LaTeX, HTML, XML, OpenOffice, RTF, Word, and plain untagged ASCII).
-
-
-<wiki:comment> URLs to files with HTML code does not work well with
googlecode and svn: </wiki:comment>
-
-<wiki:comment> *
[https://scitools.googlecode.com/svn/trunk/doc/easyviz/easyviz.pdf PDF]
</wiki:comment>
-<wiki:comment> *
[https://scitools.googlecode.com/svn/trunk/doc/easyviz/easyviz.html Plain
HTML] </wiki:comment>
-<wiki:comment> *
[https://scitools.googlecode.com/svn/trunk/doc/easyviz/easyviz_sphinx_html/index.html
Sphinx HTML] </wiki:comment>
-<wiki:comment> *
[https://scitools.googlecode.com/svn/trunk/doc/easyviz/easyviz.txt Plain
text] </wiki:comment>
-<wiki:comment> *
[http://code.google.com/p/scitools/wiki/EasyvizDocumentation Wiki]
</wiki:comment>
-<wiki:comment> *
[https://scitools.googlecode.com/svn/trunk/doc/easyviz/easyviz.do.txt
Doconce source] </wiki:comment>
+The documentation is written in the
+[http://code.google.com/p/doconce Doconce]
+format and can be translated into a
+number of different formats (reST, Sphinx, LaTeX, HTML, XML,
+OpenOffice, RTF, Word, and plain untagged ASCII).

==== Guiding Principles ====

*First principle.* Array data can be plotted with a minimal
set of keystrokes using a Matlab-like syntax. A simple
+
{{{
t = linspace(0, 3, 51) # 51 points between 0 and 3
y = t**2*exp(-t**2)
@@ -94,8 +86,8 @@
ylabel('y')
show()

-hardcopy('tmp0.ps') # this one can be included in LaTeX
-hardcopy('tmp0.png') # this one can be included in HTML
+hardcopy('tmp0.eps') # this one can be included in LaTeX
+hardcopy('tmp0.png') # this one can be included in HTML
}}}
Easyviz also allows these additional function calls to be executed
as a part of the `plot` call:
@@ -105,10 +97,10 @@
title='Simple Plot Demo',
axis=(0, 3, -0.05, 0.6),
xlabel='t', ylabel='y',
- hardcopy='tmp1.ps',
+ hardcopy='tmp1.eps',
show=True)

-hardcopy('tmp0.png') # this one can be included in HTML
+hardcopy('tmp0.png')
}}}
A scalar function `f(x,y)` may be visualized
as an elevated surface with colors using these commands:
@@ -166,49 +158,95 @@
`plot(x,y)` command. Then we add a legend, axis labels, a title, etc.
Thereafter we show how multiple curves are plotted together. We also
explain how line styles and axis range can be controlled. The
-next section deals with animations and making movie files. More advanced
-topics such as fine tuning of plots (using plotting package-specific
-commands) and working with Axis and Figure objects close the curve
+next topic deals with animations and making movie files. More advanced
+subjects, such as fine tuning of plots (using plotting package-specific
+commands) and working with Axis and Figure objects, close the curve
plotting part of the tutorial.

Various methods for visualization of scalar fields in 2D and 3D are
treated next, before we show how 2D and 3D vector fields can be handled.

+==== A Note on Import Statements ====
+
+The recommended standard import of `numpy`
+and `matplotlib` in programs reads:
+{{{
+import numpy as np
+import matplotlib.pyplot as plt
+}}}
+This import ensures that all functionality from different packages are
+prefixed by a short form of the package name. This convention has,
+from a computer science perspective, many advantages as one sees
+clearly where functionality comes from. However, convincing
+scientists with extensive Matlab, Fortran, or C++ experience to switch
+to Python can be hard when mathematical formulas are full of `np.`
+prefixes and all plotting commands are decorated with an "extra"
+`plt.` The developers of Easyviz think it is a major point to have
+Python code as close to Matlab and standard mathematical syntax as
+possible. Therefore, examples in this manual employ the "star
+import":
+{{{
+from scitools.std import *
+}}}
+This statement imports the Easyviz plotting commands and also performs
+`from numpy import *`. Hence, mathematical functions like `sin` and
+`log` are available and work for arrays, as in Matlab, and the plotting
+commands are the same as those in Matlab. This type of import statement
+is similar to the popular
+{{{
+from matplotlib.pylab import *
+}}}
+among Matplotlib users (although not promoted by Matplotlib developers).
+The primary additional feature of the
+`scitools.std` import is the possibility to choose among many different
+backends for plotting, where Matplotlib is one of the options.
+
==== Plotting a Single Curve ====

Let us plot the curve `y = t**2*exp(-t**2)` for
`t` values between 0 and 3. First we generate equally spaced
-coordinates for `t`, say 51 values (50 intervals). Then we compute the
+coordinates for `t`, say 31 values (30 intervals). Then we compute the
corresponding `y` values at these points, before we call the
`plot(t,y)` command to make the curve plot. Here is the complete
program:
+
{{{
from scitools.std import *

def f(t):
return t**2*exp(-t**2)

-t = linspace(0, 3, 51) # 51 points between 0 and 3
+t = linspace(0, 3, 31) # 31 points between 0 and 3
y = zeros(len(t)) # allocate y with float elements
for i in xrange(len(t)):
y[i] = f(t[i])

plot(t, y)
+show() # optional
}}}
+If you have problems running this file, make sure you have installed
+SciTools and one or more plotting programs, see the chapter
[#Installation].
+
The first line imports all of SciTools and Easyviz that can be handy
-to have when doing scientific computations. In this program we
+to have when doing scientific computations. This includes everything
+from `numpy` (from `numpy import *`),
+all Easyviz plotting commands, some modules (`sys`, `math`), and
+all of SciPy (`from scipy import *`) if SciPy is installed.
+In the program above, we first
pre-allocate the `y` array and fill it with values, element by
element, in a Python loop. Alternatively, we may operate
on the whole `t` array at once, which yields faster and shorter code:
+
{{{
from scitools.std import *

def f(t):
return t**2*exp(-t**2)

-t = linspace(0, 3, 51) # 51 points between 0 and 3
+t = linspace(0, 3, 31) # 31 points between 0 and 3
y = f(t) # compute all f values at once
plot(t, y)
+show() # optional
}}}
The `f` function can also be skipped, if desired, so that we can write
directly
@@ -217,28 +255,48 @@
}}}

To include the plot in electronic documents, we need a hardcopy of the
-figure in PostScript, PNG, or another image format. The `hardcopy`
+figure in PostScript, PNG, or another image format. The `savefig`
command produces files with images in various formats:
+{{{
+savefig('tmp1.eps') # produce PostScript
+savefig('tmp1.png') # produce PNG
+}}}
+An alternative name for `savefig` is `hardcopy`:
{{{
hardcopy('tmp1.eps') # produce PostScript
hardcopy('tmp1.png') # produce PNG
}}}
The filename extension determines the format: `.ps` or
-`.eps` for PostScript, and `.png` for PNG.
-Figure fig:plot1a displays the resulting plot.
+`.eps` for PostScript, and `.png` for PNG.
+Figures fig:plot1a:g and fig:plot1a:m display the resulting
+image file with the plot, as generated
+with the Gnuplot and Matplotlib plotting packages, respectively.
+With `show(False)`
+we can suppress the plot from being shown at the screen, which is
+useful when creating a large number of figure files in programs.



---------------------------------------------------------------

-Figure: A simple plot in PostScript format. (fig:plot1a)
+Figure: Default plot generated by Gnuplot. (fig:plot1a:g)

-https://scitools.googlecode.com/svn/trunk/lib/scitools/easyviz/doc/figs/plot1a.png
+https://scitools.googlecode.com/hg/doc/easyviz/figs/plot1a_g.png

-<wiki:comment>
-Put the figure file figs/plot1a.png on the web (e.g., as part of the
-googlecode repository) and substitute the line above with the URL.
-</wiki:comment>
+
+---------------------------------------------------------------
+
+
+
+
+
+---------------------------------------------------------------
+
+Figure: Default plot generated by Matplotlib. (fig:plot1a:m)
+
+https://scitools.googlecode.com/hg/doc/easyviz/figs/plot1a_m.png
+
+
---------------------------------------------------------------


@@ -255,16 +313,98 @@
terminates, and this satement postpones the termination until the user
hits the Return key.

+==== Controlling Line Styles ====
+
+By default, Easyviz plots a curve with a solid line of thickness 2 and
+markers of size 2 at each data point. This default behavior is
+inspired by the usual needs to include thicker lines and markers to
+distinguish multiple curves plots, especially if image files are to
+appear in black and white in printed reports. However, the line style
+can easily be controlled by adding a string `s` after the `y`
+argument: `plot(x, y, s)`. The syntax of the string `s` is inspired by
+Matlab. For example, `r-` means a red solid line of unit thickness
+(see Figure fig:plot1a:rs), `r--` means a red dashed line, `r-o`
+means a red solid line with circles as markers at each data point,
+`r--o` is the same except that the line is dashed. In general, if `s`
+is `clms`, the first character `c` is the color, `l` is the line type,
+`m` is the marker type, and `s` is the size of the line and marker. A
+blue line with thickness 6 and cross symbols as markers of size 6 is
+specified by `b-x6`. The effect of the given line thickness and
+symbol size depends on the underlying plotting program. One can omit
+the line type or color: `yo` specifies yellow circles and `-` gives
+solid line of thickness 1 and default color .
+
+
+
+---------------------------------------------------------------
+
+Figure: Red solid line. (fig:plot1a:rs)
+
+https://scitools.googlecode.com/hg/doc/easyviz/figs/plot1a2.png
+
+
+---------------------------------------------------------------
+
+
+
+The different available line colors include
+
+ * yellow: `'y'`
+ * magenta: `'m'`
+ * cyan: `'c'`
+ * red: `'r'`
+ * green: `'g'`
+ * blue: `'b'`
+ * white: `'w'`
+ * black: `'k'`
+
+The different available line types are
+
+ * solid line: `'-'`
+ * dashed line: `'--'`
+ * dotted line: `':'`
+ * dash-dot line: `'-.'`
+
+Lots of markers at data points are available:
+
+ * plus sign: `'+'`
+ * circle: `'o'`
+ * asterisk: `'*'`
+ * point: `'.'`
+ * cross: `'x'`
+ * square: `'s'`
+ * diamond: `'d'`
+ * upward-pointing triangle: `'^'`
+ * downward-pointing triangle: `'v'`
+ * right-pointing triangle: `'>'`
+ * left-pointing triangle: `'<'`
+ * five-point star (pentagram): `'p'`
+ * six-point star (hexagram): `'h'`
+ * no marker (default): `None`
+
+During programming, you can find all these details in the
+documentation of the `plot` function. Just type `help(plot)`
+in an interactive Python shell or invoke `pydoc` with
+`scitools.easyviz.plot`. This tutorial is available
+through `pydoc scitools.easyviz`.
+
+We remark that in the Gnuplot program all the different line types are
+drawn as solid lines on the screen. The hardcopy chooses automatically
+different line types (solid, dashed, etc.) and not in accordance with
+the line type specification.
+
==== Decorating the Plot ====

-The `x` and `y` axis in curve plots should have labels, here `t` and
+The `x` and `y` axes in curve plots should have labels, here `t` and
`y`, respectively. Also, the curve should be identified with a label,
or legend as it is often called. A title above the plot is also
common. In addition, we may want to control the extent of the axes
(although
most plotting programs will automatically adjust the axes to the range of
the
data).
All such things are easily added after the `plot` command:
+
{{{
+plot(x, y, 'r-')
xlabel('t')
ylabel('y')
legend('t^2*exp(-t^2)')
@@ -275,42 +415,93 @@
Easyviz and Matlab almost trivial.
Easyviz has also introduced a more "Pythonic" `plot` command where
all the plot properties can be set at once:
+
{{{
-plot(t, y,
+plot(t, y, 'r-',
xlabel='t',
ylabel='y',
legend='t^2*exp(-t^2)',
axis=[0, 3, -0.05, 0.6],
title='My First Easyviz Demo',
- hardcopy='tmp1.eps',
+ savefig='tmp1.eps', # or hardcopy='tmp1.eps'
show=True)
}}}

With `show=False` one can avoid the plot window on the screen and
just make the hardcopy. This feature is particularly useful if
-one generates a large number of plots in a loop.
+one generates a large number of separate figures in the program.
+The keyword `savefig` can be replaced by `hardcopy` if desired.

Note that we in the curve legend write `t` square as `t^2` (LaTeX style)
rather than `t**2` (program style). Whichever form you choose is up to
you, but the LaTeX form sometimes looks better in some plotting
-programs (Gnuplot is one example).
+programs (Matplotlib and Gnuplot are two examples).
See Figure fig:plot1c for what the modified
plot looks like and how `t^2` is typeset in Gnuplot.

+
+
+
+---------------------------------------------------------------
+
+Figure: A single curve with label, title, and axes adjusted. (fig:plot1c)
+
+https://scitools.googlecode.com/hg/doc/easyviz/figs/plot1c.png
+
+
+---------------------------------------------------------------
+
+==== Using Logarithmic Scales ====
+
+Sometimes logarithmic scales are need on the `x` or `y` axis. This is
+easily specified by replacing `plot(x,y)` by `loglog(x,y)`,
`semilogx(x,y)`,
+or `semilogy(x,y)` for the three cases of logarithmic scales on both axes,
+on the `x` axis only, or on the `y` axis only. A complete
+example, displayed in Figure fig:plot1d, reads
+
+{{{
+def f(t):
+ return exp(-t**2)
+
+t = linspace(0, 3, 51) # 51 points between 0 and 3
+y = f(t)
+semilogy(t, y, 'r-2')
+
+xlabel('t')
+ylabel('y')
+legend('exp(-t^2)')
+title('Logarithmic scale on the y axis')
+}}}



---------------------------------------------------------------

-Figure: A single curve with label, title, and axis adjusted. (fig:plot1c)
+Figure: Logarithmic scale on one axis. (fig:plot1d)
+
+https://scitools.googlecode.com/hg/doc/easyviz/figs/plot1d.png

-https://scitools.googlecode.com/svn/trunk/lib/scitools/easyviz/doc/figs/plot1c.png

-<wiki:comment>
-Put the figure file figs/plot1c.png on the web (e.g., as part of the
-googlecode repository) and substitute the line above with the URL.
-</wiki:comment>
---------------------------------------------------------------
+
+
+
+The specification of
+logarithmic scales can also be done through keyword arguments to the
+`plot` function: `log='xy'`, `log='x'`, or `log='y'`, which should
+be self-explaining syntax. The following call produces the same plot
+as above.
+
+{{{
+plot(t, y, 'r-2',
+ log='y',
+ xlabel='t',
+ ylabel='y',
+ legend='exp(-t^2)',
+ title='Logarithmic scale on the y axis',
+ savefig='tmp1.png',
+ show=True)
+}}}

==== Plotting Multiple Curves ====

@@ -323,6 +514,7 @@
issue a `hold('on')` command. Alternatively, we can provide all
data in a single `plot` command. A complete program illustrates the
different approaches:
+
{{{
from scitools.std import * # for curve plotting

@@ -336,7 +528,7 @@
y1 = f1(t)
y2 = f2(t)

-# Matlab-style syntax:
+# Matlab-style syntax
plot(t, y1)
hold('on')
plot(t, y2)
@@ -345,50 +537,143 @@
ylabel('y')
legend('t^2*exp(-t^2)', 't^4*exp(-t^2)')
title('Plotting two curves in the same plot')
-hardcopy('tmp2.eps')
+savefig('tmp2.eps') # or hardcopy('tmp2.eps')

-# alternative:
+# Alternative "Pythonic" style
plot(t, y1, t, y2, xlabel='t', ylabel='y',
legend=('t^2*exp(-t^2)', 't^4*exp(-t^2)'),
title='Plotting two curves in the same plot',
- hardcopy='tmp2.eps')
+ savefig='tmp2.eps')
}}}
-The sequence of the multiple legends is such that the first legend
+The sequence of the multiple legends is such that the first legend
corresponds to the first curve, the second legend to the second curve,
-and so on. The visual result appears in Figure fig:plot2a.
+and so on. The visual result appears in Figures fig:plot2a
+and fig:plot2a:gp.

Doing a `hold('off')` makes the next `plot` command create a new
-plot.
+plot in the same window. This new plot just erases the previous curves.
+
+
+
+---------------------------------------------------------------
+
+Figure: Two curves in the same plot, PNG file produced by Gnuplot.
(fig:plot2a)
+
+https://scitools.googlecode.com/hg/doc/easyviz/figs/plot2a.png
+
+
+---------------------------------------------------------------
+
+
+
+
+
+---------------------------------------------------------------
+
+Figure: Two curves in the same plot, PostScript file produced by Gnuplot.
(fig:plot2a:gp)
+
+https://scitools.googlecode.com/hg/doc/easyviz/figs/plot2a_gp.png
+
+
+---------------------------------------------------------------
+
+
+
+With the keyword argrument `grid=True` to `plot` we can add a
+grid, which is frequently used when plotting curves (see
+Figure fig:plot2f).
+


+---------------------------------------------------------------
+
+Figure: Curves with a grid. (fig:plot2f)
+
+https://scitools.googlecode.com/hg/doc/easyviz/figs/plot2f.png
+

---------------------------------------------------------------

-Figure: Two curves in the same plot. (fig:plot2a)

-https://scitools.googlecode.com/svn/trunk/lib/scitools/easyviz/doc/figs/plot2a.png

-<wiki:comment>
-Put the figure file figs/plot2a.png on the web (e.g., as part of the
-googlecode repository) and substitute the line above with the URL.
-</wiki:comment>
+The default location of the legends is dependent on the backend
+(some have a fixed location, like Gnuplot, and some try to find
+the most optimal location, like Matplotlib). One can control
+the location by the `loc` keyword to the `legend` function, e.g.,
+{{{
+legend('t^2*exp(-t^2)', 't^4*exp(-t^2)', loc='upper left')
+}}}
+The most popular values are upper right, upper left, lower left,
+and lower right, depending on the shape of the curves and extend
+of the axes. The keyword argument `fancybox` draws a box around
+the legends if `True`, otherwise no box is drawn. The corresponding
+keywords for the `plot` function are `legend_loc` and `legend_fancybox`:
+{{{
+plot(t, y1, t, y2, xlabel='t', ylabel='y',
+ legend=('t^2*exp(-t^2)', 't^4*exp(-t^2)'),
+ legend_loc=`upper left`, legend_fancybox=True,
+ axis=[0, 4, -0.1, 0.8],
+ title='Plotting two curves in the same plot',
+ savefig='tmp2.eps')
+}}}
+The `loc` and `fancybox` specifications work (at present)
+with Gnuplot and Matplotlib only.
+
+
+
+
---------------------------------------------------------------

-==== Controlling Line Styles ====
+Figure: A figure with legends placed to the upper left with a box frame.
+
+https://scitools.googlecode.com/hg/doc/easyviz/figs/plot2l.png
+
+
+---------------------------------------------------------------
+
+
+
+The `legend` function also accepts a list of legends instead of
+the legends as separate positional arguments. This allows an overlapping
+syntax between Matplotlib and Easyviz so that the same code can apply
+either of the packages (however, Matplotlib's keywords to
+`plot`, like `label` and `linewidth`, are not recognized so not all
+syntax is interchangable).
+
+==== Making Multiple Figures ====
+
+The `hold` command either adds a new curve or replaces old curve(s) by
+new ones. Often one wants to make multiple figures in a program,
+realized as multiple windows on the screen. The `figure()` command
+creates a new figure:
+{{{
+x = linspace(-2, 2, 81)
+y1 = sin(pi*x)*exp(-0.5*x**2)
+plot(x, y1)
+
+figure() # separate plot window
+y2 = sin(pi*x/2)*exp(-0.5*x**2)
+plot(x, y2)
+
+figure() # yet another plot window
+y3 = sin(pi*x/4)*exp(-0.5*x**2)
+plot(x, y3)
+}}}
+More information in the `figure` command is found later on under the
+heading *Working with Axis and Figure Objects*.

When plotting multiple curves in the same plot, the individual curves
get distinct default line styles, depending on the program that is
used to produce the curve (and the settings for this program). It
might well happen that you get a green and a red curve (which is bad
for a significant portion of the male population). Therefore,
-we often want to control the line style in detail. Say we want the first
-curve (`t` and `y1`) to be drawn as a red solid line and the second
-curve (`t` and `y2`) as blue circles at the discrete data points. The
-Matlab-inspired syntax for specifying line types applies a letter for
-the color and a symbol from the keyboard for the line type. For
-example, `r-` represents a red (`r`) line (`-`), while `bo` means blue
-(`b`) circles (`o`). The line style specification is added as an
-argument after the `x` and `y` coordinate arrays of the curve:
+we often want to control the line style in detail when plotting
+multiple curves.
+
+Say we want the first curve (`t` and `y1`) to be drawn as a red solid
+line (`r-`) and the second curve (`t` and `y2`) as blue circles (`bo`) at
the
+discrete data points:
+
{{{
plot(t, y1, 'r-')
hold('on')
@@ -397,21 +682,17 @@
# or
plot(t, y1, 'r-', t, y2, 'bo')
}}}
-The effect of controlling the line styles can be seen in
-Figure fig:plot2c.
+The resulting effect can be seen in Figure fig:plot2c.



---------------------------------------------------------------

-Figure: Two curves in the same plot, with controlled line styles.
(fig:plot2c)
+Figure: Two curves in the same plot, with controlled line styles.
(fig:plot2c)

-https://scitools.googlecode.com/svn/trunk/lib/scitools/easyviz/doc/figs/plot2c.png
+https://scitools.googlecode.com/hg/doc/easyviz/figs/plot2c.png

-<wiki:comment>
-Put the figure file figs/plot2c.png on the web (e.g., as part of the
-googlecode repository) and substitute the line above with the URL.
-</wiki:comment>
+
---------------------------------------------------------------


@@ -422,6 +703,7 @@
first to the last data point, while the second colon separates this
range from the stride, i.e., how many points we should "jump over"
when we pick out a set of values of the array.
+
{{{
from scitools.std import *

@@ -454,72 +736,20 @@

---------------------------------------------------------------

-Figure: Circles at every 4 points and extended line thickness (6) and
circle size (3). (fig:plot2g)
+Figure: Circles at every 4 points and extended line thickness (6) and
circle size (3). (fig:plot2g)

-https://scitools.googlecode.com/svn/trunk/lib/scitools/easyviz/doc/figs/plot2g.png
+https://scitools.googlecode.com/hg/doc/easyviz/figs/plot2g.png

-<wiki:comment>
-Put the figure file figs/plot2g.png on the web (e.g., as part of the
-googlecode repository) and substitute the line above with the URL.
-</wiki:comment>
+
---------------------------------------------------------------




-The different available line colors include
-
- * yellow: `'y'`
- * magenta: `'m'`
- * cyan: `'c'`
- * red: `'r'`
- * green: `'g'`
- * blue: `'b'`
- * white: `'w'`
- * black: `'k'`
-
-The different available line types are
-
- * solid line: `'-'`
- * dashed line: `'--'`
- * dotted line: `':'`
- * dash-dot line: `'-.'`
-
-During programming, you can find all these details in the
-documentation of the `plot` function. Just type `help(plot)`
-in an interactive Python shell or invoke `pydoc` with
-`scitools.easyviz.plot`. This tutorial is available
-through `pydoc scitools.easyviz`.
-
-We remark that in the Gnuplot program all the different line types are
-drawn as solid lines on the screen. The hardcopy chooses automatically
-different line types (solid, dashed, etc.) and not in accordance with
-the line type specification.
-
-Lots of markers at data points are available:
-
- * plus sign: `'+'`
- * circle: `'o'`
- * asterisk: `'*'`
- * point: `'.'`
- * cross: `'x'`
- * square: `'s'`
- * diamond: `'d'`
- * upward-pointing triangle: `'^'`
- * downward-pointing triangle: `'v'`
- * right-pointing triangle: `'>'`
- * left-pointing triangle: `'<'`
- * five-point star (pentagram): `'p'`
- * six-point star (hexagram): `'h'`
- * no marker (default): `None`
-
-Symbols and line styles may be combined, for instance as in `'kx-'`,
-which means a black solid line with black crosses at the data points.
-
-
*Another Example.* Let us extend the previous example with a third
curve where the data points are slightly randomly distributed around
the `f_2(t)` curve:
+
{{{
from scitools.std import *

@@ -533,7 +763,7 @@
y1 = f1(t)
y2 = f2(t)

-# pick out each 4 points and add random noise:
+# Pick out each 4 points and add random noise
t3 = t[::4] # slice, stride 4
random.seed(11) # fix random sequence
noise = random.normal(loc=0, scale=0.02, size=len(t3))
@@ -550,8 +780,8 @@
xlabel('t')
ylabel('y')
show()
-hardcopy('tmp3.eps')
-hardcopy('tmp3.png')
+savefig('tmp3.eps') # or hardcopy
+savefig('tmp3.png') # or hardcopy
}}}
The plot is shown in Figure fig:plot3.

@@ -559,14 +789,11 @@

---------------------------------------------------------------

-Figure: A plot with three curves. (fig:plot3)
+Figure: A plot with three curves. (fig:plot3)

-https://scitools.googlecode.com/svn/trunk/lib/scitools/easyviz/doc/figs/plot3.png
+https://scitools.googlecode.com/hg/doc/easyviz/figs/plot3.png
+

-<wiki:comment>
-Put the figure file figs/plot3.png on the web (e.g., as part of the
-googlecode repository) and substitute the line above with the URL.
-</wiki:comment>
---------------------------------------------------------------


@@ -575,6 +802,7 @@
are interested in the quickest possible commands.
Here is an example of minimalistic syntax for
comparing the two sample functions we have used in the previous examples:
+
{{{
t = linspace(0, 3, 51)
plot(t, t**2*exp(-t**2), t, t**4*exp(-t**2))
@@ -589,6 +817,18 @@
additional examples, can be found in the `examples` directory in the
root directory of the SciTools source code tree.

+==== Math Syntax in Legends and Titles ====
+
+Some backends understand some mathematical syntax. Easyviz accepts
+LaTeX-style syntax and translates it to something appropriate for the
+background in question. As a rule of thumb, write plain LaTeX syntax
+if you need mathematical symbols and expressions in legends and
+titles. Matplotlib will show the result in an excellent way, Gnuplot
+PostScript output will handle super- and subscripts as well as greek
+letters. All other backends will strip off backslashes, dollar signs,
+curly braces, qand other annoying LaTeX syntax. Normally, power
+expressions with double multiplication symbols are replaced by a hat.
+
==== Interactive Plotting Sessions ====

All the Easyviz commands can of course be issued in an interactive
@@ -626,7 +866,7 @@
individual plot files into a movie file.

*Example.* The function
-`f(x; m,s) = 1/(sqrt(2*pi)*s)*exp(-0.5*((x-m)/s)**2)`
+`f(x; m,s) = 1/(sqrt(2*pi)*s)*exp(-0.5*((x-m)/s)**2)`
is known as the Gaussian function or the probability density function
of the normal (or Gaussian) distribution. This bell-shaped function is
"wide" for large `s` and "peak-formed" for small `s`, see Figure
@@ -639,14 +879,11 @@

---------------------------------------------------------------

-Figure: Different shapes of a Gaussian function. (fig:plot4)
+Figure: Different shapes of a Gaussian function. (fig:plot4)
+
+https://scitools.googlecode.com/hg/doc/easyviz/figs/plot4.png

-https://scitools.googlecode.com/svn/trunk/lib/scitools/easyviz/doc/figs/plot4.png

-<wiki:comment>
-Put the figure file figs/plot4.png on the web (e.g., as part of the
-googlecode repository) and substitute the line above with the URL.
-</wiki:comment>
---------------------------------------------------------------


@@ -661,7 +898,7 @@
below, but before diving into the code we need to comment upon a
couple of issues with setting up the `plot` command for animations.

-The underlying plotting program will normally adjust the axis to the
+The underlying plotting program will normally adjust the `y` axis to the
maximum and minimum values of the curve if we do not specify the axis
ranges explicitly. For an animation such automatic axis adjustment is
misleading - the axis ranges must be fixed to avoid a jumping
@@ -677,6 +914,7 @@
Now we are ready to take a look at the complete code
for animating how the Gaussian function evolves as the `s` parameter
is decreased from 2 to 0.2:
+
{{{
from scitools.std import *
import time
@@ -692,8 +930,8 @@
# f is max for x=m; smaller s gives larger max value
max_f = f(m, m, s_stop)

-# show the movie on the screen
-# and make hardcopies of frames simultaneously:
+# Show the movie on the screen
+# and make hardcopies of frames simultaneously
counter = 0
for s in s_values:
y = f(x, m, s)
@@ -703,7 +941,7 @@
counter += 1
#time.sleep(0.2) # can insert a pause to control movie speed

-# make movie file the simplest possible way:
+# Make movie file the simplest possible way
movie('tmp*.png')
}}}

@@ -722,16 +960,16 @@
now expand (by an alphabetic sort) to a list of all files in proper
order. Without the padding with zeros, i.e., names of the form
`tmp1.png`, `tmp2.png`, ..., `tmp12.png`, etc., the alphabetic order
-will give a wrong sequence of frames in the movie. For instance,
+will give a wrong sequence of frames in the movie. For instance,
`tmp12.png` will appear before `tmp2.png`.

Note that the names of plot files specified when making hardopies must
be consistent with the specification of names in the call to `movie`.
Typically, one applies a Unix wildcard notation in the call to
-`movie`, say `plotfile*.eps`, where the asterisk will match any set of
+`movie`, say `plotfile*.png`, where the asterisk will match any set of
characters. When specifying hardcopies, we must then use a filename
-that is consistent with `plotfile*.eps`, that is, the filename must
-start with `plotfile` and end with `.eps`, but in between
+that is consistent with `plotfile*.png`, that is, the filename must
+start with `plotfile` and end with `.png`, but in between
these two parts we are free to construct (e.g.) a frame number padded
with zeros.

@@ -749,63 +987,87 @@
and later delete the subfolder. Here is a suitable code segment:
{{{
import shutil, os
-subdir = 'temp' # subfolder for plot files
+subdir = 'temp' # name of subfolder for plot files
if os.path.isdir(subdir): # does the subfolder already exist?
shutil.rmtree(subdir) # delete the whole folder
-os.mkdir(subdir) # make new subfolder
-os.chdir(subdir) # move to subfolder
-# do all the plotting
-# make movie
-os.chdir(os.pardir) # optional: move up to parent folder
+os.mkdir(subdir) # make new subfolder
+os.chdir(subdir) # move to subfolder
+# ...perform all the plotting...
+# ...make movie...
+os.chdir(os.pardir) # optional: move up to parent folder
}}}

*Movie Formats.* Having a set of (e.g.) `tmp*.png` files, one can simply
generate a movie by
-a `movie('tmp*.png')` call. The `movie` function generates a movie
-file called `movie.avi` (AVI format), `movie.mpeg` (MPEG format), or
-`movie.gif` (animated GIF format) in the current working
-directory. The movie format depends on the encoders found on your
-machine.
+a `movie('tmp*.png')` call. The format of the movie is determined by
+which video encoders that are installed on the computer. The `movie`
+function runs through a list of encoders (`convert`, `mencoder`,
+`ffmpeg mpeg_encode`, `ppmtompeg`, `mpeg2enc`, `html`) and choses the
+first one which is installed. The fall back encoder `html` actually
+does not create a video file, but makes insetad an HTML file that can
+play the series of hardcopies made (`tmp*.png`, for instance).
+When no filename is given to the `movie` function, the output file
+with the movie has filestem `movie` and extension depending on the
+video format and the encoder used. For example, if `convert` was used
+to create an animated GIF file, the default output file is `movie.gif`.
+Similarly, `movie.avi` is in AVI format, `movie.mpeg` is in MPEG format,
+and so forth.

-You can get complete control of the movie format and the
-name of the movie file by supplying more arguments to the
-`movie` function. First, let us generate an animated GIF
-file called `tmpmovie.gif`:
+You can get complete control of the movie format and the name of the
+movie file by supplying the `encoder` and `output_file` arguments to
+the `movie` function. This is the recommended use. Here is an
+example on generating an animated GIF file `tmpmovie.gif` with
+the `convert` program from the ImageMagick software suite:
{{{
-movie('tmp_*.eps', encoder='convert', fps=2,
+movie('tmp_*.png', encoder='convert', fps=2,
output_file='tmpmovie.gif')
}}}
-The generation of animated GIF images applies the `convert` program
-from the ImageMagick suite. This program must of course be installed
-on the machine. The argument fps stands for frames per second so
-here the speed of the movie is slow in that there is a delay of half
-a second between each frame (image file).
-To view the animated GIF file, one can use the `animate`
-program (also from ImageMagick) and give the movie file as command-line
-argument. One can alternatively put the GIF file in a web page
-in an IMG tag such that a browser automatically displays the movie.
+This call requires ImageMagick to be installed on the machine. The
+argument `fps` stands for frames per second so here the speed of the
+movie is slow in that there is a delay of half a second between each
+frame (image file). To view the animated GIF file, one can use the
+`animate` program (also from ImageMagick) and give the movie file as
+command-line argument. One can alternatively put the GIF file in a web
+page in an IMG tag such that a browser automatically displays the
+movie.
+
+Making an HTML file that can play the movie in a web browser
+is carried out by the call
+{{{
+movie('tmp_*.png', encoder='html', fps=10,
+ output_file='tmpmovie.html')
+}}}
+Just load `tmpmovie.html` into a browser (e.g., run `firefox tmpmovie.html`
+from the command line).

An AVI movie can be generated by the call
{{{
-movie('tmp_*.eps', encoder='ffmpeg', fps=4,
- output_file='tmpmovie1.avi',
+movie('tmp_*.png', encoder='ffmpeg', fps=4,
+ output_file='tmpmovie.avi',
}}}
-Alternatively, we may generate an MPEG movie using
+Alternatively, we may generate an MPEG movie using
the `ppmtompeg` encoder from the Netpbm suite of
image manipulation tools:
{{{
-movie('tmp_*.eps', encoder='ppmtompeg', fps=24,
- output_file='tmpmovie2.mpeg',
+movie('tmp_*.png', encoder='ppmtompeg', fps=24,
***The diff for this file has been truncated for email.***
Reply all
Reply to author
Forward
0 new messages