Plotting: axes with ticks but with no labels

892 views
Skip to first unread message

Jeff

unread,
Jan 28, 2011, 8:08:34 AM1/28/11
to sage-support
I would like to be able to plot a function, e.g. plot(sin), that has
axes and ticks on the axes but that does not have labels for the
ticks. I understand that I might be able to do this using a ticker
formatter, perhaps also, by directly using matplotlib, but I do not
know exactly how to go about doing this.

Any help would be much appreciated.

Jeff Webb

D. S. McNeil

unread,
Jan 28, 2011, 9:52:17 AM1/28/11
to sage-s...@googlegroups.com
On Fri, Jan 28, 2011 at 9:08 PM, Jeff wrote:
> I would like to be able to plot a function, e.g. plot(sin), that has
> axes and ticks on the axes but that does not have labels for the
> ticks. I understand that I might be able to do this using a ticker
> formatter, perhaps also, by directly using matplotlib, but I do not
> know exactly how to go about doing this.

There may be a simpler way, but:

import matplotlib

p = plot(sin)
p.show(tick_formatter=(matplotlib.ticker.NullFormatter(),
matplotlib.ticker.NullFormatter()))

worked for me. The repetition is to make sure that both x and y tick
labels are turned off.


Doug

--
Department of Earth Sciences
University of Hong Kong

kcrisman

unread,
Jan 28, 2011, 10:20:29 AM1/28/11
to sage-support
Yes, if you look at http://www.sagemath.org/doc/reference/sage/plot/plot.html
and search for tick_formatter, you will see documentation for this.

Do you think it would be worth having the null formatter as a
specified option? The string "null" could easily have the default be
the null formatter - that would be easy to add.

- kcrisman

Jason Grout

unread,
Jan 28, 2011, 11:08:44 AM1/28/11
to sage-s...@googlegroups.com

I think the string 'none' might be a better fit for matplotlib
conventions, for what it's worth.

Jason

kcrisman

unread,
Jan 28, 2011, 11:23:26 AM1/28/11
to sage-support


On Jan 28, 11:08 am, Jason Grout <jason-s...@creativetrax.com> wrote:
> On 1/28/11 7:20 AM, kcrisman wrote:
>
>
>
>
>
>
>
> > On Jan 28, 9:52 am, "D. S. McNeil"<dsm...@gmail.com>  wrote:
> >> On Fri, Jan 28, 2011 at 9:08 PM, Jeff wrote:
> >>> I would like to be able to plot a function, e.g. plot(sin), that has
> >>> axes and ticks on the axes but that does not have labels for the
> >>> ticks. I understand that I might be able to do this using a ticker
> >>> formatter, perhaps also, by directly using matplotlib, but I do not
> >>> know exactly how to go about doing this.
>
> >> There may be a simpler way, but:
>
> >> import matplotlib
>
> >> p = plot(sin)
> >> p.show(tick_formatter=(matplotlib.ticker.NullFormatter(),
> >>                         matplotlib.ticker.NullFormatter()))
>
> >> worked for me.  The repetition is to make sure that both x and y tick
> >> labels are turned off.
>
> > Yes, if you look athttp://www.sagemath.org/doc/reference/sage/plot/plot.html
> > and search for tick_formatter, you will see documentation for this.
>
> > Do you think it would be worth having the null formatter as a
> > specified option?  The string "null" could easily have the default be
> > the null formatter - that would be easy to add.
>
> I think the string 'none' might be a better fit for matplotlib
> conventions, for what it's worth.

But the Python None is already reserved for the default formatter,
which I suppose makes sense since 'no formatting' means 'no special
formatting' to most of us... while null is special. So with 'none'
versus None I see a lot of potential for confusion. Or?

- kcrisman

Jason Grout

unread,
Jan 28, 2011, 11:34:15 AM1/28/11
to sage-s...@googlegroups.com


Yes, I do see a possibly confusing point. Advantages are:

1. once people realize that None means default, then the confusion is
lessened.

2. 'none' works for colors and the like since that's the matplotlib
convention.

Actually, (2) doesn't work in Sage, since apparently to_mpl_color
doesn't recognize 'none'. That's a bug in my opinion, as there is no
way to, say, draw a circle with a fill but no surrounding edge.

I'd say 'null' is less intuitive than 'none' (again, once the user
realizes that None actually means default).

Thanks,

Jason

kcrisman

unread,
Jan 28, 2011, 11:56:09 AM1/28/11
to sage-support
Sounds like this will be useful, anyway. Can you open a ticket where
we can discuss this further? Maybe we can support both options...

Thanks for raising this point, Jeff!

- kcrisman

Jeff

unread,
Jan 31, 2011, 7:50:50 AM1/31/11
to sage-support


On Jan 28, 11:20 pm, kcrisman <kcris...@gmail.com> wrote:
> On Jan 28, 9:52 am, "D. S. McNeil" <dsm...@gmail.com> wrote:
>
>
>
> > On Fri, Jan 28, 2011 at 9:08 PM, Jeff wrote:
> > > I would like to be able to plot a function, e.g. plot(sin), that has
> > > axes and ticks on the axes but that does not have labels for the
> > > ticks. I understand that I might be able to do this using a ticker
> > > formatter, perhaps also, by directly using matplotlib, but I do not
> > > know exactly how to go about doing this.
>
> > There may be a simpler way, but:
>
> > import matplotlib
>
> > p = plot(sin)
> > p.show(tick_formatter=(matplotlib.ticker.NullFormatter(),
> >                        matplotlib.ticker.NullFormatter()))
>
> > worked for me.  The repetition is to make sure that both x and y tick
> > labels are turned off.
>
> Yes, if you look athttp://www.sagemath.org/doc/reference/sage/plot/plot.html
> and search for tick_formatter, you will see documentation for this.
>
> Do you think it would be worth having the null formatter as a
> specified option?  The string "null" could easily have the default be
> the null formatter - that would be easy to add.
>
> - kcrisman
First of all thanks to you and the others for the helpful suggestions.

Whatever it ends up being called, a null formatter option would be
useful, I think. In fact, it would be nice to be able to specify
arbitrary labels for each tick mark (not necessarily corresponding to
the numbers that they represent). I don't think this done in
http://www.sagemath.org/doc/reference/sage/plot/plot.html, although
with matplotlib directly I suppose it could be done.

So, for example, along with tick mark specifications such as [ [1,
1,2], [ 2, 3] ], there could be a corresponding tick label list:
[ ['label for tick at 1', 'label for tick at 1.2'], ['label for tick
2', 'label for tick 3'] ]. If I remember rightly there might be
something a bit like this in Mathematica.

Jeff

Jeff

unread,
Jan 31, 2011, 8:14:52 AM1/31/11
to sage-support
Thanks Doug, I've just tried this method and it worked very well.

Jeff
Reply all
Reply to author
Forward
0 new messages