2

In here, I have asked a question about the use of Tick (FrameTicks).

An extension to the question is,

x1 = Range[0, 10, 1];
y1 = Sin[x1];

(* This gives the automatic points of x-axis values,2,4,6,8 *)
ListLinePlot[Thread[{x1, y1}]]


(* This takes too many values for x-axis (bottom one)  *)
ListLinePlot[
    Thread[{x1, y1}], 
    FrameTicks -> {
        {Automatic, Automatic}, 
        {Thread[{x1, Exp[x1] // N}], x1}
    }, 
    Mesh -> Full, 
    Frame -> True
]

How do I use the automatic ticks (2,4,6,8) and Exp[] those values instead of the whole list of xlst?

Chen Stats Yu
  • 4,986
  • 2
  • 24
  • 50
  • @MikeHoneychurch This is just a toy example. What I am actually plotting is more complicated to pre determine the values. – Chen Stats Yu Dec 09 '14 at 20:51
  • Say for a particular dataset, i first need to plot (guess) from 0 to 100 with 20 points. If the graph is good, I would want to plot more points in the interval. If the graph is not good, I would want to use less points. Also, when I Exp[], the values a "longer", they occupy more space. So I want to find a lazy way to deal with it. For the actual problem, the y values come from NMaximize, so it's a trial and error process for plot. (to determine the ranges of interest). – Chen Stats Yu Dec 09 '14 at 21:03

1 Answers1

4

You can use FindDivisions:

divs = FindDivisions[Through@{Min, Max}@x1, 5]
(* {0,2,4,6,8,10} *)

ListLinePlot[Thread[{x1, y1}], 
 FrameTicks -> {{Automatic, Automatic}, {Thread[{divs, Exp[divs] // N}], x1}},
 Mesh -> Full,  Frame -> True]

enter image description here

Or, post-process the frame ticks to change the labels:

xticks = (FrameTicks /. AbsoluteOptions[llpa, FrameTicks])[[1]] /.
        {x_, x_, y___} :> {x, Exp[x], y};
ListLinePlot[Thread[{x1, y1}], 
 FrameTicks -> {{Automatic, Automatic}, {xticks, x1}}, Mesh -> Full, Frame -> True]

enter image description here

Note: AbsoluteOptions does not always work as expected.

kglr
  • 394,356
  • 18
  • 477
  • 896
  • I assume that mathematica has some clever way of choosing how many ticks to tick? Is there another way, to approach this, without having to set 5 intervals? So that the number of points are still determined by "automatic"? – Chen Stats Yu Dec 09 '14 at 20:57
  • 1
    @Chen, i posted an alternative method using AbsoluteOptions to get the FrameTicks. Although it seems to work here, AbsoluteOptions is known to be unrealiable in general. – kglr Dec 09 '14 at 21:18