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.
-
4$\begingroup$ Can you give a code sample that generates that plot? $\endgroup$– Eli LanseyCommented Feb 21, 2012 at 2:37
5 Answers
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]]
Alternately, you could also use FontColor -> White
, but note that it won't work with all backgrounds.
-
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$– JensCommented 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 madeFontOpacity
the primary suggestion (it certainly is superior toFontColor
) $\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$– tlehmanCommented Feb 21, 2012 at 18:14
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]
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:
-
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$ 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 usingSpacer[k]
gives more precise control. $\endgroup$– kglrCommented 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$ Commented Feb 21, 2012 at 7:49
-
1$\begingroup$ When I create my plots I rather specify the
ImageSize
and setAspectRatio
toFull
in that way then I can specify myImagePadding
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 theAspectRatio
to be something other thanFull
. Any ideas how to deal with this? $\endgroup$– jmlopezCommented 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$– GhersicCommented Aug 24, 2015 at 18:13
I don't believe this has been mentioned yet:
RegionPlot[1 < Abs[x + I y] < 2, {x, -2, 2}, {y, -2, 2}, ImagePadding -> 1]
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.
-
-
$\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 tried0
but that cuts into the frame slightly, so1
crops everything but the frame. $\endgroup$ Commented Feb 21, 2012 at 14:17 -
1$\begingroup$ It doesn't work when you have graphics outside the
Frame
(precisely because you're usingImagePadding
). For example,Graphics[{Thickness[.3], Pink, Circle[]}, ImagePadding -> 1, Frame -> True]
(removeImagePadding
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$ Commented Feb 21, 2012 at 21:46
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}]}]
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).
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}
}
]