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

Click For Summary

Discussion Overview

The discussion revolves around the challenge of visualizing data in Mathematica using a ListPlot with two x-axes representing different units: filesize in bits and filesize in KiB. Participants explore methods to achieve this dual-axis representation.

Discussion Character

  • Technical explanation, Debate/contested, Experimental/applied

Main Points Raised

  • One participant, Karl, seeks assistance in displaying two x-axes in a ListPlot, one for filesize in bits and another for filesize in KiB.
  • Another participant suggests a method involving two separate ListPlots for each unit, using an Overlay function to combine them, while also noting the importance of ImagePadding.
  • Karl responds that the suggested method does not work as intended, as the plots appear stacked rather than overlaid.
  • A further participant questions the version of Mathematica being used, implying that compatibility issues may affect the functionality of the Overlay method.

Areas of Agreement / Disagreement

Participants have not reached a consensus on a solution, as there are differing experiences with the Overlay function and its effectiveness in combining the plots.

Contextual Notes

There may be limitations related to the specific version of Mathematica being used, which could affect the implementation of the proposed solutions.

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 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 8 ·
Replies
8
Views
5K