36
$\begingroup$

I would like to remove the numbering on the axes of the following RegionPlot. I would like to keep the tick marks but drop the numbering, I haven't figured out how to do this from the documentation.

The inverse image of the interval (a,b) under the metric function d

$\endgroup$
1
  • 4
    $\begingroup$ Can you give a code sample that generates that plot? $\endgroup$
    – Eli Lansey
    Commented Feb 21, 2012 at 2:37

5 Answers 5

46
$\begingroup$

An even simpler way that does not require you to figure out the tick positions, is to set the tick font opacity to 0 and the tick font size to 0 to avoid the excess margin where the ticks would have been. Here's an example:

RegionPlot[Sin[x y] > 0, {x, -1, 1}, {y, -1, 1}, 
    FrameTicksStyle -> Directive[FontOpacity -> 0, FontSize -> 0]]

enter image description here

Alternately, you could also use FontColor -> White, but note that it won't work with all backgrounds.

$\endgroup$
3
  • 1
    $\begingroup$ I just posted the same thing with FontOpacity, then deleted it when I saw that you had already mentioned it. I would just add FontSize->0 to reduce the blank space in the image margins. $\endgroup$
    – Jens
    Commented Feb 21, 2012 at 3:38
  • 1
    $\begingroup$ Thanks, I had FontSize -> 0 in my test code, but threw it out in the end. I've included it now and made FontOpacity the primary suggestion (it certainly is superior to FontColor) $\endgroup$
    – rm -rf
    Commented Feb 21, 2012 at 4:45
  • $\begingroup$ I like this solution the best, as I am using a Show to layer multiple graphics $\endgroup$
    – tlehman
    Commented Feb 21, 2012 at 18:14
21
$\begingroup$

My preferred solution is playing with FontColor or FontOpacity as in R.M.`s answer, or define your own ticks as in David's answer.

Another alternative is to change the labels to blank in FrameTicks. Since FrameTicks->Automatic saves a lot manual effort (and it uses the built-in FindDivisions for selecting ticks), sometimes it may be more convenient to transform the automatic frameticks data:

 rp = RegionPlot[x^2 + y^3 < 2 && x + y < 1, {x, -2, 2}, {y, -2, 2}, 
 FrameTicks -> Automatic]

region plot with wick labels

First extract the frameticks information and change the labels to blank:

 newticks = Last@First[AbsoluteOptions[rp, FrameTicks]];
 newticks[[All, All, 2]] = "";

Then replot or useShow with the new frameticks:

 Show[rp, FrameTicks -> newticks]

to get:

region plot with no tick labels

$\endgroup$
6
  • 2
    $\begingroup$ I think this solution has the potential to be the best, but it leaves space at the top and bottom of the plot. I propose: newticks[[All, All, 2]] = Spacer[0]; $\endgroup$
    – Mr.Wizard
    Commented Feb 21, 2012 at 7:06
  • $\begingroup$ @Mr.Wizard, thank you! I thought an advantage of this approach was that one could choose the string length of the label by using a blank string of desired length " ". But using Spacer[k] gives more precise control. $\endgroup$
    – kglr
    Commented Feb 21, 2012 at 7:42
  • $\begingroup$ You're welcome. I noticed that, rather surprisingly, the ticks change somewhat between your first and second plots. I added an answer that is a bit of a cheat, but it preserves the default ticks if that is desired. $\endgroup$
    – Mr.Wizard
    Commented Feb 21, 2012 at 7:49
  • 1
    $\begingroup$ When I create my plots I rather specify the ImageSize and set AspectRatio to Full in that way then I can specify my ImagePadding to correctly position my plot. I like your answer since it removes the unwanted data instead of just hiding it by making it transparent. The problem I have now is that I cannot extract the ticks marks because it wants the AspectRatio to be something other than Full. Any ideas how to deal with this? $\endgroup$
    – jmlopez
    Commented Apr 9, 2013 at 18:38
  • $\begingroup$ @Mr.Wizard In Mathematica 10.2.0 the request for AbsoluteOptions[rp, FrameTicks] produces error: "Ticks::ticks: "{Automatic,Automatic} is not a valid tick specification." Odd error. $\endgroup$
    – Ghersic
    Commented Aug 24, 2015 at 18:13
16
$\begingroup$

I don't believe this has been mentioned yet:

RegionPlot[1 < Abs[x + I y] < 2, {x, -2, 2}, {y, -2, 2}, ImagePadding -> 1]

Mathematica graphics

ImagePadding
is an option for graphics functions that specifies what absolute extra padding should be left for extended objects such as thick lines and annotations such as tick and axis labels.

$\endgroup$
4
  • $\begingroup$ Why does this work? $\endgroup$
    – Eli Lansey
    Commented Feb 21, 2012 at 14:01
  • $\begingroup$ @Eli well, ImagePadding specifies the space around the graph outside of the Frame. Normally this is calculated to include the ticks and labels. I tried 0 but that cuts into the frame slightly, so 1 crops everything but the frame. $\endgroup$
    – Mr.Wizard
    Commented Feb 21, 2012 at 14:17
  • 1
    $\begingroup$ It doesn't work when you have graphics outside the Frame (precisely because you're using ImagePadding). For example, Graphics[{Thickness[.3], Pink, Circle[]}, ImagePadding -> 1, Frame -> True] (remove ImagePadding to see how it ought to look) $\endgroup$
    – rm -rf
    Commented Feb 21, 2012 at 15:27
  • $\begingroup$ @R.M correct. I still like kguler's method because it actually removes the numbers rather than merely hiding them by one means or another. $\endgroup$
    – Mr.Wizard
    Commented Feb 21, 2012 at 21:46
9
$\begingroup$

FrameTicks

Consider FrameTicks in the example below:

RegionPlot[Sin[x] Sin[y] > 1/4, {x, -1, 1}, {y, -1, 1},
  FrameTicks -> {Table[{k, "", {If[Mod[k, .5] == 0, .02, .01], 0}}, {k, -1, 1, .1}], 
                 Table[{k, "", {If[Mod[k, .5] == 0, .02, .01], 0}}, {k, -1, 1, .2}]}]

FrameTicks

In Table[{k, "", {If[Mod[k, .5] == 0, .02, .01], 0}}, {k, -1, 1, .1}] ,

k is the location of the tick

"" is the label

If... determines whether to use a major (.02) or minor (.01) tick on the inside of the respective axis.

0 indicates that the tick should not appear on the outside of the axis.

Note that the first Table sets the horizontal edges of the frame (with ticks every .1 units); the second Table sets the vertical edges of the frame (with ticks every .2 units).

$\endgroup$
6
$\begingroup$

You can use the internal, undocumented function Charting`ScaledFrameTicks to do this (Charting`ScaledFrameTicks produces unlabeled ticks, while Charting`ScaledTicks produces labeled ticks):

RegionPlot[
    Sin[x y]>0,
    {x,-1,1},
    {y,-1,1},
    FrameTicks->{
        {Charting`ScaledFrameTicks[{Identity,Identity}], Automatic},
        {Charting`ScaledFrameTicks[{Identity,Identity}], Automatic}
    }
]

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.