Ticket #9211: trac-9211-graph-vertices-cut.patch

File trac-9211-graph-vertices-cut.patch, 5.5 KB (added by jason, 11 years ago)
  • sage/graphs/graph_plot.py

    # HG changeset patch
    # User Jason Grout <jason-sage@creativetrax.com>
    # Date 1276377726 18000
    # Node ID db0a3682bd5a7cec7f484b80369006f8bcaa3568
    # Parent  8210fcf8e8e204c16f050858a1dcfac6d2656713
    #9211: Make graphs not cut off the vertices
    
    diff -r 8210fcf8e8e2 -r db0a3682bd5a sage/graphs/graph_plot.py
    a b  
    198198        if 'vertex_shape' in self._options:
    199199            voptions['marker'] = self._options['vertex_shape']
    200200           
     201        # markersize is in points^2=(1/72 inches)^2.  At 100dpi, this means
     202        # that the radius is
    201203        if self._graph.is_directed():
     204            # Assuming markersize is in data coordinates^2, this sets
     205            # the vertex radius
    202206            self._vertex_radius = sqrt(voptions['markersize']/pi)
    203207            self._arrowshorten = 2*self._vertex_radius
    204208            if self._arcdigraph:
     209                # in this case, we plot the vertices using scatter
     210                # plot.  The constant below should be converting from
     211                # points to data coordinates, but I don't think it's
     212                # correct for that.
    205213                self._vertex_radius = sqrt(voptions['markersize']/(20500*pi))
    206214
    207215        voptions['zorder'] = 7   
     
    209217        if not isinstance(vertex_colors, dict):
    210218            voptions['facecolor'] = vertex_colors
    211219            if self._arcdigraph:
    212                 self._plot_components['vertices'] = [circle(center, self._vertex_radius, fill=True, facecolor=vertex_colors) for center in self._pos.values()]
     220                self._plot_components['vertices'] = [circle(center, self._vertex_radius,
     221                                                            fill=True, facecolor=vertex_colors)
     222                                                     for center in self._pos.values()]
    213223            else:
    214                 self._plot_components['vertices'] = scatter_plot(self._pos.values(), **voptions)
     224                self._plot_components['vertices'] = scatter_plot(self._pos.values(), clip=False,
     225                                                                 **voptions)
    215226        else:
    216227            # Color list must be ordered:
    217228            pos = []
     
    234245            if self._arcdigraph:
    235246                self._plot_components['vertices'] = [circle(pos[i], self._vertex_radius, fill=True, facecolor=colors[i]) for i in range(len(pos))]
    236247            else:
    237                 self._plot_components['vertices'] = scatter_plot(pos, facecolor=colors, **voptions)
     248                self._plot_components['vertices'] = scatter_plot(pos, facecolor=colors, clip=False,
     249                                                                 **voptions)
    238250
    239251        if self._options['vertex_labels']:
    240252            self._plot_components['vertex_labels'] = []
  • sage/plot/plot.py

    diff -r 8210fcf8e8e2 -r db0a3682bd5a sage/plot/plot.py
    a b  
    445445        self.__axes_width = 0.8
    446446        self.__objects = []
    447447        self._extra_kwds = {}
     448        self.__bbox_extra_artists = []
    448449
    449450    def set_aspect_ratio(self, ratio):
    450451        """
     
    16501651        #add all the primitives to the subplot
    16511652        for g in self.__objects:
    16521653            g._render_on_subplot(subplot)
     1654            if hasattr(g, '_bbox_extra_artists'):
     1655                self.__bbox_extra_artists.extend(g._bbox_extra_artists)
    16531656       
    16541657           
    16551658        subplot.set_xlim([xmin, xmax])
     
    19701973                    dpi = 100
    19711974            else:
    19721975                raise ValueError, "file extension must be either 'png', 'ps, 'eps', 'pdf, 'svg' or 'sobj'"
    1973             figure.savefig(filename,dpi=dpi,bbox_inches='tight',**options)
     1976            figure.savefig(filename,dpi=dpi,bbox_inches='tight',
     1977                           bbox_extra_artists=self.__bbox_extra_artists, **options)
    19741978
    19751979
    19761980_SelectiveFormatterClass = None
  • sage/plot/scatter_plot.py

    diff -r 8210fcf8e8e2 -r db0a3682bd5a sage/plot/scatter_plot.py
    a b  
    8484                'hue':'The color given as a hue.',
    8585                'facecolor':'The color of the marker face.',
    8686                'edgecolor':'The color of the marker border.',
    87                 'zorder':'The layer level in which to draw.'}
     87                'zorder':'The layer level in which to draw.',
     88                'clip': 'Whether or not to clip'}
    8889
    8990    def _repr_(self):
    9091        """
     
    107108        """
    108109        from matplotlib.pyplot import scatter 
    109110        options = self.options()
    110         subplot.scatter(self.xdata, self.ydata, alpha=options['alpha'], zorder=options['zorder'], marker=options['marker'],s=options['markersize'],facecolors=options['facecolor'], edgecolors=options['edgecolor'])
     111        p=subplot.scatter(self.xdata, self.ydata, alpha=options['alpha'], zorder=options['zorder'], marker=options['marker'],s=options['markersize'],facecolors=options['facecolor'], edgecolors=options['edgecolor'], clip_on=options['clip'])
     112        if not options['clip']:
     113            self._bbox_extra_artists=[p]
    111114
    112 @options(alpha=1, markersize=50, marker='o', zorder=5, facecolor='#fec7b8', edgecolor='black')
     115@options(alpha=1, markersize=50, marker='o', zorder=5, facecolor='#fec7b8', edgecolor='black', clip=True)
    113116def scatter_plot(datalist, **options):
    114117    """
    115118    Returns a Graphics object of a scatter plot containing all points in