Wolfram ResearchProductsPurchasingServices & ResourcesAbout UsOur Sites

Graphics

  • You can join points together in a plot by using ListPlot[list, PlotJoined -> True].

  • To make circles show up as circular in Mathematica, you can use AspectRatio -> Automatic in ParametricPlot.

  • You can use Show to change the options in graphics.

  • You can suppress the output of graphics by setting the option DisplayFunction to Identity, as in the following example.

    Plot[Sin[x], {x, -2, 2}, DisplayFunction ->
          Identity];

  • You can control exactly what ranges of x and y coordinates are included in your plot by specifying the option PlotRange.

    Plot[f, {x, xmin, xmax}, PlotRange ->
          {{
    xmin, xmax}, {ymin, ymax}}];

  • There is a difference between the graphics directives PointSize and AbsolutePointSize. A PointSize dimension such as 0.01 means 1/100 of the linear size of the displayed figure. If the figure is resized and made smaller, then the point will also be smaller. However, AbsolutePointSize dimensions are absolute lengths measured in units of printer's points. Each printer's point is approximately 1/72 of an inch. If the figure is resized, the point size remains constant. The same applies to Thickness vs. AbsoluteThickness and Dashing vs. AbsoluteDashing.

  • You can use the command Block to create local variable definitions that do not affect the global definitions of the global variable of the same name. One useful way to use Block is to temporarily reassign built-in Mathematica variables. Please note that while Block and Module are similar in many ways, the following example will not work with Module.

    In[1]:= Block[{$DisplayFunction = Identity},
              a = Plot[x^2, {x, 0, 10}];
              b = ListPlot[Table[x^2, {x, 10}],
              PlotStyle -> {PointSize[.03]}];];
            Show[a, b];

    This example reassigns the values of $DisplayFunction. Inside the command Block, $DisplayFunction is set to Identity and the graphics are subsequently suppressed. Once outside the command Block, $DisplayFunction returns to its default value and a graph is created. Thus, one graph is shown, not three.

  • Every Mathematica graphic is a set of primitives and options. For example, the first part of ListPlot is a set of Point primitives.

    In[1]:= t = Table[x^2, {x, 10}];
            lp = ListPlot[t, DisplayFunction ->
                  Identity]; First[lp]

    Out[1]= {Point[{1, 1}], Point[{2, 4}],
               Point[{3, 9}], Point[{4, 16}],
               Point[{7, 49}], Point[{8, 64}],
               Point[{5, 25}], Point[{6, 36}],
               Point[{9, 81}], Point[{10, 100}]}

    You can alter a graphic by altering its primitives. For example, you can convert one primitive into another.

    In[2]:= Show[lp /. Point[pt_] :> Circle[pt,
              {.2, 2}], DisplayFunction ->
                  $DisplayFunction];

  • To change the color of a plot, you must specify an option for the command Plot. In this case, the option is PlotStyle. For example, the command Plot without an option returns a black and white image.

    Plot[Sin[x], {x, 0, 2 Pi}];


    But by specifying the option PlotStyle, you can manipulate and control the plot's color.

    Plot[Sin[x], {x, 0, 2 Pi}, PlotStyle ->
          RGBColor[1, 0, 0]];


  • To create implicit plots of nonfunctions, first use the command Needs to load the appropriate standard add-on package. Notice the use of the backquote, which is different from the single quote or apostrophe. (Please see the FAQ "How do I get packages to load properly?" for more information.)

    Needs["Graphics`ImplicitPlot`"]

    After the package loads successfully, the command ImplicitPlot can be used.

    ImplicitPlot[x == y^2, {x, -4, 4}];

    If you forget how to use this command, help is just a question mark away.

    ?ImplicitPlot

    ImplicitPlot[eqn, {x, a, b}] draws a graph of the set of points that satisfy the equation eqn. The variable x is associated with the horizontal axis and ranges from a to b. The remaining variable in the equation is associated with the vertical axis. ImplicitPlot[eqn, {x, a, x1, x2, ..., b}] allows the user to specify values of x where special care must be exercised. ImplicitPlot[{eqn1, eqn2, ...}, {x, a, b}] allows more than one equation to be plotted, with PlotStyles set as in the Plot function. ImplicitPlot[eqn, {x, a, b}, {y, a, b}] uses a contour plot method of generating the plot. This form does not allow specification of intermediate points.

  • You can plot two or more functions on the same set of coordinate axes in Mathematica. Plotting a function in Mathematica is relatively easy.

    Plot[Sin[x], {x, 0, 2 Pi}];


    However, when plotting multiple functions on the same set of coordinate axes, one must list a set of functions for Mathematica to plot.

    Plot[{Cos[x], Sin[x]}, {x, 0, 2 Pi}];


    The command Plot essentially looks for three distinct arguments. Specifically they are: Plot[what, over what domain, how should it look]. The function(s) to plot, what, must be a single argument, which in this case is represented as a list of functions.

  • To find coordinates in a 2D plot, select the plot. You can then hold down the appropriate modifier key for your system (CONTROL, COMMAND, or MOD-1) and move the pointer over the area of the plot. The coordinate values of the pointer position will be displayed in the window's status area. If you click one or more times while holding down the modifier key, the coordinates will be selected. You can then copy the coordinate values and paste them into a different cell. (Please see the FAQ "How do I select points from a graph?" for a more detailed explanation.)

  • You can turn graphics into GIFs using Export. Mathematica provides a variety of mechanisms for exporting graphics to other common graphics formats. The command Export allows you to send graphics systematically from Mathematica to external files. For example, generate the following plot.

    Plot[Sin[x] + Sin[x Sqrt[2]], {x, 0, 10}]

    Now save the result as a GIF file by using the command Export.

    Export["sinplot.gif", %, "GIF"]


Return to the Mathematica tips index.



 © 2008 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: