2
$\begingroup$

I am trying to label the frame of an overlay plot I have made. However, it is not working at all. Here is my code:

A2 = A[[15 ;; 31, 2]];
PlotA = ListLinePlot[A2, PlotStyle -> Red, ImagePadding -> 25, 
   Frame -> {True, False, True, True}, 
   FrameTicksStyle -> Directive[15], 
   FrameTicks -> {{{2, 1995}, {7, 2000}, {12, 2005}, {17, 2010}}, 
     None, {{2, 1995}, {7, 2000}, {12, 2005}, {17, 2010}}, All}, 
   FrameStyle -> {Automatic, Automatic, Automatic, Red}, 
   FrameLabel -> {{False, "Consumption"}, {"Year", "Year"}}];
C2 = Consumption[[1 ;; 17, 2]];
PlotC = ListLinePlot[C2, PlotStyle -> Blue, ImagePadding -> 25, 
   Frame -> {False, True, False, False}, 
   FrameTicksStyle -> Directive[15], 
   FrameStyle -> {Automatic, Blue, Automatic, Automatic}, 
   FrameLabel -> {{False, "Affordability"}, {False, False}} ];
Overlay[{PlotA, PlotC}]

enter image description here

Am I going about it the right way? When the plot is displayed, no labels are visible.

$\endgroup$
2
  • $\begingroup$ Please include a data sample. Your problem probably boils down to increasing ImagePadding -> . $\endgroup$ – Kuba May 21 '14 at 11:33
  • $\begingroup$ Josh, you have asked two questions and you haven't accepted any so far. Please check this link regarding why accepting answers. $\endgroup$ – Öskå May 21 '14 at 20:10
2
$\begingroup$

You can also do the following with any plot:

A2 = RandomReal[1, 16];
C2 = RandomReal[1, 17];
PlotA = ListLinePlot[A2, PlotStyle -> Red, ImagePadding -> 25, 
   Frame -> {True, False, True, True}, 
   FrameTicksStyle -> Directive[15], 
   FrameTicks -> {{{2, 1995}, {7, 2000}, {12, 2005}, {17, 2010}}, 
     None, {{2, 1995}, {7, 2000}, {12, 2005}, {17, 2010}}, All}, 
   FrameStyle -> {Automatic, Automatic, Automatic, Red}];
PlotC = ListLinePlot[C2, PlotStyle -> Blue, ImagePadding -> 25, 
   Frame -> {False, True, False, False}, 
   FrameTicksStyle -> Directive[15], 
   FrameStyle -> {Automatic, Blue, Automatic, Automatic}];
plot = Overlay[{PlotA, PlotC}]

Labeled[plot, 
  {Rotate[Style["Affordability", Blue], 90 °], 
   Rotate[Style["Consumption", Red], 90 °], 
   "Year", "Year"}, 
  {Left, Right, Top, Bottom}]

Or as kguler points out in his comment:

Labeled[plot, 
  {Style["Affordability", Blue], 
   Style["Consumption", Red], 
   "Year", "Year"}, 
  {Left, Right, Top, Bottom}, RotateLabel -> True]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ You can also use the option RotateLabel->True to get rotated labels for Left and Right sides (+1). $\endgroup$ – kglr May 21 '14 at 12:27
  • $\begingroup$ @kguler Thank you, I edited accordingly :) $\endgroup$ – Öskå May 21 '14 at 12:33
1
$\begingroup$

Using

A2 = RandomReal[1, 16];
C2 = RandomReal[1, 17];

and increasing ImagePadding -> 55:

enter image description here

Notice that you have to use None not False if you don't want particular label.

$\endgroup$
2
  • $\begingroup$ Thank you very much, yes it was just the ImagePadding that caused the error. $\endgroup$ – Josh May 21 '14 at 12:08
  • $\begingroup$ @Josh Great :) please, take a tour $\endgroup$ – Kuba May 21 '14 at 12:10

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.