MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Plotting vectors on a linear function

This is the kind of diagram that the Presentations Application is a great
help with. You just programmatically draw one thing after another as you
would by hand. You could do this diagram with standard Mathematica but it is
much less intuitive. Here is the code in Presentations. I used red circle
points to mark the special points and, just for fun, added a Text label
within the plot. 

<< Presentations` 

Module[{x0 = 4/12},
 (* Data based labels for the axis lines *)
 xticks = 
  CustomTicks[Identity, databased[{x0, 1}], 
   CTNumberFunction -> (InputForm)];
 yticks = CustomTicks[Identity, databased[{1 - x0, 1}]];
  {(* Linear function *)
   Draw[1 - x, {x, 0, 1}],
   (* Arrows attached to the linear function *)
   Table[Arrow[{{x, 1 - x}, {x, 1 - x} + 1/5 {x, 1 - x}}], {x, 0, 1, 
   (* Dotted lines marking a specific point on the function *)
    Line[{{0, 1 - x0}, {x0, 1 - x0}, {x0, 0}}]},
   (* Red circle points marking the ends and selected point  *)
   CirclePoint[#, 3, Black, Red] & /@ {{0, 1}, {x0, 1 - x0}, {1, 0}},
   (* Text label in the plot *),
   Text[Style["Diderot Diagram", 16], {0.5, 1}, {-1, 0}]},
  Axes -> True, AxesLabel -> {Subscript[x, 2], Subscript[x, 1]},
  PlotRange -> {{0, 1.2}, {0, 1.2}},
  PlotRangePadding -> 0.05,
  ImagePadding -> {{10, 20}, {20, 20}},
  Ticks -> {xticks, yticks},
  Method -> {"AxesInFront" -> False},
  ImageSize -> 300]

Since two of the circle points lie on the axes and I don't want the axis
lines to cut through the point coloring I used a special Graphics Method
option to put the axes behind the graphics. I also used data based
CustomTicks to put tick marks only at specific points, and used InputForm on
the x-axis ticks for more compact labeling with fractions.

Mathematica has many special plot types but it doesn't (and couldn't) have a
GeometricDiagram plot type. You have to compose them yourselves.

David Park
djmpark at 

From: Clemens Diderot [mailto:clmnsbchn at] 

Hi all,

I am trying to plot a linear function (y=1-x) together in one graph with a
bunch of vectors, which have their tails on the function. A bit like in this
example here:

Anyone any idea? Much appreciated!


  • Prev by Date: Re: Mathematica 8 3D Plot question
  • Next by Date: Re: Where is ShowGraph?
  • Previous by thread: Re: Plotting vectors on a linear function
  • Next by thread: Re: reverses order of terms producing the string: 1.2 x=