RE: Show graphics command
- To: mathgroup at smc.vnet.net
- Subject: [mg40368] RE: [mg40347] Show graphics command
- From: "David Park" <djmp at earthlink.net>
- Date: Thu, 3 Apr 2003 01:42:09 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Nathan, Here are some examples. data = Table[{x, Sin[x] + Random[Real, {-0.2, 0.2}]}, {x, 0, 2Pi, 2Pi/20}]; The basic method is to use the DisplayFunction option to turn the display off or on. You may wish to lookup DisplayFunction in Help. plot1 = ListPlot[data, DisplayFunction -> Identity]; plot2 = Plot[Sin[x], {x, 0, 2Pi}, DisplayFunction -> Identity]; Show[plot1, plot2, DisplayFunction -> $DisplayFunction, Prolog -> AbsolutePointSize[5]]; A shorter method is to use a Block statement and temporarily reset the system DisplayFunction. Block[{$DisplayFunction = Identity}, plot1 = ListPlot[data]; plot2 = Plot[Sin[x], {x, 0, 2Pi}];] Show[plot1, plot2, Prolog -> AbsolutePointSize[5]]; An even shorter method is to uses the DisplayTogether command from the Graphics`Graphics` package. Needs["Graphics`Graphics`"] DisplayTogether[ ListPlot[data, Prolog -> AbsolutePointSize[5]], Plot[Sin[x], {x, 0, 2Pi}]]; The only trouble with some of these methods is that it is sometimes difficult to control how options are picked up. Basically Mathematica picks up the options from the first plot. So if you wrote your plots in reverse order you would lose the AbsolutePointSize option. DisplayTogether[ Plot[Sin[x], {x, 0, 2Pi}], ListPlot[data, Prolog -> AbsolutePointSize[5]]]; If you were trying to set options in both plots you would be out of luck. The DrawGraphics package at my web site was basically designed to overcome these problems and provide a more natural paradigm for combining plots. One uses Draw statements to replace Plot statements. The Draw statements extract the graphic primitives of a plot without producing a side display. Hence the output of a Draw statement is on the same level as the other graphic primitives such as Point, Line etc. You can also freely mix in graphics directives. So the above plot, with the curve plotted in Blue, would be given as Needs["DrawGraphics`DrawingMaster`"] Draw2D[ {AbsolutePointSize[5], ListDraw[data], Blue, Draw[Sin[x], {x, 0, 2Pi}]}, Axes -> True]; I've come to think that ListPlot and MultipleListPlot are often the difficult way to do things. It is often easier to just Map Point onto the data list to plot the points or wrap the data list in Line to plot the line. Here is an example, plotting the data points as points and as a Red line. Draw2D[ {AbsolutePointSize[5], Point /@ data, Red, Line[data], Blue, Draw[Sin[x], {x, 0, 2Pi}]}, Axes -> True]; You can add as many other elements to the graphic as you wish, just by stacking them up. You could. for example, add a curve produced by ParametricPlot just by writing it is ParametricDraw, or a curve produced by ImplicitPlot, just by writing it as ImplicitDraw. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Nathan Moore [mailto:nmoore at physics.umn.edu] To: mathgroup at smc.vnet.net The list operations have been very useful. Here's a pet peeve. Often when I combine several graphics objects with the show command I get a bunch of extraneous plots. Suppose I have a list of {x,y} pairs (named "data") and a fit function f[x] and I want to show them together. The easiest way to do this is with the command, Show[ListPlot[data],Plot[f[x],{x,0,Xo}] When I execute this I get 3 plots, ListPlot[data], the Plot[f[x]], and then the tro combined. How can I have the front end suppress the first two plots? (this "error" is especially annoying when I'm plotting 7 or 8 lists together) Nathan Moore