1
$\begingroup$

I want to make some description on my plots, but I can't make it good.

First I tried this:

Plot[Sin[100 x], {x, 0, 50}, PlotStyle -> Black, 
 Epilog -> 
  Inset[Framed[Style[111, 30, Red], FrameStyle -> Red, 
    Background -> Directive[White, Opacity[0.5]]], {25, 0}, {Center, 
    Bottom}], AxesStyle -> Red]

enter image description here

But I need some margins, so I did it:

Plot[Sin[100 x], {x, 0, 50}, PlotStyle -> Black, 
 Epilog -> 
  Inset[Framed[Style[111, 30, Red], FrameStyle -> Red, 
    Background -> Directive[White, Opacity[0.5]], 
    ImageMargins -> 5], {25, 0}, {Center, Bottom}], AxesStyle -> Red]

enter image description here

But where is my background??? I don't understand what's wrong. OK. I tried this:

Plot[Sin[100 x], {x, 0, 50}, PlotStyle -> Black, 
 Epilog -> 
  Inset[Framed[Style[111, 30, Red], FrameStyle -> Red, 
    ImageMargins -> 5], {25, 0}, {Center, Bottom}, 
   Background -> Directive[White, Opacity[0.5]]], AxesStyle -> Red]

enter image description here

Ands it's not that I want. I need margins without background. So I make a stupid thing, I added one Framed more:

Plot[Sin[100 x], {x, 0, 50}, PlotStyle -> Black, 
 Epilog -> 
  Inset[Framed[
    Framed[Style[111, 30, Red], FrameStyle -> Red, 
     Background -> Directive[White, Opacity[0.5]]], 
    FrameStyle -> None, ImageMargins -> 5], {25, 0}, {Center, 
    Bottom}], AxesStyle -> Red]

enter image description here

OK. That's not so bad. But why margins are so big?

Plot[Sin[100 x], {x, 0, 50}, PlotStyle -> Black, 
 Epilog -> 
  Inset[Framed[
    Framed[Style[111, 30, Red], FrameStyle -> Red, 
     Background -> Directive[White, Opacity[0.5]]], 
    FrameStyle -> Green, ImageMargins -> 5], {25, 0}, {Center, 
    Bottom}], AxesStyle -> Red]

enter image description here

Oh... That's because we have some padding inside of our frame. And how can I zero this padding?

So what can I do to make what I want? I can't understand why second example didn't work. But I want to see the picture as if it worked.

Sorry if i'm so newbie in WM. Thx.

$\endgroup$
  • $\begingroup$ Pardon me, what is the goal to look like? Somehow I became confused by your examples rather than understanding better. Possibly you want this?: Plot[Sin[100 x], {x, 0, 50}, PlotStyle -> Black, Epilog -> Inset[ Framed[Style[111, 30, Red], FrameStyle -> Red, Background -> Directive[White, Opacity[0.5]]], {25, 0}, {Center, -1.2}], AxesStyle -> Red] $\endgroup$ – Mr.Wizard Jul 18 '16 at 7:41
  • $\begingroup$ Looks like YES, but, NO. I can't use OPOS to make equal margins, because of different size of text inside this Epilog... I have dynamic plots so it's really hard. I can't explain, but this is too hard to calculate all coordinates in all different situations. It's easily to use 1 exact coordinate+margin, instead of two exact pos+opos. So I want margins to work or set paddings of second framed to zero somehow... $\endgroup$ – Vasily Jul 18 '16 at 17:07
  • $\begingroup$ I may need to see your animation to understand your requirements, but my best guess is: Plot[Sin[100 x], {x, 0, 50}, PlotStyle -> Black, Epilog -> Inset[ Framed[Style[111, 30, Red], FrameStyle -> Red, Background -> Directive[White, Opacity[0.5]]], Offset[{0, 5}, {25, 0}], {Center, Bottom}], AxesStyle -> Red] -- this keeps the Framed expression offset from zero by a fixed absolute distance. $\endgroup$ – Mr.Wizard Jul 18 '16 at 17:52
  • $\begingroup$ @Mr.Wizard, Thx. That works better for me. I need to change sign +/-5 in some cases, that make this solution some complicated, but it works almost like margin, like I want. Thx. $\endgroup$ – Vasily Jul 19 '16 at 10:47
1
$\begingroup$

This appears to be a bug. Try for example this modified version of @Mr.Wizard's suggestion:

Graphics[Inset[
  Framed[Style[111, 30, Red], FrameStyle -> Red, 
   Background -> Directive[White, Opacity[0.5]], 
   ImageMargins -> 70], {25, 0}, {Center, -1.2}], Background -> Black]

On Mac OS X, this screen shot shows that the notebook initially displays a background in the wrong position. But as soon as I scroll the page, the background disappears. It's also absent in an exported PNG. But the upshot is that the background should be rendered. It works as long as you don't include the ImageMargins option in Framed.

To address the spacings issue in your last example, you may want to use FrameMargins with a negative value.

$\endgroup$

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.