Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am plotting a few curves inside a frame with labels on three of its sides; left, right and bottom. I want legends to be places at the top. The problem which I am facing is that the top label occupies white space and I want it not to do so. In the code it is labeled as "I want this removed". Please guide me how can I remove the top label completely leaving no gap between frame and legends.

Plot[{Sin[h],Cos[h],Tan[h]},{h,5,10},
PlotStyle->{{GrayLevel[0],Dashing[None],Thickness[0.005]},
   {GrayLevel[0],Dashing[Tiny],Thickness[0.005]},
   {GrayLevel[0],Dashing[Small],Thickness[0.005]},
   {GrayLevel[0], Dashing[Medium],Thickness[0.005]}},
 Axes -> False,
 Frame -> True, 
 FrameLabel->{{"Left", Rotate["Right",180 Degree]},{"Bottom","I want this removed"}},
 PlotLegends -> Placed[LineLegend[Automatic, {"sin", "cos", "tan"},
 LegendMarkerSize->{{45, 15}}],Top]]
share|improve this question

2 Answers 2

up vote 1 down vote accepted

One way is to put None instead of "Top" as follows:

Plot[{Sin[h], Cos[h], Tan[h]}, {h, 5, 10}, 
 PlotStyle -> {{GrayLevel[0], Dashing[None], 
    Thickness[0.005]}, {GrayLevel[0], Dashing[Tiny], 
    Thickness[0.005]}, {GrayLevel[0], Dashing[Small], 
    Thickness[0.005]}, {GrayLevel[0], Dashing[Medium], 
    Thickness[0.005]}}, Axes -> False, Frame -> True, 
 FrameLabel -> {{"Left", Rotate["Right", 180 Degree]}, {"Bottom", 
    None}},

 PlotLegends -> 
  Placed[LineLegend[Automatic, {"sin", "cos", "tan"}, 
    LegendLayout -> "Row", LegendMarkerSize -> {{45, 15}}], {0.5, 
    1.002}]]

Then you get this: enter image description here

If you need to have an additional label on top above the legends, use Column to combine them as here:

  Column[{
  Style["top", 10, "Times New Roman"],
  Plot[{Sin[h], Cos[h], Tan[h]}, {h, 5, 10}, 
   PlotStyle -> {{GrayLevel[0], Dashing[None], 
      Thickness[0.005]}, {GrayLevel[0], Dashing[Tiny], 
      Thickness[0.005]}, {GrayLevel[0], Dashing[Small], 
      Thickness[0.005]}, {GrayLevel[0], Dashing[Medium], 
      Thickness[0.005]}}, Axes -> False, Frame -> True, 
   FrameLabel -> {{"Left", Rotate["Right", 180 Degree]}, {"Bottom", 
      None}},

   PlotLegends -> 
    Placed[LineLegend[Automatic, {"sin", "cos", "tan"}, 
      LegendLayout -> "Row", LegendMarkerSize -> {{45, 15}}], {0.5, 
      1.001}], ImageSize -> 300
   ]
  }, Alignment -> Center]

which gives the following picture: enter image description here

However, what I usually do is the following:

 Plot[{Sin[h], Cos[h], Tan[h]}, {h, 5, 10}, PlotRange -> {-3.5, 4.5}, 
 PlotStyle -> {{GrayLevel[0], Dashing[None], 
    Thickness[0.005]}, {GrayLevel[0], Dashing[Tiny], 
    Thickness[0.005]}, {GrayLevel[0], Dashing[Small], 
    Thickness[0.005]}, {GrayLevel[0], Dashing[Medium], 
    Thickness[0.005]}}, Axes -> False, Frame -> True, 
 FrameLabel -> {{"Left", Rotate["Right", 180 Degree]}, {"Bottom", 
    "Top"}},

 PlotLegends -> 
  Placed[LineLegend[Automatic, {"sin", "cos", "tan"}, 
    LegendLayout -> "Column", LegendFunction -> "Frame", 
    LegendMarkerSize -> {{45, 15}}], {0.85, 0.77}]]

yielding this: enter image description here

share|improve this answer
    
This provides more flexibility and I think its a better way. Legends also look more beautiful this way. gratitude! –  naveed Aug 14 '13 at 16:22

You mean Like this? You can adjust ImagePadding on all 4 edges. It has the same layout for all other Frame related options

Plot[{Sin[h], Cos[h], Tan[h]}, {h, 5, 10},
 PlotStyle -> {{GrayLevel[0], Dashing[None], Thickness[0.005]},
   {GrayLevel[0], Dashing[Tiny], Thickness[0.005]}, {GrayLevel[0], 
    Dashing[Small], Thickness[0.005]}, {GrayLevel[0], Dashing[Medium],
     Thickness[0.005]}},
 Axes -> False, Frame -> True, 
 FrameLabel -> {{"Left", Rotate["Right", 180 Degree]}, {"Bottom", 
    "I want this removed"}},
 PlotLegends -> Placed[LineLegend[Automatic, {"sin", "cos", "tan"},
    LegendMarkerSize -> {{45, 15}}], Top], 
 ImagePadding -> {{30, 30}, {30, 2}}
 ]

Mathematica graphics

before

Mathematica graphics

share|improve this answer
    
Not quite I am afraid. The picture you Posted can be achieved by just removing the labels. As I mentioned in question three of them are required. Just top label is the problem. I know I can remove it by removing text from "" marks but it will then leave white space and legends will be at some distance. I want that distance to be removed keeping other three labels at their places. –  naveed Aug 14 '13 at 3:16
    
Ok this makes sens now. Let me check what have you done. –  naveed Aug 14 '13 at 3:17
    
yes you did the right thing. Webpage was not refreshed properly so I could not see other labels. I thought you removed all of them. This is what i wanted. Now i will learn more about ImagePadding. Rest is up to me thanks for your kind help. –  naveed Aug 14 '13 at 3:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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