Skip to content
Nijso edited this page Mar 19, 2015 · 26 revisions

maxima-draw2d-plus is a collection of additional functions for the draw2d package of the maxima CAS, a free symbolic mathematics package, see:

http://maxima.sourceforge.net/

http://riotorto.users.sourceforge.net/gnuplot/index.html

To load the package, put the files vector.mac and hex.lisp in a location where maxima can find it and type on the maxima prompt:

(%i01) batch("vector.mac");

The package draw2d is automatically loaded when you load vector.mac. You can now use the new command Vectorplot.

The syntax is:

Vectorplot([fx(x,y),fy(x,y)],[xmin,xmax],[ymin,ymax],[optional-arguments])

(%i02) Vectorplot([y,-x],[-2,2],[-2,2]);

your first vector plot

A vector plot of the vector field [y,-x] will be drawn, using 10x10 vectors on an equidistant grid. The vectors are colored by their norm (sqrt(VxVx + VyVy)). Vectorplot expects 2 variables in the vector field and will rank the variables alphabetically. The first variable (alphabetically) will be associated with the horizontal axis and the second variable will be associated with the vertical axis. This behavior can be changed with the parameters xvar and yvar.

(%i02) Vectorplot([w,-v],[-2,2],[-2,2]);

(%i02) Vectorplot([v,-w],[-2,2],[-2,2]);

(%i02) Vectorplot([v,-w],[-2,2],[-2,2],xvar=w,yvar=w);

You can save images to file by writing to a file terminal, e.g. jpg or png:

(%i02) Vectorplot([y,-x],[-2,2],[-2,2],terminal=png);

The file will be saved in the default file maxima_out.png. You can change the filename using the keyword filename:

(%i02) Vectorplot([y,-x],[-2,2],[-2,2],terminal=png,filename="vectorplot");

The file extension is automatic. A higher quality image is obtained using the terminal pngcairo:

(%i02) Vectorplot([y,-x],[-2,2],[-2,2],terminal=pngcairo,filename="vectorplotcairo"); higher quality png image using the pngcairo terminal

Notice the smoother vectors compared to the jagged lines in the previous figure.

The default number of vectors in X and Y direction is 10, so by default Vectorplot will draw 100 vectors. You can change this using the optional argument vectorpoints:[Nx,Ny]:

(%i02) Vectorplot([y,-x],[-2,2],[-2,2],vectorpoints:[25,25],terminal=pngcairo,filename="densevectorplotcairo");

dense vectorplot

You can change the color palette for coloring the vectors using the colorpalette parameter. Colorpalette is a list of colors where the first color is the lowest value and the last color is the highest value. Colors can be defined as names or as hexadecimal values like "#ffffff" (the names are simply aliases). By default, the vectors are colored by their norm. If you want to change this, use the optional parameter colorfunction.

Vectorplot([y,-x],[-2,2],[-2,2],vectorpoints=[10,10],colorfunction=x,colorpalette=[blue,green,red]);

or:

Vectorplot([y,-x],[-2,2],[-2,2],vectorpoints=[10,10],colorfunction=x,colorpalette=palette_BGR);

vector plot using a different palette

If you want a constant color plot, you can give a single color as an argument to colorpalette. The colorfunction will then be ignored. Vectorplot([y,-x],[-2,2],[-2,2],vectorpoints=[10,10],colorfunction=x,colorpalette=black);

vector plot using a constant color

The mandatory xrange and yrange values determine the area within which the vectors will be drawn. By default, the actual xrange and yrange of the plot will be slightly larger so that vectors on the edge will not be cut off by the borders. If for some reason you want the vectors to be drawn in only a subsection of the plot, you can explicitly give the xrange and yrange:

(%i02) Vectorplot([y,-x],[-2,2],[-2,2],vectorpoints=[10,10],xrange=[-4,4],yrange=[-3,3]);

vector plot with a small plotting area in a large domain

Normally, the maximum vectorsize vmax is length(xrange)/Nx or length(yrange)/Ny, whichever is smaller. The minimum vector size is vmin=0.05*vmax. If you want to use your own minimum and maximum size, set the optional argument vectorscale=[vmin,vmax].

(%i02) Vectorplot([y,-x],[-2,2],[-2,2],vectorpoints=[10,10],vectorscale=[0.1,0.5]); vector plot with a scaling factor

Vectorplot([y,sin(x)-y/10.0],[-10,10],[-6,6],vectorpoints=[15,15],colorpalette=Palette_BGR);

vectorplot with different palette

Clone this wiki locally