3
$\begingroup$

In scientific literature, plots often have a design like what I've been trying to make (see below).
These images have the following characteristics:
1) Frames on the left and on the right
2) An x-axis with (automatic) ticks but without labels.
3) Tick labels on the bottom but without the ticks themselves

enter image description here

Plot[Sin[x], {x, 0, 10},
 Frame -> {{True, True}, {True, False}},
 FrameTicks -> {{All, All}, {All, None}},
 FrameStyle -> {{None, None}, {White, None}},
 FrameTicksStyle -> {{None, None},
   {Directive[FontColor -> Gray, White], None}},
 PlotRangePadding -> 0]

The way I've been trying to achieve 1) and 3), is by making the lower frame and frame ticks white. However, this has an unwanted side effect. The bottom of the two frames and the graph are now overlapped by this frame which makes it seem like it is cut off.

I haven't even tried 2) yet.

Is there a way to get the design I like without this effect? Perhaps by removing only the ticks and not the ticklabels? Ideas for 2) are welcome aswell. In particular I'm interested in implementations that do not require functions like ImageCompose or Overlay.

EDIT: I also don't want to use any (custom) packages like 'CustomTicks'

$\endgroup$
6
$\begingroup$

Is this ok?

layout = Overlay[{
     Show[#, Frame -> {{True, True}, {True, False}},
             FrameStyle -> {{Automatic, Automatic}, 
                            {{FontOpacity -> 1, Opacity@0}, Automatic}},
             FrameTicks -> {{Automatic, All}, {All, None}},
             ImagePadding -> 35,
             Axes -> False]
     ,
     Show[Delete[#, {1, 1}], 
             Axes -> {True, False}, 
             ImagePadding -> 35, 
             TicksStyle -> FontOpacity -> 0]
     }] &;

layout @ Plot[Sin[x], {x, 0, 10}]

enter image description here

$\endgroup$
  • $\begingroup$ This seems to work! This does however make use of Overlay, but I guess it's very hard to do without using such a function? $\endgroup$ – Karel Apr 17 '15 at 10:04
  • $\begingroup$ @Karel I don't think you can have FrameTicks and AxisTics generated at once. You could get FullGraphics from plot with Ticks and use Show instead of Overlay but I don't know it is stable enugh. Noone is using FullGraphics lately, afaict. $\endgroup$ – Kuba Apr 17 '15 at 10:17
4
$\begingroup$
Plot[Sin[x], {x, 0, 10}, Frame -> True, 
 FrameStyle -> {{Automatic, Black}, {White, White}}, 
 FrameTicks -> {{Range[-1, 1, 0.5], 
    Range[-1, 1, 0.5]}, {({#, Style[#, Black]} & /@ Range[0, 10]), 
    None}}]

enter image description here

$\endgroup$
  • $\begingroup$ Your plot has not ticks on axis. $\endgroup$ – Kuba Apr 17 '15 at 11:18
  • $\begingroup$ @Kuba...oh! sorry but it matches the intended result on image...I am sorry I misinterpreted...just sought to reproduce image but not the text $\endgroup$ – ubpdqn Apr 17 '15 at 11:43
1
$\begingroup$

You can Inset the framed plot into a graphic with axes (while avoiding the use of Overlay as requested). Here is your plot, suitably modified to have the required frame ticks (and no axes):

p = Plot[Sin[x], {x, 0, 10}, 
    Axes -> False, 
    Frame -> {{True, True}, {True, False}},
    FrameTicks -> {{All, All}, {All, None}},
    FrameStyle->{{Automatic,Automatic},{Directive[FontOpacity->1,Opacity[0]],None}}
]

enter image description here

In order to inset the plot, one needs to use the same PlotRange, ImagePadding, PlotRangePadding, and AspectRatio in both the graphic and the inset plot so that the axes and frame line up:

Graphics[
    {
    Inset[
        Show[p, PlotRangePadding->0, ImagePadding->40, AspectRatio->1/GoldenRatio],
        {0, 0},
        {0, 0},
        ImageScaled[{1, 1}]
    ]
    },
    PlotRange -> {{0, 10}, {-1, 1}},
    AspectRatio -> 1/GoldenRatio,
    Axes -> {True, False},
    Ticks -> Automatic,
    TicksStyle -> FontOpacity -> 0,
    ImagePadding -> 40
]

enter image description here

Now, suppose that you instead just want to use the existing PlotRange, ImagePadding, and AspectRatio from the plot? This information can be extracted from the plot by using my graphicsInformation function from question 2091. Here is what graphicsInformation reveals about the plot p:

info = graphicsInformation[p]

{"ImagePadding" -> {{23., 24.}, {17., 0.5}}, "ImageSize" -> {360., 210.945}, "PlotRangeSize" -> {313., 193.445}, "ImagePaddingSize" -> {47., 17.5}, "PlotRange" -> {{-0.208333, 10.2083}, {-1.11111, 1.11111}}}

With the above information one does not need to override the options of the plot (using Show) to align the frame and axes:

Graphics[
    {
    Inset[p, {0, 0}, {0, 0}, ImageScaled[{1, 1}]]
    },
    Axes -> {True, False},
    Ticks -> Automatic,
    TicksStyle -> FontOpacity -> 0,
    PlotRange -> ("PlotRange" /. info),
    ImagePadding -> ("ImagePadding" /. info),
    AspectRatio -> 1 / Divide @@ ("PlotRangeSize" /. info)
]

enter image description here

$\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.