Ticket #15315: trac_15315-density_and_matrix_plot_aspect_ratio.patch

File trac_15315-density_and_matrix_plot_aspect_ratio.patch, 2.6 KB (added by ppurka, 8 years ago)
  • sage/plot/density_plot.py

    # HG changeset patch
    # User Punarbasu Purkayastha <ppurka@gmail.com>
    # Date 1382407104 -28800
    # Node ID 4a2501c8b79c1e5922202eb21dc11c808dab8d85
    # Parent  69c1cf4a08321aa2b9e47a0a912adf0fdbc251b8
    fix aspect_ratio for density_plot
    
    diff --git a/sage/plot/density_plot.py b/sage/plot/density_plot.py
    a b  
    4242
    4343    EXAMPLES:
    4444
    45     Note this should normally be used indirectly via `density_plot``::
     45    Note this should normally be used indirectly via ``density_plot``::
    4646
    4747        sage: from sage.plot.density_plot import DensityPlot
    4848        sage: D = DensityPlot([[1,3],[2,4]],(1,2),(2,3),options={})
     
    220220    ::
    221221
    222222        sage: density_plot(log(x) + log(y), (x, 1, 10), (y, 1, 10)).show(dpi=20) # These are equivalent
     223
     224    TESTS:
     225
     226    Check that :trac:`15315` is fixed, i.e., density_plot respects the
     227    ``aspect_ratio`` parameter. Without the fix, it looks like a thin line
     228    of width a few mm. With the fix it should look like a nice fat layered
     229    image::
     230
     231        sage: density_plot((x*y)^(1/2), (x,0,3), (y,0,500), aspect_ratio=.01)
     232
     233    Default ``aspect_ratio`` is ``"automatic"``, and that should work too::
     234
     235        sage: density_plot((x*y)^(1/2), (x,0,3), (y,0,500))
     236
    223237    """
    224238    from sage.plot.all import Graphics
    225239    from sage.plot.misc import setup_for_eval_on_grid
  • sage/plot/graphics.py

    diff --git a/sage/plot/graphics.py b/sage/plot/graphics.py
    a b  
    22132213        subplot = sub
    22142214        if not subplot:
    22152215            subplot = figure.add_subplot(111)
    2216         if aspect_ratio is None:
    2217             aspect_ratio=self.aspect_ratio()
    2218         if aspect_ratio == 'automatic':
    2219             subplot.set_aspect('auto', adjustable='box')
    2220         else:
    2221             subplot.set_aspect(aspect_ratio, adjustable='box')
    22222216        #add all the primitives to the subplot
    22232217        old_opts = dict()
    22242218        for g in self._objects:
     
    22312225            g._render_on_subplot(subplot)
    22322226            if hasattr(g, '_bbox_extra_artists'):
    22332227                self._bbox_extra_artists.extend(g._bbox_extra_artists)
     2228        # Set the aspect ratio
     2229        if aspect_ratio is None:
     2230            aspect_ratio=self.aspect_ratio()
     2231        if aspect_ratio == 'automatic':
     2232            subplot.set_aspect('auto', adjustable='box')
     2233        else:
     2234            subplot.set_aspect(aspect_ratio, adjustable='box')
    22342235
    22352236        #--------------------------- Set the scale -----------------------#
    22362237        xscale, yscale, basex, basey = self._set_scale(figure, scale=scale,