MathGroup Archive 2002

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

Search the Archive

Re: ImageSize, ImageMargins and ImageRegion

  • To: mathgroup at smc.vnet.net
  • Subject: [mg38051] Re: ImageSize, ImageMargins and ImageRegion
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Thu, 28 Nov 2002 14:07:45 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

David Park wanted to control the positioning of graphics in his notebook.
---------

The following might help:

In[1]:=
  Plot[Sin[x],{x,0,2 Pi}, ImageSize->{500,300}, PlotRegion->{{0.2,1},{0,1}}
];

In[2]:=
  Plot3D[x^2+y^2, {x,-3,3}, {y,-3,3}, ImageSize->{500,300},
PlotRegion->{{0.2,1},{0,1}} ];


But the lines above aren't the same using the mouse to adjust the graphic.
That sort of thing is controlled with a Cell option called CellMargins.  If
you want to change the positioning of all Graphics you can modify the Style
Sheet (hint, after you go in the Style Sheet the style for Graphics cells is
next to style for Output cells).  But then maybe you want to automatically
get specific graphics at a certain position without using the mouse, or the
Option Inspector.  If that is what you want MyPlot below does the same as
Plot, except it has a CellMargins option!  Of course you can adapt this for
your Draw functions, Plot3D, ContourPlot, etc.
--------------

In[3]:=
 Options[MyPlot]=Join[Options[Plot], { CellMargins->{{4,4},{4,4}} } ];


MyPlot[expr_,pltRange_,opts___?OptionQ]:= 
  Module[{margins,df,grOptions,gr}, 
 
{margins,df}={CellMargins,DisplayFunction}/.Flatten[{opts,Options[MyPlot]}];
    grOptions=DeleteCases[ Flatten[{opts}], _?(First[#]===CellMargins&)];
    If[df===$DisplayFunction,
      gr=Plot[expr, pltRange, DisplayFunction->Identity, Evaluate@grOptions
];
      NotebookWrite[ SelectedNotebook[], 
         Cell[GraphicsData["PostScript", DisplayString[gr]], "Graphics",
CellMargins->margins] 
      ],
      (*else*)
      Plot[expr, pltRange, Evaluate@grOptions ]
  ] ]


In[5]:=
  MyPlot[Sin[x],{x,0,6 Pi}, Frame->True, CellMargins->{{70,0},{0,30}} ];



----------
Regards,
  Ted Ersek

Download my latest tricks from: 
http://www.verbeia.com/mathematica/tips/Tricks.html
and  
http://www.verbeia.com/mathematica/tips/GraphicsTricks.html




  • Prev by Date: Simplification ?
  • Next by Date: Shortcut for AlternatingGroup[9] computation
  • Previous by thread: ImageSize, ImageMargins and ImageRegion
  • Next by thread: Re: Number of cyclic subgroups of order 15 in Z_90 (+) Z_36