Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: Plot Axis Unit Conversions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98878] Re: Plot Axis Unit Conversions
  • From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
  • Date: Mon, 20 Apr 2009 19:12:52 -0400 (EDT)
  • References: <gsh17u$or$1@smc.vnet.net>

Dear unknown owen,

It is pretty easy to generate a figure with axes both in meters and in
inches using FrameTicks. However, getting the ticks look good, i.e.
choosing nice values (preferably automatically) is a different matter.
But I've got a solution for you:

Apart from values as Automatic and None, FrameTicks can be given a
function as parameter which gets the minimum and maximum value for the
given axis and which then should generate the major and minor ticks
based on these values. My trick involves using Plot itself for picking
nice values.

This is my FrameTicks function inchScale:

inchScale[min_, max_] := Apply[{2.54/100 #1, ##2} &, AbsoluteOptions[
    Plot[x, {x, 100/2.54 min, 100/2.54 max}, Frame -> True,
     FrameTicks -> {Automatic, None, None, None}], FrameTicks][[1, 2,
    1]], 1]

and this is how you use it:

Plot[Sin[x], {x, 0, 10}, Frame -> True,
 FrameTicks -> {Automatic, Automatic, inchScale, inchScale},
 FrameLabel -> {"x-axis (in m)", "y-axis (in m)", "x-axis (in inch)",
   "y-axis (in inch)"}]

Pretty easy, eh?

To explain the inchScale gibberish: I first let Mathematica generate a
simple plot of f[x]=x with the range min,max converted to inches (it
is not necessary that it's the same plot as long ast ist has the same
range; for speed it'd better be a simple plot). inchScale gets min,max
from your actual plot.

I then have Mathematica generate the plot with FrameTicks and use
AbsoluteOptions to get a peek at the value of FrameTicks used in this
plot. The [[1, 2, 1]] part is to peel off some superfluous levels of
brackets and stuff. The last step involves scaling the inches back to
meters so that they fit in the same plot.

Hope this helps.

Cheers - Sjoerd



On Apr 20, 7:29 am, unknowno... at gmail.com wrote:
> Hello everyone,
>
> I am working on a notebook involving a flutter analysis of a flat
> plate in a wind tunnel. All of the equations involve metric units, but
> most of the physical measurements of size I have are in inches. In
> order to maintain a consistent system of units, I would like to plot
> the axis units in metric and English units. Specifically, I have a
> plot for the critical flutter speed in units of m/s versus the chord
> length in meters, and I want to overlay an x-axis, possibly on the
> top, that will display the equivalent length in inches (i.e,
> xinches=x*10000/254) without messing up the graph. At the very least,
> I would like to display it in centimeters instead of meters for better
> clarity. I do NOT want to recalculate the function using inches - just
> display the conversion. It would be nice if I could display it in both
> inches and centimeters at the same time.
>
> This is an absolute breeze to do in another system, but I haven't been
> able to find anything specifically dealing with scaling of axes for
> Mathematica. Anyone have any ideas?
>
> Thanks very kindly!



  • Prev by Date: Re: running mathematica notebooks without interface
  • Next by Date: Preserving Notebook Changes
  • Previous by thread: Re: Plot Axis Unit Conversions
  • Next by thread: Re: Plot Axis Unit Conversions