Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

remove tick labels

1,679 views
Skip to first unread message

markus

unread,
Dec 24, 2011, 7:10:52 AM12/24/11
to
Hi,

is there a simple way in Mathematica to remove the tick labels from a
plot while keeping the tick marks?
I know that in principle one could specify all the tick mark
positions, formatting and labels in a list as an argument to the plot
function, but this is quite cumbersome. What I want is to let
Mathematica create all the ticks automatically and the remove just the
labels afterwards. I thought it should be possible by manipulating the
output of the plot command in some way, but I haven't found out yet.

Regards,
Markus

Bob Hanlon

unread,
Dec 25, 2011, 6:33:28 AM12/25/11
to
Show[(plt = Plot[x, {x, 0, 1}]),
Ticks -> (Ticks /. AbsoluteOptions[plt, Ticks] /.
{t_, t_, l_List, s_List} -> {t, "", l, s})]

Bob Hanlon

Nasser M. Abbasi

unread,
Dec 25, 2011, 6:35:31 AM12/25/11
to
Well, this is the best I could do, it removes the labels, but
for some reason the y-axis ticks spacings seems look different.

May be playing more with it will fix it.

I think there should be an option to do this. I do not think
a user has to do this sort of low level stuff just to remove
tick labels.

-------------------------------------------
t = AbsoluteOptions[p, Ticks];

tx = Map[If[Head[#[[2]]] === Real, ReplacePart[#, "", {2}], #] &,
t[[1, 2, 1]]];

ty = Map[If[Head[#[[2]]] === Real, ReplacePart[#, "", {2}], #] &,
t[[1, 2, 2]]];

Plot[Sin[x], {x, -Pi, Pi}, Ticks -> {tx, ty}]
-------------------------------------------

For reference, I used this article for help

"This notebook illustrates how to move tick labels from the default positions.
The specific example presented here puts the labels above the horizontal axis."

http://library.wolfram.com/infocenter/TechNotes/4134/

--Nasser

Heike Gramberg

unread,
Dec 25, 2011, 6:34:30 AM12/25/11
to
The easiest way is probably to set LabelStyle->Opacity[0]. This doesn't remove the tick marks but merely hides them by setting their opacity to 0. Since TicksStyle overrides LabelStyle, to
create a plot where only the tick marks along say the x-axes are hidden, you could do something
like

Plot[Sin[x], {x, 0, 2 Pi}, TicksStyle -> {Automatic, Opacity[1]}, LabelStyle -> Opacity[0]]

Note that setting LabelStyle affects all labels such as AxesLabel so you would need to use something like Style[label, Opacity[1]] to override the zero opacity set by LabelStyle, i.e.
Plot[Sin[x], {x, 0, 2 Pi}, LabelStyle -> Opacity[0], AxesLabel -> Map[Style[#, Opacity[1]] &, {x, Sin[x]}]]

Heike.

David Park

unread,
Dec 25, 2011, 6:33:59 AM12/25/11
to
The Presentations Application has CustomTicks and NoTicksLabel commands.
The easiest method to specify plots without tick labels would be as follows:

<< Presentations`

testplot = Plot[Sin[x], {x, 0, 2 \[Pi]},
Frame -> True]

Write CustomTicks without labels and use them in the plot.

xticks = CustomTicks[Identity, {0, 7, 1, 5}] // NoTickLabels;
yticks = CustomTicks[Identity, {-1, 1, 0.5, 5}] // NoTickLabels;
Plot[Sin[x], {x, 0, 2 \[Pi]},
Frame -> True,
FrameTicks -> {xticks, yticks}]

Here the Identity in the CustomTicks command specifies that the tick
positions will be the same as the underlying coordinates. (Otherwise we
could use a function that generates custom tick marks.) The list {0, 7, 1,
5} means to make ticks from 0 to 7 in steps of 1 with 5 subdivisions for
small ticks. So you have to specify the ticks but it is not tedious.

We can try to let Mathematica automatically generate the ticks and then use
NoTickLabels to suppress the labels.

testplot = Plot[Sin[x], {x, 0, 2 \[Pi]},
Frame -> True];
specialticks =
FrameTicks /. AbsoluteOptions[testplot, FrameTicks] //
NoTickLabels;;
Show[testplot, FrameTicks -> specialticks]

This does not work properly as the length of the ticks are not the same as
in the original plot, nor are the y ticks the same!

step1=FrameTicks/. AbsoluteOptions[testplot,FrameTicks];
step1[[2]]//Column

The original plot has major y divisions spaced by 0.5, but using
AbsoluteOptions gives divisions spaced by 0.25. It is easier here to use
CustomTicks than to mess with Mathematica features.


David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/index.html

Nasser M. Abbasi

unread,
Dec 26, 2011, 6:53:44 AM12/26/11
to
On 12/25/2011 5:33 AM, Bob Hanlon wrote:
> Show[(plt = Plot[x, {x, 0, 1}]),
> Ticks -> (Ticks /. AbsoluteOptions[plt, Ticks] /.
> {t_, t_, l_List, s_List} -> {t, "", l, s})]
>
> Bob Hanlon
>

I tried something like the above during my attempts, but if you notice,
the ticks on the 'modified' plot do not look the same as the
original one.

If we Compare

Plot[Sin[x], {x, -Pi, Pi}]

with what you have:

Show[(plt = Plot[Sin[x], {x, -Pi, Pi}]),
Ticks -> (Ticks /.
AbsoluteOptions[plt, Ticks] /. {t_, t_, l_List, s_List} -> {t,
"", l, s})]


We notice 2 things:
1) some ticks are lost near the orgin on the x-axis
2) the y-axis ticks no longer looks like in the orginal plot.

--Nasser

0 new messages