3
$\begingroup$

I would like to ask for some help to figure out how can i put two ListLinePlot together with right alignment. Here is what i tried to do:

absnyomplot = 
ListLinePlot[
Table[{(i - 1)*5, fnyomdel[[i]]}, {i, 1, Length[fnyomdel]}], 
InterpolationOrder -> 1, Mesh -> Full, PlotStyle -> Blue, 
Frame -> {True, True, True, False}, 
FrameStyle -> {Automatic, Blue, Automatic, Automatic}, 
ImageSize -> Large, 
FrameLabel -> {"Time[min]", "Abs pressure [kPa]"}, 
LabelStyle -> Directive[Large]];

abshomomplot = 
ListLinePlot[
Table[{(i - 1)*5, fhomdel[[i]]}, {i, 1, Length[fhomdel]}], 
InterpolationOrder -> 1, Mesh -> Full, PlotStyle -> Red, 
Axes -> False, Frame -> {False, False, False, True}, 
FrameTicks -> {None, None, None, All}, 
FrameStyle -> {Automatic, Automatic, Automatic, Red}, 
ImageSize -> Large, 
FrameLabel -> {{" ", "Temperature [\[Degree]C]"}, {" ", " "}}, 
LabelStyle -> Directive[Large]];

Overlay[{absnyomplot, abshomomplot}]

And the result: enter image description here

So the first points of the two plots should be the on the same place on the horizontal axis.

Thanks in advance!

$\endgroup$
  • $\begingroup$ Thank you guys! I appreciate your answers! $\endgroup$ – Molnár István Jun 18 '15 at 13:36
10
$\begingroup$

Use the same ImagePadding for both images.

See also this question.

fnyomdel = Accumulate[RandomReal[{0, 1}, 10]];
fhomdel = Accumulate[RandomReal[{0, 12}, 10]];
absnyomplot = 
  ListLinePlot[
   Table[{(i - 1)*5, fnyomdel[[i]]}, {i, 1, Length[fnyomdel]}], 
   InterpolationOrder -> 1, Mesh -> Full, PlotStyle -> Blue, 
   Frame -> {True, True, True, False}, 
   FrameStyle -> {Automatic, Blue, Automatic, Automatic}, 
   ImageSize -> Large, 
   FrameLabel -> {"Time[min]", "Abs pressure [kPa]"}, 
   LabelStyle -> Directive[Large], ImagePadding -> 50];

abshomomplot = 
  ListLinePlot[
   Table[{(i - 1)*5, fhomdel[[i]]}, {i, 1, Length[fhomdel]}], 
   InterpolationOrder -> 1, Mesh -> Full, PlotStyle -> Red, 
   Axes -> False, Frame -> {False, False, False, True}, 
   FrameTicks -> {None, None, None, All}, 
   FrameStyle -> {Automatic, Automatic, Automatic, Red}, 
   ImageSize -> Large, 
   FrameLabel -> {{" ", "Temperature [\[Degree]C]"}, {" ", " "}}, 
   LabelStyle -> Directive[Large], ImagePadding -> 50];

Overlay[{absnyomplot, abshomomplot}]

enter image description here

(I took the liberty of generating the data. It would be better if you didn't post code that refer to unavailable data).

$\endgroup$
  • $\begingroup$ I ran your exact code and I get a result where the Temperature scale is missing the number scale and the Time label is cut off half way up. I changed the ImagePadding to '75' from '50' to get all the labels to show. However, the Temperature scale is still missing? Any thoughts? I am running MMA 10.1.0 on OS X 10.10.3 ... $\endgroup$ – Joseph Jun 18 '15 at 13:32
  • $\begingroup$ Okay wont happen again! $\endgroup$ – Molnár István Jun 18 '15 at 13:32
  • $\begingroup$ If I change the FrameTicks->{None, None, None, All} in the second ListLinePlot statement to FrameTicks->All, then the numeric Temperature scale appears on the plot $\endgroup$ – Joseph Jun 18 '15 at 13:48
  • $\begingroup$ @Joseph If the ImagePadding is too low, it might crop the FrameLabels and/or the FrameTicks. Use a higher value and you'll see them all. $\endgroup$ – yohbs Jun 18 '15 at 13:58
2
$\begingroup$

As another option for a similar plot, you can rescale the data pretty easily and just plot them with the same plot command.

fnyomdel = Accumulate[RandomReal[{0, 1}, 10]];
fhomdel = Accumulate[RandomReal[{0, 12}, 10]];

ListLinePlot[
 {
  Transpose@{Range@Length@fnyomdel, fnyomdel}
  , Rescale[
   fhomdel, ({Min@#, Max@#} &@fhomdel), ({Min@#, Max@#} &@fnyomdel)]
  }
 , PlotStyle -> {Blue, Red}
 , Frame -> True
 , FrameTicks -> {Automatic
   , Automatic
   , None
   , Transpose@({Rescale[#, {Min@#, Max@#}, {Min@fnyomdel, 
          Max@fnyomdel}], #} &@Range[0, 40, 10])
   }
 , FrameStyle -> {Black, Blue, Black, Red}
 ]

You have to do a little more work to rescale the axis ticks on the right, but it makes some things line up better. From there you can style it however you like.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.