2
$\begingroup$

I want to make a plot with two x-axes, one on the bottom and another on the top, where the variables are different but the function is the same. For instance, let f = y(a,b). How can I have in the same plot y(a) and y(b), where a is running on the bottom x-axis and b is running on the top x-axis?

I saw a similar problem in How to add second, linearly rescaled X-axis on the top frame? , however, I thought it only works for tables.

$\endgroup$

1 Answer 1

2
$\begingroup$

The method from your link also works for plots (at least in version 14.0):

oldXRange = {0, Pi}; newXRange = {Pi/1, 3/2  Pi};
Plot[{Sin[x], Sin[x + Pi]}, {x, 0, Pi}, Frame -> True, 
 FrameTicks -> {{Automatic, Automatic}, {Automatic, 
    Charting`FindTicks[oldXRange, newXRange]}}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Hi, Daniel! Thanks for you answer! However, it does not work when I want for two different variables, like: Plot[{Sin[y], Sin[x + Pi]}, {{x, 0, Pi}, {y, 0, Pi}}, Frame -> True, FrameTicks -> {{Automatic, Automatic}, {Automatic, Charting`FindTicks[oldXRange, newXRange]}}] $\endgroup$ Commented Feb 27 at 9:52
  • $\begingroup$ You can only have one variable, but you may rescale the variable. Eg: {fun1[x],fun2[1+3x]} $\endgroup$ Commented Feb 27 at 11:19

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.