RE: Show[] applied to a Plot[] and a ListPlot[] ??
- To: mathgroup at smc.vnet.net
- Subject: [mg41048] RE: [mg41023] Show[] applied to a Plot[] and a ListPlot[] ??
- From: "David Park" <djmp at earthlink.net>
- Date: Wed, 30 Apr 2003 04:22:07 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Rob, Needs["Graphics`Colors`"] data = {{0, 260.}, {.25, 218.}, {.5, 200.}, {.75, 212.}, {1., 240.}}; a0 = 260.; a1 = -188.; a2 = -2.667; a3 = 384.; a4 = -213.333; f[x_] = a0 + a1 x + a2 x^2 + a3 x^3 + a4 x^4; a = Plot[f[x], {x, 0, 1}]; b = ListPlot[data, Epilog -> {RGBColor[1, 0, 0], PointSize[0.025], Point /@ data}]; Show[a,b] Show[b,a] The reason that the first Show statement didn't work is that it picked up the options from the first plot, a, and threw away the options from the second plot, b. And thus the whole Epilog option was lost. The same problem occurs if you use the DisplayTogether statement from the Graphics`Graphics` package. In your case the solution is simple, just reverse the order of a and b in the Show statement. (But what if you have important Epilog options associated with each Plot? Then one or the other will get thrown away! Or you could put the b Epilog that has nothing to do with the a plot in the a plot. Not an intuitive way to proceed.) But for the b plot you should use Prolog instead of Epilog and then you can write... b = ListPlot[data, Prolog -> {RGBColor[1, 0, 0], PointSize[0.025]}] But the Prolog option also gets thrown away. So you would still have to reverse a and b in Show. A better way is to write... b = ListPlot[data, PlotStyle -> {RGBColor[1, 0, 0], PointSize[0.025]}]; With that, you can write Show[{a,b}] and PlotStyle does not get thrown away. Why not? Because PlotStyle affects the detailed graphical primitives produced by ListPlot and is not an "over-all" plot option (such as Frame, ImageSize, ApectRatio etc.) But Prolog and Epilog are "over-all" options. It's just a Mathematica feature. You could also have written b as b = Show[Graphics[ {Red, PointSize[0.025], Point /@ data}]]; But I would do all this more simply, without the side plots, by using the DrawGraphics package from my web site. Needs["DrawGraphics`DrawingMaster`"] Draw2D[ {Draw[f[x], {x, 0, 1}], Red, PointSize[0.025], Point /@ data}, Axes -> True]; David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: 1.156 [mailto:rob at piovere.com] To: mathgroup at smc.vnet.net First I start with a few measured data points: data = {{0,260.}, {.25,218.},{.5,200.}, {.75,212.}, {1.,240.}}; (* I do some curve fitting/regression and I come up with a polynomial and I'd like to see how the curve compares with the data *) a0 = 260.; a1 = -188.; a2 = -2.667; a3 = 384.; a4 = -213.333.; f[x_]= a0+ a1 x+ a2 x^2+ a3 x^3 +a4 x^4; (* So I plot each of them, both look good to me. a plots the best fit curve and b plots the data points with nice big red dots. I got the b code from some kind soul on this ng I think. Both plots are over a domain from 0 to 1 *) a = Plot[f[x], {x, 0, 1}]; b=ListPlot[data,Epilog\[Rule]{RGBColor[1,0,0],PointSize[0.025],Point/@data}] (* now that I see that both plots work, I do my usual and Show them together *) Show[{a,b}] But woe is me: I can see some of the b points as small black dots (not RED!), and several I can't see at all next to the plain black plot of a. This seems to work fine if both a and b are standard Plot[] functions but here I'm mixing Plot[] and ListPlot[] -- I'm definitely teasing the devil. Can someone give me a hint how to make Mathematica Show[] reveal the nice big red dots from a ListPlot in b while also displaying the Plot[] curve? Rob