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

AI Thread Summary
The discussion focuses on visualizing data in Mathematica using ListPlot, specifically the challenge of displaying two x-axes: one for filesize in bits and another for filesize in KiB. The user, Karl, seeks assistance in modifying the ListPlot to achieve this dual-axis representation. A suggested solution involves creating two separate plots—one for KiB and another for bits—and then using Overlay to combine them. However, Karl encounters issues with Overlay, as the plots appear stacked rather than combined. Another participant notes that the solution works in Mathematica version 10, prompting a query about Karl's software version, as compatibility may affect the functionality of Overlay. The conversation highlights the need for precise adjustments in plotting and the importance of software version compatibility in achieving the desired visualization.
karl21
Messages
2
Reaction score
0
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:
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".

mathematica_x.png


Can anyone help me out please how to solve this?

Thanks in advance
Karl
 
Physics news on Phys.org
Here's a quick trick - you can plot the KiB one with
Code:
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:
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.
 
Hello,

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
Karl
 
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.
 

Similar threads

Replies
3
Views
2K
Replies
8
Views
4K
Back
Top