This is just a follow-up of this post:

Animating a rotating disk

Part of the code is:

circ = RegionPlot[x^2 + y^2 <= radius^2, {x, -radius, radius}, 
{y, -radius, radius}, 
Mesh -> 20, MeshStyle -> {{Red}, {Blue}}, BoundaryStyle -> Black, 
PlotStyle -> None]

where radius = 20.

Say that I would like to add a big dot at the coordinates (10,10) on the above disc. My code is:

circ2 = Show[circ, 
Epilog -> Inset[ListPlot[{10, 10}], PlotStyle -> PointSize[0.025]] ]

This however does not work.

Can anyone suggest how to add a point on an already made graphic and save the combined graphic as a single new object?

Thanks a lot...


1 Answer 1

radius = 20;

circ = RegionPlot[
  x^2 + y^2 <= radius^2, {x, -radius, radius}, {y, -radius, radius}, 
  Mesh -> 20, MeshStyle -> {{Red}, {Blue}}, BoundaryStyle -> Black, 
  PlotStyle -> None]

circ2 = Show[circ, Graphics[{PointSize[0.025], Point[{10, 10}]}]]

Mathematica graphics

You could have used ListPlot too, but the point here is that Show combined Graphics into a new Graphics, so you need to feed it with Graphics (ListPlot returns a Graphics object)

circ3 = Show[circ, 
  ListPlot[{{10, 10}}, PlotStyle -> PointSize[0.025]]]

Another option perhaps more similar to what you were trying could be

Show[circ, Epilog -> {PointSize -> Large, Point[{{10, 10}}]}]

Graphics are composed of primitives, directives and options. Primitives are the shapes (Line, Point, Circle, etc). Directives are stuff that affect the shapes, such as color settings, point size, line type, arrow heads, etc. In the same Graphic object you can combine several directives, affecting different primitives (a red circle with a black dot) Options are general to the graphic. AspectRatio, stuff about the axes, etc..

So, a Graphics object is Graphics[{list of primitives and directives}, options]

What Show does is take several Graphics, combine its primitives and directives, and optionally change the general options.

PlotStyle is an option for functions that automatically create Graphics, like Plot and his family. It is NOT a Graphics option. In those functions, it allows among other things to set directives to the stuff you're plotting. So if you're used to writing Plot[f[t], {t, 0, 10}, PlotStyle->something, otheroptions->othervalues] then that something is probably a directive. And probably, otheroptions are general graphic options (or other particular options of the plotting function such as Filling, etc).

So, let's see what you were trying to do with your code

Epilog -> Inset[ListPlot[{10, 10}], PlotStyle -> PointSize[0.025]] ]

You were trying to create a new Graphics with the same primitives and directives than circ, but with an extra option Epilog. Furthermore, you were trying to add as options to the Graphics something that is not an option :P. Epilog just adds more primitives to the Graphics object after it is rendered. It is more or less the same as adding more primitives to the list, except that it allows to do it as an option so it's convenient to add annotations in functions such as Plot. The fact that they are added after the Graphics was rendered also means you can mix 2D and 3D primitives. No different in your case than writing the following

Show[circ, Graphics[{Inset[ListPlot[{10, 10}]]}]]

Moving on. Inset takes a Graphics, Image, cell expression, string, etc, and turns it into a primitive. So, the Graphics object generated by ListPlot now is taken as a whole, with it's own set of axes and everything, and combined with the primitives of circ. Not what you wanted

Final comment. ListPlot if it's given a one dimensional list, interprets all the numbers as y-coordinates. If you want it to plot (x,y) pairs, you need to give it a list of (x, y) pairs. In your case, a list of only one pair, {{10, 10}}

Hope that now you not only understand why your code didn't work but also why what works works

  • $\begingroup$ @yCalleecharan, just edited to explain a little bit more of what I believe to know (I'm not an expert on this area). Glad to help $\endgroup$
    – Rojo
    Commented Feb 12, 2012 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.