STACK Documentation

Documentation home | Category index | Parent | Site map

Plots and graphics in STACK questions.

Plots and graphics can be placed into any of the CAStext fields.

The main way to create plots with the core STACK commands is using Maxima. As of version 4.0, the tags {#...#} provide the possibility to interact with 3rd party scripts. If you have examples of this, please contact the developers. This page is about core supported functionality.


In STACK, the plot command has been defined to be a wrapper for Maxima's plot2d command. The wrapper makes sure that an image file is given an appropriate name, file location, and that Maxima returns a URL to the user giving the image. Not all of the features of plot2d are available through plot.

Try, for example, the following in the question stem.


You can add a second variable to control the axes.


However, Maxima will not always allow you to get the axes you want (this is a bug in Maxima). To get many plots in one window, we need to define a list of expressions.


This can be done with Maxima's makelist command



  • Currently STACK has gnuplot return a basic SVG image.
  • Only a very few of Maxima's plot_options are respected by plot, mainly for security reasons. (plot calls an external command gnuplot which writes to the server filesystem.)
  • The draw package is currently not supported.

Traditional axes

Note: this example only works with newer versions of Maxima (and not before 5.31.3).

A traditional plot with the axes in the middle can be generated by the following.

{@plot([x^2/(1+x^2),2*x/(1+x^2)^2], [x, -2, 2], [y,-2.1,2.1], [box, false], [yx_ratio, 1], [axes, solid], [xtics, -2, 0.5, 2],[ytics, -2, 0.5, 2])@}


The ylabel command rotates its argument through 90 degrees. If you want a horizontal label on the \(y\)-axis you will need to use the label command instead.

{@plot([x^2/(1+x^2),2*x/(1+x^2)^2], [x, -2, 2], [y,-2.1,2.1], [label,["y",-2.5,0.25]])@}


The grid is controlled by the maxima command grid2d (newer versions of Maxima only). Compare the following.

{@plot([x^2/(1+x^2),2*x/(1+x^2)^2], [x, -2, 2], [y,-2.1,2.1], grid2d)@}
{@plot([x^2/(1+x^2),2*x/(1+x^2)^2], [x, -2, 2], [y,-2.1,2.1])@}


The following plot options are currently supported by STACK. If you would like to expand the range of options available please contact the developers.

[xlabel, ylabel, label, legend, color, style, point_type, nticks, logx, logy, axes, box, plot_realpart, yx_ratio, xtics, ytics, ztic, grid2d],

Please see Maxima's documentation for more information on these options. Note that the draw package is currently not supported.

Notes on some of the options.

  • The default in Maxima is to include a legend consisting of a string representation of the plot. In STACK this is turned off by default. To switch it back on, use the command [legend, true]. Any other value of the option legend will respect the original command.

Alternate text for an image (alt tag)

The default alternate text for an image (img alt tag) generated by a plot command such as


is "STACK auto-generated plot of x^2 with parameters [[x,-2,2]]". If your question asks students to "give an algebraic expression which describes this curve" then you will need to set alternative text which does not include the answer.

To set a specific alt tag, pass an equation [alt,"..."] as an argument to the plot function.

plot(x^2,[x,-2,2],[alt,"Hello world"]);

If you would like an expression as part of this then try

plot(p,[x,-2,2],[alt,sconcat("Here is ",string(p))]);

A catalogue of plots

The following CAStext gives representative examples of the plot2d features supported by STACK's plot command. Cut and paste it into the caschat script. Beware that these are likely to cause a timeout on the CAS if you try them all at once.

<h3>Basic plot</h3>
The following plot tests the option to explicitly test the alt-text.
{@plot(x^3,[x,-3,3], [alt,"What is this function?"])@}
<h3>Mutiple graphs, clips the \(y\) values</h3>
<h3>With and without a grid</h3>
{@plot([x^2/(1+x^2),2*x/(1+x^2)^2], [x, -2, 2], [y,-2.1,2.1], grid2d)@}
{@plot([x^2/(1+x^2),2*x/(1+x^2)^2], [x, -2, 2], [y,-2.1,2.1])@}
<h3>Discrete plots</h3>
Basic discrete plot.
Combination of discrete plots with normal plots.
{@plot([x^2, [discrete,[ [0,0], [1,1], [0,2]]]],[x,-2,2])@}
Using different point styles.
{@plot([[discrete, [[10, .6], [20, .9], [30, 1.1],[40, 1.3], [50, 1.4]]],[discrete, [[11, .5], [15, .9], [25, 1.2],[40, 1.3], [50, 1.4]]]],[style, points],[point_type,circle,square],[color,black,green])@}
<h3>Parametric plots</h3>
{@plot([parametric, cos(t), sin(3*t), [t,0,2*%pi]], [nticks, 500])@}
<h3>Setting non-trivial options: labels on the axes and legend</h3>
{@plot(x*sin(1/x),[x,-1,2],[xlabel,"Independent variable"],[ylabel,"Dependent variable"],[legend,"This is a plot"])@}
<h3>Log scale for y-axis, with red colour</h3>
{@plot(exp(3*s),[s, -2, 2],[logy], [color,red])@}
<h3>Turn off the box, grid and the axes</h3>
Default options
{@plot([parametric, (exp(cos(t))-2*cos(4*t)-sin(t/12)^5)*sin(t), (exp(cos(t))-2*cos(4*t)-sin(t/12)^5)*cos(t), [t, -8*%pi, 8*%pi]], [nticks, 100])@}
<tt>[axes, false]</tt>
{@plot([parametric, (exp(cos(t))-2*cos(4*t)-sin(t/12)^5)*sin(t), (exp(cos(t))-2*cos(4*t)-sin(t/12)^5)*cos(t), [t, -8*%pi, 8*%pi]], [nticks, 100], [axes,false])@}
<tt>[box, false]</tt>
{@plot([parametric, (exp(cos(t))-2*cos(4*t)-sin(t/12)^5)*sin(t), (exp(cos(t))-2*cos(4*t)-sin(t/12)^5)*cos(t), [t, -8*%pi, 8*%pi]], [nticks, 100], [box,false])@}
<h3>Putting the axes in the middle</h3>
{@plot([x^2/(1+x^2),2*x/(1+x^2)^2], [x, -2, 2], [y,-2.1,2.1], [box, false], [yx_ratio, 1], [axes, solid], [xtics, -2, 0.5, 2],[ytics, -2, 0.5, 2])@}


In Maxima


generates a plot of an implicit function.

Maxima's implicit_plot() function does not respect the plot options, and we cannot place the resulting plot files in the correct places. Hence, STACK does not currently support implicit plots.


Note also that images can be included as HTML. It is easiest to place your image somewhere on the internet and include a URL in the body of your STACK question.

Google charts

Note that Google deprecated the API in 2012 with guaranteed availability until April 2015.

You can dynamically generate a URL for Google charts and in this way include randomly generated diagrams.

An example question is included as


This includes the code in the question variables to create random objects.

a : 30 + rand(20);
b : 40 + rand(50);
anb : 5 + rand(20);
aub : a+b-anb;

Then, in the question stem we have the HTML which uses this. Note the way the values of variables are inserted here using the {#...#} syntax that outputs raw values instead of LaTeX representations.

<img src="{#a#},{#b#},0,{#anb#},0,0&chdl=A|B">

This should look like the following, with in this case \(a=33\), \(b=65\), \(a\cap b=18\).

See also

Maxima reference topics.

Documentation home | Category index | Parent | Site map