Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

RE: one question about draw graph in frame

  • To: mathgroup at smc.vnet.net
  • Subject: [mg49013] RE: [mg49001] one question about draw graph in frame
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Tue, 29 Jun 2004 04:49:40 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Daohua Song [mailto:ds2081 at columbia.edu]
To: mathgroup at smc.vnet.net
>Sent: Monday, June 28, 2004 10:14 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg49013] [mg49001] one question about draw graph in frame
>
>
>Dear group,
>      i draw a graph in frame model and can use framticks to 
>let the upper 
>and right have some scale you want. My question is that if it 
>is possible 
>to let the mathematics to do it automatically? you know, to write down 
>every ticks is annoying.
>      e.g
>      \!\(Plot[x\^2, {x,
>      0, 1}, Frame -> True, FrameTicks -> {{0,  .5,  .7, 1}, {0,  .5, 
>1}}]\)
>      Any suggestion will be appreciated!
>daohua
>
>


One option would be to use a tickfunction.  Either get it from the book "Mathematica Graphics" by Tom Wickham-Jones, or from the Graphics`Graphics` standard package:

In[39]:= <<Graphics`Graphics`

In[41]:= With[{tx = LinearScale[0,2], ty = LinearScale[0,4]},
  Plot[x^2, {x,0,2}, Frame -> True, FrameTicks -> {tx, ty, tx, ty}]]

The disadvantage here is that you don't get the minor ticks. You might delve further into the package to get those too, but here is another hacker's method to reach for the Automatic tick marks:


First make a "dummy plot" with the intended plot ranges (alternatively -- if not too expensive -- just plot your function):

In[35]:= Plot[{}, {x, 0, 2}, Frame -> True, PlotRange -> {{0, 2}, {0, 4}}, 
  DisplayFunction -> Identity]


Now we extract the frameticks generated automatically:

In[36]:= {tx, ty, tx0, ty0} = FrameTicks /. AbsoluteOptions[%, FrameTicks];

tx and ty contain the ticks including position labels for the x- and y-axis, tx0, ty0 just the plain ticks. You now may reuse them ad lib, e.g.:


In[37]:=
Plot[x^2, {x, 0, 2}, Frame -> True, FrameTicks -> {tx, ty0, tx0, ty}]


--
Hartmut Wolf


P.S.: Perhaps best download the packages "ExtendGraphics" by Tom Wickham-Jones from the WRI web site an then easily do:

In[48]:= << ExtendGraphics`ticks`

In[49]:= Options[TickFunction]
Out[49]=
{MajorLength -> {0.00625, 0}, MinorLength -> {0.003125, 0}, 
 MajorStyle -> {Thickness[0.002]}, MinorStyle -> {Thickness[0.001]}, 
 TextFunction -> Automatic, TickLabels -> Automatic, TickNumbers -> {8, 32}}

In[50]:= ?TickFunction
"TickFunction is a function that can be used with the Ticks option to alter 
the appearance of tick marks."

In[52]:=
Plot[x^2, {x, 0, 2}, Frame -> True, FrameTicks -> TickFunction]


  • Prev by Date: RE: PlotLabel with assigned variables *and* on several lines
  • Next by Date: File reference in Front End
  • Previous by thread: Re: one question about draw graph in frame
  • Next by thread: RE: one question about draw graph in frame