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

Tags:
1. Jul 25, 2015

### karl21

Hello,

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):

ListPlot[
{{35640,36000000},{62784,64000000},{97704,100000000}},
FrameLabel->{"KiB","Resolution (px)", "Bit"},
Frame->True,
GridLines->Automatic,
AxesOrigin->{1,0},
GridLinesStyle->{{Gray, Dotted}, {Gray, Dotted}},
FrameTicks->{{All,None},{All,All}}
]

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?

Karl

2. Jul 25, 2015

### kontejnjer

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.

3. Jul 25, 2015

### karl21

Hello,

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
Karl

4. Jul 26, 2015

### kontejnjer

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.