With this backend one can create Matlab scripts (M-files) with Matlab commands from scripts with Easyviz commands. The interactive and show attributes are by default turned off in this backend and one should therefore call either show or hardcopy (both calling _replot) before saving the Matlab script with a call to save_m. To use this backend, one can run a script somefile.py like
python somefile.py –SCITOOLS_easyviz_backend matlab2
or one can specify the backend in the SciTools configuration file scitools.cfg under the [easyviz] section
[easyviz] backend = matlab2
and then
from scitools.std import *
or if just easyviz is needed
from scitools.easyviz import *
REQUIREMENTS:
No requirements
EXAMPLES:
We start with a simple example using the plot command:
>>> from scitools.std import *
>>> x = linspace(-2,2,5)
>>> plot(x,x**2,'b-s',title='Simple plot')
[<scitools.easyviz.common.Line object at 0xb7de244c>]
>>> print get_script()
>>>
As we can see, the result is no output. This is because the _replot method has not been called yet. However, we don’t need to call this method explicitly. Instead we should call either show or hardcopy (both of which calls _replot). Here we use show:
>>> show()
>>> print get_script()
figure(1)
clf('reset')
ax1 = gca;
x = [-2.0, -1.0, 0.0, 1.0, 2.0];
y = [4.0, 1.0, 0.0, 1.0, 4.0];
plot(x,y,'Color','b','LineStyle','-','Marker','s')
title('Simple plot'),...
set(gca, 'XScale', 'lin', 'YScale', 'lin'),...
axis normal,...
axis auto,...
axis xy,...
hidden on,...
caxis auto,...
view(2),...
xlabel(''),ylabel(''),zlabel(''),...
box on,...
grid off,...
axis on,...
>>>
We can now store these commands in a Matlab script by calling the save_m function:
>>> save_m('mytest.m')
In this case, the file mytest.m will be placed in the current working directory and we can then run the file in Matlab, e.g., with the following statement:
>>> os.system("matlab -nojvm -nosplash -r mytest")
Note that we skip the extension of the file name (.m). To get back to the Python prompt, we must first exit Matlab.
Now we create a contour plot in combination with a quiver plot:
>>> reset() # remove the previous Matlab commands
>>> xx, yy = ndgrid(linspace(-3,3,31), linspace(-3,3,31), sparse=False)
>>> zz = peaks(xx, yy)
>>> contour(xx,yy,zz,12,hold='on')
>>> uu, vv = gradient(zz)
>>> quiver(xx,yy,uu,vv,hold='off')
>>> hardcopy('tmp0.ps',color=True)
>>> save_m('mytest2.m')
Here, we begin by calling reset(). This ensures that the string with the Matlab commands is empty before we start calling different plotting commands. After calling contour and quiver, we use the hardcopy command to store the plot to a PostScript file. As mentioned above, hardcopy calls _replot so there is no need to call show in this case. At the end we call save_m to store the Matlab commands in the file mytest2.m. We can then run the script as we did above:
>>> os.system("matlab -nojvm -nosplash -r 'mytest2;quit'")
In this case, we will be brought back to the Python prompt once Matlab has stored the plot in the file tmp0.ps.
NOTES:
Bases: scitools.easyviz.common.BaseClass
Methods
autumn([m]) | Shades of red and yellow color map. |
axes(*args, **kwargs) | Create axes in specified positions. |
axis(*args, **kwargs) | Choose the axis limits and appearance. |
bar(*args, **kwargs) | Draw a bar graph. |
bone([m]) | Gray-scale with a tinge of blue color map. |
box(*args) | Display a box around the boundaries of the current axis. |
brighten(*args) | Brighten or darken the color map. |
camdolly(*args) | Dolly camera. |
camlight(*args, **kwargs) | Create or set position of a light. |
camlookat(*args) | Move camera and target to view specified objects. |
campos(*args) | Camera position. |
camproj(*args) | Camera projection. |
camroll(*args) | Roll camera. |
camtarget(*args) | Camera target. |
camup(*args) | Camera up vector. |
camva(*args) | Camera view angle. |
camzoom(*args) | Zoom camera. |
caxis(*args) | Set the limits for the color axis. |
cla(*args) | Clear the current axis. |
clabel(*args) | Control labeling of contours. |
clf() | Clear the current figure. |
close(*args) | Close figure. |
closefig([arg]) | Close figure window. |
closefigs() | Close all figure windows. |
colorbar(*args) | Display a color bar. |
colorcube([m]) | Enhanced color-cube color map. |
colormap(*args) | Specify colormap. |
coneplot(*args, **kwargs) | Draw a 3D cone plot. |
contour(*args, **kwargs) | Draw a 2D contour plot. |
contour3(*args, **kwargs) | Draw 3D contour plot. |
contourf(*args, **kwargs) | Draw filled contour plot. |
contourslice(*args, **kwargs) | Draw contour lines in slice planes. |
cool([m]) | Shades of cyan and magenta color map. |
copper([m]) | Linear copper-tone color map. |
daspect(*args) | Change the data aspect ratio. |
figure(*args, **kwargs) | Create a new figure or switch between figures and return Figure object. |
fill(*args, **kwargs) | Draw filled 2D polygons. |
fill3() | Draw filled 3D polygons. |
flag([m]) | Alternating red, white, blue, and black color map. |
gca() | Return the current axis in the current figure. |
gcf() | Return current figure. |
get_script() | Return a string with the currently stored Matlab commands. |
getp(*args) | Get object properties or an attribute in this backend instance. |
gray([m]) | Linear gray-scale color map. |
grid(*args) | Toggle the display of grid lines. |
hardcopy(filename, **kwargs) | Save a hardcopy of the current figure to file (with the given filename). |
hidden(*args) | Toggle hidden line removal in the current axis. |
hold(*args) | Change the hold state of the current axis. |
hot([m]) | Black-red-yellow-white color map. |
hsv([m]) | Hue-saturation-value color map. |
init() | Initialize internal data structures. |
ishold() | Return the hold state (True if hold is on, and False if it is off). |
isocaps(*args, **kwargs) | Draw isosurface end caps. |
isosurface(*args, **kwargs) | Draw isosurfaces from 3D scalar fields. |
jet([m]) | Variant of hsv. |
legend(*args, **kwargs) | Add legend(s) to the current plot. |
light(**kwargs) | Add a light to the current axis. |
lines([m]) | Color map with the line colors. |
loglog(*args, **kwargs) | Draw a loglog plot with logarithmic scaling on x- and y-axis. |
m1(*args) | Add a label to the z-axis. |
m2([m]) | Shades of blue and green color map. |
material(*args) | Set the material reflectance mode. |
mesh(*args, **kwargs) | Draw a 3D mesh surface. |
meshc(*args, **kwargs) | Draw a mesh with a contour plot beneath. |
openfig([filename]) | Load figures saved in a file (with the given filename). |
pcolor(*args, **kwargs) | Draw a 2D pseudocolor plot. |
pink([m]) | Pastel shades of pink color map. |
plot(*args, **kwargs) | Draw line and scatter plots. |
plot3(*args, **kwargs) | Draw lines and points in 3D space. |
prism([m]) | Prism color map. |
quiver(*args, **kwargs) | Draw arrows from a 2D vector field. |
quiver3(*args, **kwargs) | Draw velocity vectors in 3D space. |
reset() | Reset the class variable _script where the current Matlab commands |
save_m(filename) | Save the Matlab commands for the current figure(s) in a M-file |
savefig([filename]) | Save all current figures to a file (with the given filename). |
semilogx(*args, **kwargs) | Draw a semilog plot with logarithmic scaling on x-axis. |
semilogy(*args, **kwargs) | Draw a semilog plot with logarithmic scaling on y-axis. |
setp(*args, **kwargs) | Set object properties or attributes in this backend instance. |
shading(*args) | Control the color shading of surfaces. |
show() | Redraw the current figure. |
slice_(*args, **kwargs) | Draw volumetric slice plot. |
spring([m]) | Shades of magenta and yellow color map. |
stem(*args, **kwargs) | Draw a stem plot. |
streamline(*args, **kwargs) | Draw streamlines from 2D or 3D vector data. |
streamribbon(*args, **kwargs) | Draw stream ribbons from 3D vector data. |
streamslice(*args, **kwargs) | Draw streamlines in axis aligned slice planes. |
streamtube(*args, **kwargs) | Draw stream tubes from 3D vector data. |
subplot(*args, **kwargs) | Create axes in tiled positions. |
summer([m]) | Shades of green and yellow color map. |
surf(*args, **kwargs) | Draw a 3D solid surface. |
surfc(*args, **kwargs) | Draw a solid surface with contours beneath. |
surfl(*args, **kwargs) | 3D shaded surface with lighting. |
title(*args) | Add title to the current plot. |
vga([m]) | Windows colormap for 16 colors. |
view(*args) | Specify viewpoint. |
white([m]) | All white color map. |
winter([m]) | Shades of blue and green color map. |
xlabel(*args) | Add a label to the x-axis. |
xlim(*args) | Set or get limits on x axis. |
ylabel(*args) | Add a label to the y-axis. |
ylim(*args) | Set or get limits on y axis. |
zlabel(*args) | Add a label to the z-axis. |
zlim(*args) | Set or get limits on z axis. |
Create a new figure or switch between figures and return Figure object. num is the figure number of the new or existing figure.
Save a hardcopy of the current figure to file (with the given filename). The file format (image type) is determined from the extension of the filename. If any changes have been made by working directly on the backend instance, set the keyword argument replot to False to stop Easyviz from replotting the current figure and destroying those changes.
Supported extensions:
‘.ps’ (PostScript) ‘.eps’ (Encapsualted PostScript) ‘.jpg’ (Joint Photographic Experts Group) ‘.png’ (Portable Network Graphics) ‘.pdf’ (Portable Document Format) ‘.pbm’ (Portable Bitmap) ‘.pgm’ (Portable Graymap) ‘.ppm’ (Portable Pixmap) ‘.tif’ (Tagged Image File Format) ‘.hgl’ (Hewlett-Packard Graphics Language) ‘.ai’ (Adobe Illustrator file) ‘.pcx’ (Paintbrush 24-bit file) ‘.bmp’ (Bitmap Image)
Optional arguments:
- renderer – Specify which renderer to use. Available renderers
- are ‘painters’, ‘zbuffer’, and ‘opengl’. If not specified, the default renderer in Matlab is chosen. (This option is not available when running Matlab with the -nodisplay argument.)
- color – If True, create a plot with colors. If False
- (default), create a plot in black and white. This option is only available for PostScript output.
- pslevel – Set the PostScript level to be used. By default,
- level 1 PostScript is used, while pslevel=2 will use PostScript level 2 instead.
- raw – If True, this will use raw format on PBM, PGM,
- and PPM files. If False (default), a plain text format is used.
- quality – Set the quality level of a JPEG image. Must be an
- integer between 0 and 100, where 100 gives the best quality but also the lowest compression. The default quality level is 75.
- tiffcompression – Set whether to use compression or no compression
- (default) on a TIFF file.
Example on how to use the backend directly to save a hardcopy of the current figure:
>>> g = get_backend()
>>> g.print_(g.gcf(), '-deps', 'foo.eps')
Add a label to the z-axis.
Calling:
zlabel(s)
adds the text given in s beside the z-axis on the current axis.
Calling:
zlabel(ax, ...)
adds the zlabel to the Axis object ax instead of the current axis.
Shades of blue and green color map.