plots with logarithmic axis?

89 views
Skip to first unread message

Stan Schymanski

unread,
Oct 13, 2011, 7:25:04 AM10/13/11
to sage-support
Dear all,

According to ticket http://trac.sagemath.org/sage_trac/ticket/4529,
http://trac.sagemath.org/sage_trac/ticket/1431 shows a way how to use
logarithmic axes in plot(), but I am just not getting it. Could
someone point me in the right direction or give a simple example for a
plot with the y-axis scaled logarithmically?

Thanks heaps!
Stan

Jason Grout

unread,
Oct 13, 2011, 10:18:26 AM10/13/11
to sage-s...@googlegroups.com


Do you want log *ticks* or a log *scale*? #1431 is about the tickmarks,
not the scale. So my last comment on #4529 seems to not be correct, at
least referring to what #1431 turned out to be in the end.

To change the scale, you can modify the plot afterwards, but I am
running into some sort of problem doing it:


sage: p=plot(e^x,(x,0,10))
sage: m=p.matplotlib()
sage: from matplotlib.backends.backend_agg import FigureCanvasAgg
sage: m.set_canvas(FigureCanvasAgg(m))
sage: m.gca().set_yscale('log')
sage: m.savefig('test.png')


It would be pretty straightforward to add log scaling options to plot as
well---it's a single call in matplotlib. You can also just use
matplotlib directly:
http://matplotlib.sourceforge.net/examples/pylab_examples/log_demo.html?highlight=codex%20loglog


Thanks,

Jason

Jason Grout

unread,
Oct 13, 2011, 10:32:54 AM10/13/11
to sage-s...@googlegroups.com
On 10/13/11 9:18 AM, Jason Grout wrote:
> On 10/13/11 6:25 AM, Stan Schymanski wrote:
>> Dear all,
>>
>> According to ticket http://trac.sagemath.org/sage_trac/ticket/4529,
>> http://trac.sagemath.org/sage_trac/ticket/1431 shows a way how to use
>> logarithmic axes in plot(), but I am just not getting it. Could
>> someone point me in the right direction or give a simple example for a
>> plot with the y-axis scaled logarithmically?
>
>
> Do you want log *ticks* or a log *scale*? #1431 is about the tickmarks,
> not the scale. So my last comment on #4529 seems to not be correct, at
> least referring to what #1431 turned out to be in the end.
>
> To change the scale, you can modify the plot afterwards, but I am
> running into some sort of problem doing it:
>
>
> sage: p=plot(e^x,(x,0,10))
> sage: m=p.matplotlib()
> sage: from matplotlib.backends.backend_agg import FigureCanvasAgg
> sage: m.set_canvas(FigureCanvasAgg(m))
> sage: m.gca().set_yscale('log')
> sage: m.savefig('test.png')

It seems something was wrong with the plot in the above example, or
something. Anyways, starting with:

p=plot(x,(x,1,10))

works fine.

To do #4529, I'd suggest adding a keyword to show that defines the
scales of the x and y axes. I've added some comments to the ticket.


Thanks,

Jason

Stan Schymanski

unread,
Oct 21, 2011, 10:30:48 AM10/21/11
to sage-support
Hi Jason,

Thanks for that! How ironic that it does not work for non-linear
functions!
I actually played around with p.matplotlib() before I found your
reply, but I haven't got it to plot anything. Is there a step I am
missing before I can import a plot() into pylab and manipulate it
there? That would be a great feature!

Stan

On Oct 13, 4:32 pm, Jason Grout <jason-s...@creativetrax.com> wrote:
> On 10/13/11 9:18 AM, Jason Grout wrote:
>
>
>
>
>
>
>
>
>
> > On 10/13/11 6:25 AM, Stan Schymanski wrote:
> >> Dear all,
>
> >> According to tickethttp://trac.sagemath.org/sage_trac/ticket/4529,
> >>http://trac.sagemath.org/sage_trac/ticket/1431shows a way how to use
> >>logarithmicaxes inplot(), but I am just not getting it. Could
> >> someone point me in the right direction or give a simple example for a
> >>plotwith the y-axis scaled logarithmically?
>
> > Do you want log *ticks* or a log *scale*? #1431 is about the tickmarks,
> > not the scale. So my last comment on #4529 seems to not be correct, at
> > least referring to what #1431 turned out to be in the end.
>
> > To change the scale, you can modify theplotafterwards, but I am
> > running into some sort of problem doing it:
>
> > sage: p=plot(e^x,(x,0,10))
> > sage: m=p.matplotlib()
> > sage: from matplotlib.backends.backend_agg import FigureCanvasAgg
> > sage: m.set_canvas(FigureCanvasAgg(m))
> > sage: m.gca().set_yscale('log')
> > sage: m.savefig('test.png')
>
> It seems something was wrong with theplotin the above example, or
Reply all
Reply to author
Forward
0 new messages