3
$\begingroup$

I am creating some plots that use FrameStyle->AbsoluteThickness@5 and PlotStyle->AbsoluteThickness@0.5. In my plots' Epilog option, I want to use some Inset[Framed@...,FrameStyle->AbsoluteThickness@0.5] expressions. Upon exporting the graphics to PDF, I noticed that the FrameStyle option does nothing. This lead me to the following question on this site:

Formatting Framed - Some FrameStyle graphics directives don't work

So I tried the following, to get a feeling for what BoxFrame does:

Plot[Sin[x], {x, 0, 2 Pi},
 PlotStyle -> AbsoluteThickness@0.5,
 Frame -> True,
 FrameStyle -> AbsoluteThickness@0.5,
 ImageSize -> 180,
 Epilog -> {Inset[
    Framed["sin(x)", BoxFrame -> {{0.1, 0.5}, {5, 0}}],
    {3/2 Pi, 0.5}]}]

The resulting PDF looks like this:

enter image description here

It seems like only integer numbers work in the BoxFrame option. But how can I make the frame thinner? Especially, how can I make it exactly 0.5 pt thick?

$\endgroup$
  • $\begingroup$ I used to make nested Framed objects to take control. $\endgroup$ – Kuba Jun 21 '13 at 11:56
  • $\begingroup$ Could you provide an example of that? $\endgroup$ – einbandi Jun 21 '13 at 12:05
1
$\begingroup$

Another possible way would be using an inline Cell with specified CellFrame.

labelcell =
    Cell[BoxData[
                 ToBoxes[
                        Style[ Defer[Sin[x]],
                               20, GrayLevel[.4], FontFamily -> "Constantia"],
                        TraditionalForm]
                ],
         CellFrame -> {{1, 4}, {6, 10}},
         CellFrameMargins -> 5,
         CellFrameColor -> RGBColor[0.2, 0.4, 0.7]
        ] // Cell[TextData[{#}]] &; (* make it an inline Cell *)

Plot[Sin[x], {x, 0, 2 Pi},
     PlotStyle -> AbsoluteThickness@0.5,
     Frame -> True,
     FrameStyle -> AbsoluteThickness@0.5,
     ImageSize -> 500,
     Epilog -> {
                Inset[RawBoxes[labelcell], {3/2 Pi, 0.5}]
               }
    ]

CellFramed label

$\endgroup$
  • 1
    $\begingroup$ Thanks! With your solution I finally get the desired output, even in the PDF. It's a shame that there seems to be no simple way for such a simple problem... $\endgroup$ – einbandi Jun 25 '13 at 21:25
  • $\begingroup$ @einbandi Thanks for acceptance! I don't know why Framed doesn't work.. Fortunately there are always more than one roads lead to Rome. :D $\endgroup$ – Silvia Jun 25 '13 at 21:30
2
$\begingroup$

I hate situations when MMA is forcing me to create such inelegant solutions. It is how I am dealing with it:

The basic idea is to govern the margins by outerFrame FrameMargins. One good thing here is FrameMargins:

specifies the absolute margins in printer's points to leave inside the frame

With[{
  outerFrame = Sequence[Alignment -> Center, Background -> Black, 
                        FrameMargins -> {{25, 5}, {10, -1}}],
  innerFrame = Sequence[Background -> White, FrameStyle -> None, ImageMargins -> 0]
   },
 Plot[
  Sin[x], {x, 0, 2 Pi},
  PlotStyle -> AbsoluteThickness@0.5, Frame -> True, FrameStyle -> AbsoluteThickness@0.5, 
  ImageSize -> 480, Epilog -> {
    Inset[
     Framed[Framed["sin(x)", innerFrame], outerFrame]
     , {3/2 Pi, 0.5}]}]
  ]

enter image description here

$\endgroup$
  • $\begingroup$ I like the idea of this answer, but I just can't get it to work properly. The thinnest frame I can get is exactly as thick as the one using FrameStyle or BoxFrame (which looks like 1 pt in the resulting PDF). $\endgroup$ – einbandi Jun 25 '13 at 21:18

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.