Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am having a problem using custom tick specifications along with AspectRatio -> Full.
The problem affects both Ticks and FrameTicks.

An example of the problem:

x = MapThread[{#, #2, {0, 0.007}} &, {100 Range@5, {"One","Two","Three","Four","Five"}}];

p = ListPlot[Array[Log, 600], Ticks -> {x}, AspectRatio -> Full, ImageSize -> {250, 250}]

Mathematica graphics

Giving an explicit AspectRatio produces the output I desire:

Show[p, AspectRatio -> 1]

Mathematica graphics

A plot without the custom ticks is not distorted:

Show[p, Ticks -> Automatic]

Mathematica graphics

I wish to understand what is causing the problem and find a way to work around it besides specifying a numeric AspectRatio. I could add a routine to calculate the aspect ratio from the image size but I would rather find a way to make AspectRatio -> Full work as intended.

share|improve this question
    
AspectRatio::aspr: Value of option AspectRatio -> Full is not a finite positive number or Automatic. >> :D –  belisarius Feb 15 '13 at 20:13
    
@belisarius Are you saying this has been removed in later versions? v7 help says: AspectRatio->Full specifies that a graphic should be stretched so as to fill out its enclosing region in a Grid or related construct. –  Mr.Wizard Feb 15 '13 at 21:00
    
Is the result of AbsoluteOptions[ListPlot[Range@5, AspectRatio -> Full], AspectRatio] on v8.0 –  belisarius Feb 15 '13 at 21:33
    
On my computer, the tick height is proportional to the horizontal PlotRange. The formula seems to be "absolute tick height" = "horizontal PlotRange" X "specified tick height". This does not correspond to what I see on your first graphics –  andre Feb 15 '13 at 22:55
1  
I'm running v9.0.1 on OS X 10.6.8. I get the same output as you (@Mr.Wizard) do when I evaluate your code. –  m_goldberg Feb 16 '13 at 3:04
show 7 more comments

2 Answers 2

not a answer

With my Mathematica 8.0.4 on Win 7 your code :

x = MapThread[{#, #2, {0, 0.007}} &, {100 Range@5, {"One", "Two", 
     "Three", "Four", "Five"}}];

p = ListPlot[Array[Log, 600], Ticks -> {x}, AspectRatio -> Full, 
  ImageSize -> {250, 250}]

gives :

enter image description here

This graphics is not exactly the same as yours

One can see that the ticks height is ~ -4, in accordance with the formula : "absolute tick height" = "horizontal PlotRange" X "specified tick height"

here : ~4 = 600 0.007

If I try another PlotRange :

x = MapThread[{#, #2, {0, 0.007}} &, {100 Range@5, {"One", "Two", 
     "Three", "Four", "Five"}}];

p = ListPlot[Array[Log, 600], Ticks -> {x}, AspectRatio -> Full, 
  ImageSize -> {250, 250}, PlotRange -> {{1, 300}, Automatic}]

I get :

enter image description here

corresponding to 2 = 300 0.007

etc ...

Note

It is easier to play with "positive" ticks and it doesn't change the problem. Example :

x = MapThread[{#, #2, (* here is the difference --> *) {0.007, 0}} &, {100 Range@5, {"One", "Two", 
     "Three", "Four", "Five"}}];

p = ListPlot[Array[Log, 600], Ticks -> {x}, AspectRatio -> Full, 
  ImageSize -> {250, 250}, PlotRange -> {{1, 300}, Automatic}]

enter image description here

Once again : ~2 = 300 0.007

share|improve this answer
    
What you show here is what I see with v.9.0.1 on OS X 10.6.8 with one difference: I see the y-axis always positioned at x = 0. The ticks marks, however, are exactly the same as you show. –  m_goldberg Feb 16 '13 at 14:35
add comment

I believe andre already answered the question. I'm only providing this as a reference to myself and others who might need to specify the ticks while having AspectRatio -> Full.

The reason I set AspectRatio to Full is so that I can have more control of the final figure. To try to fix Mr. Wizards problem we can remove the tick length information.

x = MapThread[{#, #2} &, {100 Range@5, {"One", "Two", "Three", "Four", "Five"}}];
p = Framed@ListPlot[Array[Log, 600], Ticks -> {x}, AspectRatio -> Full, ImageSize -> {250, 250}]

This gives us a plot with inverted tick marks.

enter image description here

The key part with the ticks is the information that andre provided:

"absolute tick height" = "horizontal PlotRange" X "specified tick height"

To create the figure we can do:

basicPlot = ListPlot[Array[Log, 600]];
xlen = First@Differences@AbsoluteOptions[basicPlot, PlotRange][[1, 2, 1]];
tickLength = .1;
x = MapThread[
        {#, #2, {0, tickLength/xlen}} &,
        {100 Range@5, {"One", "Two", "Three", "Four", "Five"}}
    ];

tickLength is set to .1, in units of the actual plot. This should be changed to the desired length of the ticks.

As a bonus I like to specify where I wish to place my x and y labels:

xLabel[x_, pos_] := Graphics[{
        Text[Style[x, 10, FontFamily -> "Arial"], pos, {0, 1}]
    }];
yLabel[x_, pos_] := Graphics[{
        Text[Style[x, 10, FontFamily -> "Arial"], pos, {0, 1}, {0, 1}]
    }];

Now we draw the final plot:

Framed@Show[
  basicPlot,
  xLabel["X Label", {300, -1}],
  yLabel["Y Label", {-100, 3}],
  AspectRatio -> Full,
  Axes -> None,
  FrameTicks -> {x, Automatic, None, None},
  Frame -> {True, True, True, True},
  ImagePadding -> {{45, 5}, {45, 5}},
  PlotRangeClipping -> False,
  ImageSize -> {250, 250}
  ]

enter image description here

Notice how I use ImagePadding to control how much space I will leave for my labels and where the figure will be placed in the space specified by ImageSize. PlotRangeClipping needs to be set to False so that the labels can be displayed. If you need to clip then mask it.

mask = Graphics[{
    Gray,
    Polygon[{
      ImageScaled[{0, 0}],
      ImageScaled[{0, 1}],
      ImageScaled[{1, 1}],
      ImageScaled[{1, 0}],
      ImageScaled[{0, 0}],
      Scaled[{0, 0}],
      Scaled[{1, 0}],
      Scaled[{1, 1}],
      Scaled[{0, 1}],
      Scaled[{0, 0}],
      ImageScaled[{0, 0}]
      }]
    }];
Framed@Show[
  basicPlot,
  mask,
  xLabel["X Label", {300, -1}],
  yLabel["Y Label", {-100, 3}],
  AspectRatio -> Full,
  Axes -> None,
  FrameTicks -> {x, Automatic, None, None},
  Frame -> {True, True, True, True},
  ImagePadding -> {{45, 5}, {45, 5}},
  PlotRangeClipping -> False,
  ImageSize -> {250, 250}
  ]

enter image description here

In mask change the color to White. Once you are done with the final edits to the figure remove the outside frame.

share|improve this answer
    
Thanks for the answer! Sadly, for your "final plot" I get this: i.stack.imgur.com/T4vkp.png Apparently some part of this bug has been fixed in later versions, but a form of it still remains. –  Mr.Wizard Apr 9 '13 at 22:25
    
@Mr.Wizard, what mma version are you using? So, just to be clear the above output was for mma 9.0.1. I still have mm8, I'll try it there. –  jmlopez Apr 9 '13 at 22:30
    
v7 still :^) -- anyway, I'm sure this will be helpful to others. –  Mr.Wizard Apr 9 '13 at 22:31
    
Good to know. I just checked v8, it works fine there. –  jmlopez Apr 9 '13 at 22:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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