login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Graphics in FriCAS

The graphics commands are described in Chapter 7 of the FriCASBook?. The syntax is:

    draw(f(x), x=a..b, options)
    draw(f(x,y), x=a..b, y=c..d, options)

fricas
vp1:=draw(sin(x), x=%pi/10..%pi)
fricas
Compiling function %B with type DoubleFloat -> DoubleFloat 
   Graph data being transmitted to the viewport manager...
   FriCAS2D data being transmitted to the viewport manager...

\label{eq1}\mbox{\rm \hbox{\axiomType{TwoDimensionalViewport}\ } :}\verb#"sin(x)"#(1)
Type: TwoDimensionalViewport?

This command creates a "view port" and would normally (on linux for example) also display the graph.

The draw command works only under an X-Windows environment (unix/linux). There were attemps to create a new user interface (AxiomUI. fricasserver) that among other things will allow graphics to be viewed under other operating systems. But currently they stalled... If you're interested in graphics, please pitch in!

Although due to technical limitations of this system (no Xwindows environment on the Web server) we are not yet able to use draw here. However we description below a similar command named gnuDraw that can be used to generate similar graphics on this web site.

gnuDraw

It is possible to produce graphics similar to FriCAS using gnuplot on this web site. This uses GnuDraw? (GDRAW) library which is included in FriCAS (starting from version 1.2.4).

The following examples are taken from Chapter 7 Graphics of the FriCASBook?.

Section: 7.1 Two-Dimensional Graphics

The general format for drawing a function defined by a formula f(x) is:

  gnudraw(f(x), x = a..b, "filename.dat", options)

where a..b defines the range of x, options are additional draw options and "filename.dat" will contain the gnuplot script necessary to create the graph.

fricas
gnuDraw(sin(x), x=%pi/10..%pi,"FriCASGraphics1.dat")
fricas
Compiling function %E with type DoubleFloat -> DoubleFloat
Type: Void

This file may be displayed on the web page using:

  !/begin{gnuplot}
  load "filename.dat"
  /end{gnuplot}

See below.

Technical Details

We can extract the graph data from the view port. For example we can display the list of data points that would be plotted in the graph.

(Note: we disable LaTeX output typesetting in order to save space.)

fricas
)set output tex off
 
fricas
)set output algebra on
g1:=getGraph(vp1,1)
(3) Graph with 1 point list
Type: GraphImage?
fricas
pointLists(g1)
(4) [ [[0.3141592653589793,0.3090169943749474,1.0,3.0], [0.37306412761378793,0.36447049987914965,1.0,3.0], [0.43196898986859655,0.4186597375374281,1.0,3.0], [0.4908738521234052,0.47139673682599764,1.0,3.0], [0.5497787143782138,0.5224985647159488,1.0,3.0], [0.6086835766330224,0.5717879602276122,1.0,3.0], [0.667588438887831,0.619093949309834,1.0,3.0], [0.7264933011426397,0.6642524379112817,1.0,3.0], [0.7853981633974483,0.7071067811865475,1.0,3.0], [0.8443030256522569,0.7475083268625967,1.0,3.0], [0.9032078879070655,0.785316930880745,1.0,3.0], [0.9621127501618741,0.8204014435255136,1.0,3.0], [1.0210176124166828,0.8526401643540922,1.0,3.0], [1.0799224746714913,0.8819212643483549,1.0,3.0], [1.1388273369262998,0.9081431738250811,1.0,3.0], [1.1977321991811083,0.9312149347588035,1.0,3.0], [1.2566370614359168,0.9510565162951534,1.0,3.0], [1.3155419236907253,0.9675990923602596,1.0,3.0], [1.3744467859455338,0.9807852804032303,1.0,3.0], [1.4333516482003423,0.9905693404435771,1.0,3.0], [1.4922565104551508,0.9969173337331279,1.0,3.0], [1.5511613727099594,0.9998072404820648,1.0,3.0], [1.6100662349647679,0.999229036240723,1.0,3.0], [1.6689710972195764,0.995184726672197,1.0,3.0], [1.7278759594743849,0.987688340595138,1.0,3.0], [1.7867808217291934,0.9767658813208727,1.0,3.0], [1.845685683984002,0.9624552364536477,1.0,3.0], [1.9045905462388104,0.9448060464668786,1.0,3.0], [1.963495408493619,0.9238795325112875,1.0,3.0], [2.0224002707484274,0.8997482840522223,1.0,3.0], [2.081305133003236,0.8724960070727982,1.0,3.0], [2.1402099952580445,0.8422172337162878,1.0,3.0], [2.199114857512853,0.8090169943749488,1.0,3.0], [2.2580197197676615,0.7730104533627385,1.0,3.0], [2.31692458202247,0.7343225094356872,1.0,3.0], [2.3758294442772785,0.6930873625456377,1.0,3.0], [2.434734306532087,0.6494480483301858,1.0,3.0], [2.4936391687868955,0.6035559419535738,1.0,3.0], [2.552544031041704,0.5555702330196047,1.0,3.0], [2.6114488932965125,0.5056573733779872,1.0,3.0], [2.670353755551321,0.45399049973954964,1.0,3.0], [2.7292586178061295,0.400748833103144,1.0,3.0], [2.788163480060938,0.3461170570774962,1.0,3.0], [2.8470683423157466,0.2902846772544658,1.0,3.0], [2.905973204570555,0.23344536385590897,1.0,3.0], [2.9648780668253636,0.17579627993435823,1.0,3.0], [3.023782929080172,0.11753739745784152,1.0,3.0], [3.0826877913349806,0.058870803651193036,1.0,3.0], [3.141592653589793,1.2246467991473532e-16,1.0,3.0]] ]
Type: List(List(Point(DoubleFloat?)))
fricas
)set output algebra off
 
fricas
)set output tex on

Using lower level functions the points in such a graph can also be constructed as follows:

First we need this domain

fricas
)expose GraphImage
GraphImage is now explicitly exposed in frame initial

fricas
lineSegments := [[point [sin(x*%pi/10)$DoubleFloat, _
                  x*%pi/10], point [sin((x+1)*%pi/10)$DoubleFloat, _
                 (x+1)*%pi/10]] for x in 1..10]

\label{eq2}\begin{array}{@{}l}
\displaystyle
\left[{
\begin{array}{@{}l}
\displaystyle
\left[{\left[{0.3090169943749474}, \:{0.3141592653589793}\right]}, \: \right.
\
\
\displaystyle
\left.{\left[{0.5877852522924731}, \:{0.6283185307179586}\right]}\right] (2)
Type: List(List(Point(DoubleFloat?)))

fricas
lineColors := [light blue() for i in 1..10]

\label{eq3}\begin{array}{@{}l}
\displaystyle
\left[{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Light}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Light}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Light}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Light}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Light}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Light}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Light}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Light}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Light}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Light}\ } \mbox{\rm palette}}\right] 
(3)
Type: List(Palette)

fricas
pointColors  := [dark blue() for i in 1..10]

\label{eq4}\begin{array}{@{}l}
\displaystyle
\left[{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Dark}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Dark}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Dark}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Dark}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Dark}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Dark}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Dark}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Dark}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Dark}\ } \mbox{\rm palette}}, \: \right.
\
\
\displaystyle
\left.{[{\mbox{\rm \hbox{\axiomType{Hue}\ } :}{22}\mbox{\rm \hbox{\axiomType{Weight}\ } :}{1.0}}\mbox{\rm ] from the}\hbox{\axiomType{Dark}\ } \mbox{\rm palette}}\right] 
(4)
Type: List(Palette)

fricas
lineSize := [6 for i in 1..10]

\label{eq5}\left[ 6, \: 6, \: 6, \: 6, \: 6, \: 6, \: 6, \: 6, \: 6, \: 6 \right](5)
Type: List(PositiveInteger)

fricas
g2:=makeGraphImage(lineSegments, lineColors, pointColors, lineSize)

\label{eq6}\mbox{\rm \hbox{\axiomType{Graph}\ } with}{10}\mbox{\rm point lists}(6)
Type: GraphImage?
fricas
)set output tex off
 
fricas
)set output algebra on
pointLists(g2)
(10) [ [[0.3090169943749474,0.3141592653589793], [0.5877852522924731,0.6283185307179586]] ,
[[0.5877852522924731,0.6283185307179586], [0.8090169943749475,0.9424777960769379]] ,
[[0.8090169943749475,0.9424777960769379], [0.9510565162951535,1.2566370614359172]] , [[0.9510565162951535,1.2566370614359172],[1.0,1.5707963267948966]], [[1.0,1.5707963267948966],[0.9510565162951536,1.8849555921538759]],
[[0.9510565162951536,1.8849555921538759], [0.8090169943749475,2.199114857512855]] ,
[[0.8090169943749475,2.199114857512855], [0.5877852522924732,2.5132741228718345]] ,
[[0.5877852522924732,2.5132741228718345], [0.3090169943749475,2.827433388230814]] ,
[[0.3090169943749475,2.827433388230814], [1.2246467991473532e-16,3.141592653589793]] ,
[[1.2246467991473532e-16,3.141592653589793], [- 0.3090169943749469,3.455751918948772]] ]
Type: List(List(Point(DoubleFloat?)))
fricas
)set output algebra off
 
fricas
)set output tex on


load "FriCASGraphics1.dat"




  Subject:   Be Bold !!
  ( 13 subscribers )  
Please rate this page: