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 have a DateListPlot, much the same as below, that I want to overlay text onto. I'd like the text to be wrapped in a frame much the same way as the legend box is, but I can't figure out how to do it. I've tried the cheaters way of putting a rectangle beneath the text, but then I can't get the rounded corners to match the legend box. I am also unable to changed the thickness of the legend frame.

Any help would be greatly appreciated.

DateListPlot[{FinancialData["IBM", "Jan. 1, 2008"], 
  FinancialData["GOOG", "Jan. 1, 2008"]}, Joined -> False, 
 ImageSize -> Large, AspectRatio -> .3, FrameLabel -> {None, "Price"},
  Epilog -> {Text[Style["Several\nLines\nof Text", 12], 
    Scaled[{0.02, .5}], {-1, 0}, 
    Background -> RGBColor[1, 1, 1, .8]]}, 
 PlotLegends -> 
  Placed[PointLegend[{"IBM", "GOOGLE"}, LabelStyle -> 12, 
    LegendFunction -> (Framed[#, 
        FrameStyle -> Directive[Thickness[.05]], RoundingRadius -> 4, 
        Background -> RGBColor[1, 1, 1, .8]] &)], {{.98, .95}, {1, 
     1}}]]

CurrentPlot

share|improve this question

2 Answers 2

up vote 4 down vote accepted

The solution is Framed together with Inset.

DateListPlot[{FinancialData["GOOG", "Jan. 1, 2008"]}, Joined -> False,
  ImageSize -> Large, AspectRatio -> .3, 
 FrameLabel -> {None, "Price"}, 
 Epilog -> {Inset[
    Framed[Text[Style["Several\nLines\nof Text", 12]], 
     RoundingRadius -> 4, Background -> RGBColor[1, 1, 1, .8]], 
    Scaled[{0.06, .5}]]}, 
 PlotLegends -> 
  Placed[PointLegend[{"IBM", "GOOGLE"}, LabelStyle -> 12, 
    LegendFunction -> (Framed[#, 
        FrameStyle -> Directive[Thickness[.05]], RoundingRadius -> 4, 
        Background -> RGBColor[1, 1, 1, .8]] &)], {{.98, .95}, {1, 
     1}}]]

enter image description here

share|improve this answer
    
Any idea how to change the thickness of the frame? When I export to pdf, it is much thicker than the plot frame. Inset works beautifully, BTW. –  Chris Roth Jan 9 at 19:27
    
@ChrisRoth Since the obvious Framed[x + y, FrameStyle -> Thin] does not work I don't have any ideas. You could either use the second answer or perhaps rasterize the plot before exporting to PDF (It looks fine as an image) –  Ajasja Jan 9 at 19:40
    
Try AbsoluteThickness for the frame thickness specification. –  Mike Honeychurch Jan 9 at 21:10
    
@MikeHoneychurch Does not work (since the frame is not a graphics directive). –  Ajasja Jan 9 at 21:23
    
@ChrisRoth Hmm, perhaps this issue should/could be posted as a separate question. –  Ajasja Jan 9 at 21:23

Rectangle has an Option RoundingRadius:

ListPlot[RandomReal[1, 100], 
         Epilog -> {
           {EdgeForm[Thick], Opacity[.5], Orange, 
            Rectangle[Scaled[{.6, .4}], Scaled[{.9, .9}], RoundingRadius -> Scaled@.02]},
           {Black, Text[Style["Fake\nlegend", 18], Scaled[{.75, .65}]]}}]

enter image description here

share|improve this answer

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.