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.

With

ListLinePlot [
 {13, 6, 2, 2, 3},
 AxesOrigin -> {1, 0},Background -> GrayLevel@0.95,
 GridLines -> None, ImageSize -> 300,
 ImageMargins -> 0, PlotLabel -> "XYZ",
 Filling -> Bottom, PlotMarkers -> Automatic, Frame -> True]

I obtained:

enter image description here

  1. I would like to move the PlotLabel "XYZ" into the upperright corner of the plotting area.

  2. The Background-option also colors the background of the axes-values and the label, but I only want to color (like in Excel) the actual plotting-area.

I could think of some complicated ways to achieve this, but would like to see a short and handy solution.

Thanks in advance for your help.

share|improve this question
    
This is not elegant but it works...: 1. Generate your background: data = {13, 6, 2, 2, 3}; background = RegionPlot[x y <= Length[data] Max[data], {x, 1, Length[data]}, {y, 0, Max[data]}, PlotStyle -> GrayLevel@0.95]; 2. Display it together with your plot (implementing Öskå's suggestion): Labeled[ Show[background, ListLinePlot[data,AxesOrigin -> {1, 0},GridLines -> None, ImageSize -> 300, ImageMargins -> 0]],"XYZ", {{Top, Right}}]. –  Boson May 23 at 12:37
    
One of the two questions here is a duplicate of: Changing the background color of a framed plot. –  Jens May 23 at 14:39

3 Answers 3

up vote 7 down vote accepted

You can put there a Rectangle ;)

ListLinePlot[{13, 6, 2, 2, 3}, Axes -> False, Frame -> True, PlotMarkers -> Automatic,
                               Filling -> Bottom, BaseStyle -> 18,
             Prolog -> {GrayLevel@0.95, Scaled /@ Rectangle[{0, 0}, {1, 1}]},
             Epilog -> {Inset["XYZ", Scaled[{.9, .9}]]}]

enter image description here

share|improve this answer
1  
I was having this :( You are way too fast –  Öskå May 23 at 12:38
    
I like that solution. (It is better than mine.) –  Boson May 23 at 12:39
    
@Öskå@Kuba - ALMOST what I was looking for. ALMOST, because I would like to see "XYZ" inside the plotting area. Thank you so far. And yes, answers here are very fast :) –  eldo May 23 at 12:45
1  
@Kuba I need AxesOrigin -> {1, 0}, to make it look better, maybe it's just v8. Picture without. –  Öskå May 23 at 12:53
    
Or you could add it in your answer, I guess it's not shadowing anything in v9. –  Öskå May 23 at 12:57

You can get the background effect you want by double plotting your data. The plot label can be shifted using Row and Spacer.

ListLinePlot[{{13, 6, 2, 2, 3}, {13, 6, 2, 2, 3}},
  AxesOrigin -> {1, 0},
  Filling -> {1 -> Bottom, 2 -> Top},
  FillingStyle -> {2 -> GrayLevel @ 0.95},
  ImageSize -> 300,
  ImageMargins -> 0,
  PlotLabel -> Row[{"", "XYZ"}, Spacer[250]]]

plot

share|improve this answer

Try this:

    Show[{
  ListLinePlot[{13, 6, 2, 2, 3}, AxesOrigin -> {1, 0}, 
   Filling -> Bottom,
   GridLines -> None, ImageSize -> 300, ImageMargins -> 0, 
   Epilog -> Inset[Style["XYZ", 16], Scaled[{0.9, 0.9}]]],
  Graphics[{Opacity[0.1], Rectangle[{1, 14.5}, {5.05, 0}]}]
  }]

Looking as follows: enter image description here

If you need the same color below and above the line, remove the option Filling.

share|improve this answer
    
@Kuba - Thanks, Exactly what I needed –  eldo May 23 at 12:53
    
The fact that the rectangle is dependent on the data (Rectangle[{1, 14.5}, {5.05, 0}]) is quite bad IMO. –  Öskå May 23 at 12:55
    
@Öskå - Thanks for editing (I had preset options early in the program) - I can live with Kuba's solution because the program "knows" the rectangle-values. –  eldo May 23 at 13:01
    
@ Öskå Yes, It is unsatisfactory. It is fast to do though. You just put the stuff inside manipulate and get these numbers within seconds. –  Alexei Boulbitch May 23 at 15:01

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.