2
$\begingroup$

Let's consider the following simple example

Clear["Global`*"];

S0 = Plot[Sin[x], {x, -10, 10}, Frame -> True]

enter image description here

Now, I want to add a second horizontal axis (at the top of the frame) in which 1 unit of the lower axis corresponds to 5.2 units in the top axis. Any ideas?

Merry Christmas to all!

$\endgroup$
3
  • 1
    $\begingroup$ You can use FrameTicks -> {{Automatic,None},{Automatic,Table[{i,5.2*i},{i,-10,10,5}]}} $\endgroup$
    – Rom38
    Dec 25 '19 at 10:45
  • 1
    $\begingroup$ closely related/ possible duplicate: Two Axes, One plot $\endgroup$
    – kglr
    Dec 25 '19 at 11:16
  • $\begingroup$ @kglr If possible, please post a quick answer. $\endgroup$
    – Vaggelis_Z
    Dec 25 '19 at 13:19
3
$\begingroup$
Plot[Sin[x], {x, -10, 10}, Frame -> True, 
 FrameTicks -> {{Automatic, Automatic},
      {All, Charting`FindTicks[{0, 1}, {0, 5.2}][-10, 10]}}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Nice! One question: why the numbers of the top axis come with a dot, e.g., 20. instead of 20 (as in the lower axis)? Is there a way to remove the dots? $\endgroup$
    – Vaggelis_Z
    Dec 25 '19 at 13:43
  • $\begingroup$ @Vaggelis_Z, when we tick spec is a Charting`FindTicks[{0, 1}, {0, 5.2}] that function is evaluated at automatically computed min and max for associated axis. If we provide integer arguments to this function using Charting`FindTicks[{0, 1}, {0, 5.2}][-10,10] we do get integer labels. $\endgroup$
    – kglr
    Dec 25 '19 at 14:19

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