Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica Mathematica: How to use two x-axis with different units?

  1. Jul 25, 2015 #1

    I've collected data with pairs of { resolution, filesize in bit }.

    Now I would like to use a ListPlot to visualize the data in mathematica.
    My problem is now showing the x-asis two times. One for the filesize in bit (above) and the other for the filesize in KiB (below).

    Code (Text):

        FrameLabel->{"KiB","Resolution (px)", "Bit"},
        GridLinesStyle->{{Gray, Dotted}, {Gray, Dotted}},

    I know, I need to change the second 'all' to something like "take the x axis value and divide it by 1024".


    Can anyone help me out please how to solve this?

    Thanks in advance
  2. jcsd
  3. Jul 25, 2015 #2
    Here's a quick trick - you can plot the KiB one with
    Code (Text):

    plot1=ListPlot[{#1/1024, #2} & @@@ {{35640, 36000000}, {62784,
      64000000}, {97704, 100000000}},
     FrameLabel -> {"KiB", "Resolution (px)"}, Frame -> True,
     GridLines -> Automatic, AxesOrigin -> {1, 0},
     GridLinesStyle -> {{Gray, Dotted}, {Gray, Dotted}},
     FrameTicks -> {{All, None}, {All, None}}, ImagePadding -> 60,
     ImageSize -> 800, PlotRange -> {{0, Automatic}, Automatic}]
    The "#" part is just dividing the first element in each list with 1024. Now, the "Bit" one would be:
    Code (Text):

    plot2=ListPlot[{{35640, 36000000}, {62784, 64000000}, {97704, 100000000}},
     FrameLabel -> {None, "Resolution (px)", "Bit"}, Frame -> True,
     ImagePadding -> 60, GridLines -> Automatic, AxesOrigin -> {1, 0},
     GridLinesStyle -> {{Gray, Dotted}, {Gray, Dotted}},
     FrameTicks -> {{All, None}, {None, All}}, ImageSize -> 800,
     PlotRange -> {{0, Automatic}, Automatic}]
    Then simply use Overlay[{plot1,plot2}] and you'll get what you were looking for. Note: the ImagePadding is crucial, without it the Overlay won't work as it should.
  4. Jul 25, 2015 #3

    thanks for your replay.
    However it still doesn't work :(

    I can separately create the plots - with correct axis.
    But when I use Overlay the 2 plots simply get shown below each other - not combined.

    Best regards
  5. Jul 26, 2015 #4
    Works fine on MMA 10, which version are you using? I can't really think of any other way to do this if Overlay doesn't work, I don't think it's possible to do both using just one ListPlot.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Similar Threads for Mathematica axis different
Mathematica Storing Mathematica output
Mathematica Mathematica to MATLAB
Mathematica Cannot do the integral of the Hyper-geometric function?
Mathematica Cannot Plot This Function in Mathematica
Mathematica While Loop in Mathematica