#13078: Make it easier to do custom tick formatting
-------------------------------+--------------------------------------------
       Reporter:  kcrisman     |         Owner:  jason, was
           Type:  enhancement  |        Status:  new       
       Priority:  minor        |     Milestone:  sage-5.1  
      Component:  graphics     |    Resolution:            
       Keywords:               |   Work issues:            
Report Upstream:  N/A          |     Reviewers:            
        Authors:               |     Merged in:            
   Dependencies:               |      Stopgaps:            
-------------------------------+--------------------------------------------

Comment (by kcrisman):

 I'll put that here as well.
 {{{
 #!diff
 # patch
 diff --git a/sage/plot/graphics.py b/sage/plot/graphics.py
 --- a/sage/plot/graphics.py
 +++ b/sage/plot/graphics.py
 @@ -1913,7 +1913,7 @@
                      raise ValueError('Expand the range of the dependent
 variable to allow two multiples of your tick locator (option `ticks`).')

              x_formatter, y_formatter = tick_formatter
 -            from matplotlib.ticker import FuncFormatter
 +            from matplotlib.ticker import FuncFormatter, FixedFormatter
              from sage.misc.latex import latex
              from sage.symbolic.ring import SR
              if x_formatter is None:
 @@ -1924,6 +1924,8 @@
                  x_formatter = FuncFormatter(lambda n,pos:
 _multiple_of_constant(n,pos,x_const))
              elif x_formatter == "latex":
                  x_formatter = FuncFormatter(lambda n,pos:
 '$%s$'%latex(n))
 +            elif isinstance(x_formatter, (list, tuple)):
 +                x_formatter = FixedFormatter(x_formatter)
              if y_formatter is None:
                  y_formatter = OldScalarFormatter()
              elif y_formatter in SR:
 @@ -1932,6 +1934,8 @@
                  y_formatter = FuncFormatter(lambda n,pos:
 _multiple_of_constant(n,pos,y_const))
              elif y_formatter == "latex":
                  y_formatter = FuncFormatter(lambda n,pos:
 '$%s$'%latex(n))
 +            elif isinstance(y_formatter, (list, tuple)):
 +                y_formatter = FixedFormatter(y_formatter)

              subplot.xaxis.set_major_locator(x_locator)
              subplot.yaxis.set_major_locator(y_locator)
 }}}
 You also said:

 This can be tested with a plot like this:
 {{{
 plot(x, (x,0,2), ticks=[[1,2],[1,2,3.5]],
 tick_formatter=[["$x_1$","$x_2$"],["$y_1$","$y_2$","$y_3$"]])
 }}}
 There should probably be more checks like
 {{{
 len(ticks[0]) == len(tick_formatter[0])
 }}}
 and so on, but that can be addressed in a proper patch.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13078#comment:4>
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