Ticket #9211: trac-9211-fix_cut_vertices_in_graphs.patch

File trac-9211-fix_cut_vertices_in_graphs.patch, 5.6 KB (added by ppurka, 10 years ago)

( Fix cut off vertices in graphs ) Apply to devel/sage/

  • sage/graphs/graph_plot.py

    # HG changeset patch
    # User P Purkayastha <ppurka@gmail.com>
    # Date 1318325123 -28800
    # Node ID b01c2facbe51d941d95a8b5ca8169d0fd8f5f45a
    # Parent  8a0b4f90f1ca76dbdba159897c39209c5da85442
    # trac #9211: Fix cut off vertices in graphs
    
    diff --git a/sage/graphs/graph_plot.py b/sage/graphs/graph_plot.py
    a b  
    237237        if not isinstance(vertex_colors, dict):
    238238            voptions['facecolor'] = vertex_colors
    239239            if self._arcdigraph:
    240                 self._plot_components['vertices'] = [circle(center, self._vertex_radius, fill=True, facecolor=vertex_colors) for center in self._pos.values()]
     240                self._plot_components['vertices'] = [circle(center,
     241                    self._vertex_radius, fill=True, facecolor=vertex_colors)
     242                    for center in self._pos.values()]
    241243            else:
    242                 self._plot_components['vertices'] = scatter_plot(self._pos.values(), **voptions)
     244                self._plot_components['vertices'] = scatter_plot(
     245                    self._pos.values(), clip=False, **voptions)
    243246        else:
    244247            # Color list must be ordered:
    245248            pos = []
     
    260263                colors+=[c]*len(leftovers)
    261264
    262265            if self._arcdigraph:
    263                 self._plot_components['vertices'] = [circle(pos[i], self._vertex_radius, fill=True, facecolor=colors[i]) for i in range(len(pos))]
     266                self._plot_components['vertices'] = [circle(pos[i],
     267                    self._vertex_radius, fill=True, facecolor=colors[i])
     268                    for i in range(len(pos))]
    264269            else:
    265                 self._plot_components['vertices'] = scatter_plot(pos, facecolor=colors, **voptions)
     270                self._plot_components['vertices'] = scatter_plot(pos,
     271                    facecolor=colors, clip=False, **voptions)
    266272
    267273        if self._options['vertex_labels']:
    268274            self._plot_components['vertex_labels'] = []
    269275            # TODO: allow text options
    270276            for v in self._nodelist:
    271                 self._plot_components['vertex_labels'].append(text(str(v), self._pos[v], rgbcolor=(0,0,0), zorder=8))
     277                self._plot_components['vertex_labels'].append(text(str(v),
     278                    self._pos[v], rgbcolor=(0,0,0), zorder=8))
    272279   
    273280    def set_edges(self, **edge_options):
    274281        """
  • sage/plot/plot.py

    diff --git a/sage/plot/plot.py b/sage/plot/plot.py
    a b  
    465465        self.__axes_width = 0.8
    466466        self.__objects = []
    467467        self._extra_kwds = {}
     468        self.__bbox_extra_artists = []
    468469
    469470    def set_aspect_ratio(self, ratio):
    470471        """
     
    19771978        #add all the primitives to the subplot
    19781979        for g in self.__objects:
    19791980            g._render_on_subplot(subplot)
     1981            if hasattr(g, '_bbox_extra_artists'):
     1982                self.__bbox_extra_artists.extend(g._bbox_extra_artists)
    19801983       
    19811984        #add the legend if requested
    19821985        if show_legend is None:
     
    24812484            #figure.canvas.mpl_connect('draw_event', pad_for_tick_labels)
    24822485            if fig_tight is True:
    24832486                figure.savefig(filename, dpi=dpi, bbox_inches='tight',
    2484                            transparent=transparent)
     2487                    bbox_extra_artists=self.__bbox_extra_artists,
     2488                    transparent=transparent)
    24852489            else:
    24862490                figure.savefig(filename, dpi=dpi,
    24872491                           transparent=transparent)
  • sage/plot/scatter_plot.py

    diff --git a/sage/plot/scatter_plot.py b/sage/plot/scatter_plot.py
    a b  
    8686             ('marker', 'What shape to plot the points.'),
    8787             ('markersize', 'the size of the markers.'),
    8888             ('rgbcolor', 'The color as an RGB tuple.'),
    89              ('zorder', 'The layer level in which to draw.')]
     89             ('zorder', 'The layer level in which to draw.'),
     90             ('clip', 'Whether or not to clip.')]
    9091        """
    9192        return {'markersize': 'the size of the markers.',
    9293                'marker': 'What shape to plot the points.',
     
    9596                'hue':'The color given as a hue.',
    9697                'facecolor':'The color of the marker face.',
    9798                'edgecolor':'The color of the marker border.',
    98                 'zorder':'The layer level in which to draw.'}
     99                'zorder':'The layer level in which to draw.',
     100                'clip': 'Whether or not to clip.'}
    99101
    100102    def _repr_(self):
    101103        """
     
    126128        """
    127129        from matplotlib.pyplot import scatter 
    128130        options = self.options()
    129         subplot.scatter(self.xdata, self.ydata, alpha=options['alpha'], zorder=options['zorder'], marker=options['marker'],s=options['markersize'],facecolors=options['facecolor'], edgecolors=options['edgecolor'])
     131        p = subplot.scatter(self.xdata, self.ydata, alpha=options['alpha'],
     132                zorder=options['zorder'], marker=options['marker'],
     133                s=options['markersize'], facecolors=options['facecolor'],
     134                edgecolors=options['edgecolor'], clip_on=options['clip'])
     135        if not options['clip']:
     136            self._bbox_extra_artists=[p]
    130137
    131 @options(alpha=1, markersize=50, marker='o', zorder=5, facecolor='#fec7b8', edgecolor='black', aspect_ratio='automatic')
     138@options(alpha=1, markersize=50, marker='o', zorder=5, facecolor='#fec7b8', edgecolor='black', clip=True, aspect_ratio='automatic')
    132139def scatter_plot(datalist, **options):
    133140    """
    134141    Returns a Graphics object of a scatter plot containing all points in