8
$\begingroup$

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

$\endgroup$

2 Answers 2

6
$\begingroup$

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

$\endgroup$
5
  • $\begingroup$ 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. $\endgroup$
    – Chris Roth
    Commented Jan 9, 2014 at 19:27
  • $\begingroup$ @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) $\endgroup$
    – Ajasja
    Commented Jan 9, 2014 at 19:40
  • $\begingroup$ Try AbsoluteThickness for the frame thickness specification. $\endgroup$ Commented Jan 9, 2014 at 21:10
  • $\begingroup$ @MikeHoneychurch Does not work (since the frame is not a graphics directive). $\endgroup$
    – Ajasja
    Commented Jan 9, 2014 at 21:23
  • $\begingroup$ @ChrisRoth Hmm, perhaps this issue should/could be posted as a separate question. $\endgroup$
    – Ajasja
    Commented Jan 9, 2014 at 21:23
2
$\begingroup$

Rectangle has an Option RoundingRadius:

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

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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