#4529: Implement plots with logarithmic scale
-----------------------------------------+----------------------------------
       Reporter:  ronanpaixao            |         Owner:  ronanpaixao          
           Type:  enhancement            |        Status:  needs_work           
       Priority:  major                  |     Milestone:  sage-5.1             
      Component:  graphics               |    Resolution:                       
       Keywords:  plot log scale         |   Work issues:  convenience functions
Report Upstream:  N/A                    |     Reviewers:  Karl-Dieter Crisman  
        Authors:  Punarbasu Purkayastha  |     Merged in:                       
   Dependencies:  #12974                 |      Stopgaps:                       
-----------------------------------------+----------------------------------
Changes (by kcrisman):

  * reviewer:  => Karl-Dieter Crisman


Old description:

> Attached is a patch which introduces log scale to `Graphics()` class.
>
> Depends on #12974.
>
> Apply the following patches in the specified order. `SAGE_ROOT` is the
> directory where the sage installation is present.
> {{{
> cd SAGE_ROOT/devel/sage
> ../../sage -hg qimport -P http://trac.sagemath.org/sage_trac/raw-
> attachment/ticket/12974/trac_12974-fix_graphics_attributes.patch
> ../../sage -hg qimport -P http://trac.sagemath.org/sage_trac/raw-
> attachment/ticket/12974/trac_12974-refactor.patch
> ../../sage -hg qimport -P http://trac.sagemath.org/sage_trac/raw-
> attachment/ticket/12974/trac_12974-reorder_some_arguments.patch
> ../../sage -hg qimport -P http://trac.sagemath.org/sage_trac/raw-
> attachment/ticket/12974/trac_12974-whitespace_cleanup.patch
> ../../sage -hg qimport -P http://trac.sagemath.org/sage_trac/raw-
> attachment/ticket/4529/trac_4529-add_logscale_to_Graphics.2.patch
> ../../sage -b
> }}}
>
> ----
> '''OLD DISCUSSION BELOW :)'''
>
> Currently plot() has no option to use logarithmic scales.
>
> One workaround is to use matplotlib directly, with its semilogy(),
> semilogx() and loglog() functions, but that wouldn't produce plots with
> the customisations implemented in sage.
> Another workaround is messing with the plot figure like:
>
> {{{
> #!python
> import pylab
> p=plot(x,marker='.')
> f=pylab.figure()
> f.gca().set_xscale('log')
> p.save(figure=f)
> }}}
>
> But that creates two problems:
>
>  * The first problem is that the adaptive choosing of points just
> considers linear scale, so the points get too much spaced apart in the
> beginning of the plot and too close in the end.
>  * The second problem relates to the axis, which, for the same reason,
> isn't located right.
>
> Also, this requires the user to know how to deal with figures, which is
> not directly exposed by sage.
>
> There are some possibilities to fix that:
>  1. Make plot() detect if the figure changes the scales and modify the
> adaptive algorithm and the axis codes accordingly
>  2. Create a kwarg to tell plot() to implement the scale-change
> internally
>  3. Create other functions to use loglog(), semilogx() and semilogy()
>  4. Many (or all) of the above together, since they aren't mutually
> exclusive
>
> From what I noticed, Mathematica implements the separate functions way,
> but it may be better to fix the issue in plot() itself and if the other
> functions are wanted, just make it so that they call plot() with the
> correct arguments

New description:

 Attached is a patch which introduces log scale to `Graphics()` class.

 Depends on #12974.

 Apply [attachment:trac_4529-add_logscale_to_Graphics.2.patch] and a patch
 to be determined.

 OR

 Apply the following patches in the specified order. `SAGE_ROOT` is the
 directory where the sage installation is present.
 {{{
 cd SAGE_ROOT/devel/sage
 ../../sage -hg qimport -P http://trac.sagemath.org/sage_trac/raw-
 attachment/ticket/12974/trac_12974-fix_graphics_attributes.patch
 ../../sage -hg qimport -P http://trac.sagemath.org/sage_trac/raw-
 attachment/ticket/12974/trac_12974-refactor.patch
 ../../sage -hg qimport -P http://trac.sagemath.org/sage_trac/raw-
 attachment/ticket/12974/trac_12974-reorder_some_arguments.patch
 ../../sage -hg qimport -P http://trac.sagemath.org/sage_trac/raw-
 attachment/ticket/12974/trac_12974-whitespace_cleanup.patch
 ../../sage -hg qimport -P http://trac.sagemath.org/sage_trac/raw-
 attachment/ticket/4529/trac_4529-add_logscale_to_Graphics.2.patch
 ../../sage -b
 }}}

 ----
 '''OLD DISCUSSION BELOW :)'''

 Currently plot() has no option to use logarithmic scales.

 One workaround is to use matplotlib directly, with its semilogy(),
 semilogx() and loglog() functions, but that wouldn't produce plots with
 the customisations implemented in sage.
 Another workaround is messing with the plot figure like:

 {{{
 #!python
 import pylab
 p=plot(x,marker='.')
 f=pylab.figure()
 f.gca().set_xscale('log')
 p.save(figure=f)
 }}}

 But that creates two problems:

  * The first problem is that the adaptive choosing of points just
 considers linear scale, so the points get too much spaced apart in the
 beginning of the plot and too close in the end.
  * The second problem relates to the axis, which, for the same reason,
 isn't located right.

 Also, this requires the user to know how to deal with figures, which is
 not directly exposed by sage.

 There are some possibilities to fix that:
  1. Make plot() detect if the figure changes the scales and modify the
 adaptive algorithm and the axis codes accordingly
  2. Create a kwarg to tell plot() to implement the scale-change internally
  3. Create other functions to use loglog(), semilogx() and semilogy()
  4. Many (or all) of the above together, since they aren't mutually
 exclusive

 From what I noticed, Mathematica implements the separate functions way,
 but it may be better to fix the issue in plot() itself and if the other
 functions are wanted, just make it so that they call plot() with the
 correct arguments

--

Comment:

 Some comments:
  * Shouldn't `base=2` raise an error when `scale='linear'` in your
 example? Maybe the
 {{{
        if scale is None:
             return ('linear', 'linear', 10, 10)
 }}}
    could return 'linear', 'linear', None, None?
  * In `_matplotlib_tick_formatter`, should `base` and `scale` be next to
 each other in the function definition?  (This is a very minor critique, of
 course.)
  * Nice consolidation of the `ticklabels` business at the end of the
 patch.
  * Regardless of the outcome of the poll (on which you can vote), I think
 one should add a lot more examples in the documentation for `show` for the
 various options.  Lots of them.
  * What's going on with the `pr, i  = '', 0` thing removed?  I just don't
 know what it had been doing - seems to have been dead code, but I always
 get nervous when I have no idea what it ''used'' to do...
  * kini says that the `[13:]` seems brittle if matplotlib's API changes;
 would it be possible to remove the specific string `\\mathdefault`
 instead?
  * I wonder about the not setting of the spines outward when the axes
 shouldn't cross.  Here is an example which serves the point:
 {{{
 sage: G = plot(exp(x), (x,5,10))
 sage: G.show(scale=('semilogy', 2))
 }}}
    I don't even think this is a very atypical example to arise in
 practice.  It should be documented somehow.
  * It's fairly easy to have just one tick in a given direction, which
 usually raises an error in normal plots but isn't raising an error for
 yours.  I'm not sure if one would want to raise an error like "Use a
 different base so that you get at least two ticks!" or something.

 But even with all of these comments, and waiting for the post-poll patch,
 '''fantastic''' job on this.  Someone had to come along to finally wrap
 this for us, it's been requested zillions of times, and this is very worth
 the effort, thank you so much.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/4529#comment:39>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to