2
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ @MikeHoneychurch This is just a toy example. What I am actually plotting is more complicated to pre determine the values. $\endgroup$ Commented Dec 9, 2014 at 20:51
  • $\begingroup$ 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). $\endgroup$ Commented Dec 9, 2014 at 21:03

1 Answer 1

4
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ 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"? $\endgroup$ Commented Dec 9, 2014 at 20:57
  • 1
    $\begingroup$ @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. $\endgroup$
    – kglr
    Commented Dec 9, 2014 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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