2

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.

1 Answers1

2

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

Daniel Huber
  • 51,463
  • 1
  • 23
  • 57
  • 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]}}] – Jacinto Paulo Feb 27 '24 at 09:52
  • You can only have one variable, but you may rescale the variable. Eg: {fun1[x],fun2[1+3x]} – Daniel Huber Feb 27 '24 at 11:19