#20924: Error in plot - force use of aspect ratio
-----------------------------------+------------------------
       Reporter:  aram.dermenjian  |         Type:  defect
         Status:  new              |     Priority:  major
      Milestone:  sage-7.3         |    Component:  graphics
       Keywords:                   |    Merged in:
        Authors:                   |    Reviewers:
Report Upstream:  N/A              |  Work issues:
         Branch:                   |       Commit:
   Dependencies:                   |     Stopgaps:
-----------------------------------+------------------------
 It seems as though when using plot() we are forced to have an aspect ratio
 of automatic whether we want that or not. Example:

 If we define a class
 {{{
 class something:
     def plot(self):
         G = Graphics()
         G.set_aspect_ratio(1)
         return G
 }}}

 when we do something.plot() the aspect ratio is correctly set to 1. But
 when we do plot(something) the aspect ratio gets converted to automatic.
 This is due to the native way that plot is handled:

 file: src/sage/plot/plot.py
 {{{
 @options(alpha=1, thickness=1, fill=False, fillcolor='automatic',
 fillalpha=0.5, rgbcolor=(0,0,1), plot_points=200, adaptive_tolerance=0.01,
 adaptive_recursion=5, detect_poles = False, exclude = None,
 legend_label=None, __original_opts=True, aspect_ratio='automatic')
 def plot(funcs, *args, **kwds):
       G_kwds = Graphics._extract_kwds_for_show(kwds, ignore=['xmin',
 'xmax'])

       original_opts = kwds.pop('__original_opts', {})
       do_show = kwds.pop('show',False)

       from sage.structure.element import is_Vector
       if kwds.get('parametric',False) and is_Vector(funcs):
           funcs = tuple(funcs)


       if hasattr(funcs, 'plot'):
           G = funcs.plot(*args, **original_opts)
       # if we are using the generic plotting method
       else:
           # Other things - deleted for clarity

       G._set_extra_kwds(G_kwds)
       if do_show:
           G.show()
       return G
 }}}

 Notice how the last option in @options is aspect_ratio='automatic'. The
 reason that this is the only one with an issue is the comination of
 Graphics._extract_kwds_for_show and G._set_extra_kwds.

 When using Graphics._extract_kwds_for_show we are doing the following:
 file: src/sage/plot/graphics.py
 {{{
     SHOW_OPTIONS = dict(# axes options
                         axes=None, axes_labels=None,
 axes_labels_size=None,
                         axes_pad=None, base=None, scale=None,
                         xmin=None, xmax=None, ymin=None, ymax=None,
                         # Figure options
                         aspect_ratio=None, dpi=DEFAULT_DPI,
 fig_tight=True,
                         figsize=None, fontsize=None, frame=False,
                         title=None, title_pos=None, transparent=False,
                         # Grid options
                         gridlines=None, gridlinesstyle=None,
                         hgridlinesstyle=None, vgridlinesstyle=None,
                         # Legend options
                         legend_options={}, show_legend=None,
                         # Ticks options
                         ticks=None, tick_formatter=None,
 ticks_integer=False,
                         # Text options
                         typeset='default')

     def _extract_kwds_for_show(cls, kwds, ignore=[]):
         result = {}
         for option in cls.SHOW_OPTIONS:
             if option not in ignore:
                 try:
                     result[option] = kwds.pop(option)
                 except KeyError:
                     pass
         return result
 }}}

 As you can see, we always grab these additional kwds, in particular we
 grab the 'aspect_ratio' kwd. This means that when G._set_extra_kwds gets
 called, the aspect ratio is changing AFTER we have already set it in our
 something.plot() method.

 It seems as though this is not working as expected and/or there is some
 non-intuitive way to get around this issue.

 Recommendations:
  - We should only be doing _set_extra_kwds if we are NOT using the plot
 method of an object
  - Or we should have some way to override this property so that if we are
 setting an aspect ratio, then it does not get forcibly overwritten as is
 happening now.


 I'm thinking of doing the second one, where I do something of the
 following nature:

 {{{
       if hasattr(funcs, 'plot'):
           G = funcs.plot(*args, **original_opts)
           for ext in G._extra_kwds
               if ext in G_kwds:
                    delete G_kwds[ext]
 }}}

 Like this, if we are ever setting something beforehand, we are not
 unintentionally removing it as we are now.
 Thoughts would be beneficial on this ticket as plot is a fairly common
 tool that is used in multiple places and so I don't want to alter
 something that might break other things especially if there does actually
 exist something that would get around this issue that I don't know about
 and/or if someone has a different idea of how to approach it.

 Thank you.

--
Ticket URL: <https://trac.sagemath.org/ticket/20924>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to