Changeset 7854:3212df4ffd91


Ignore:
Timestamp:
12/21/07 15:28:41 (5 years ago)
Author:
William Stein <wstein@…>
Branch:
default
Message:

Trac #924 -- changes need to upgrade to matplotlib-0.91.1

Location:
sage/plot
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sage/plot/axes.py

    r2450 r7831  
    255255            #draw the x-axes? 
    256256            if self.__draw_x_axis: 
    257                 subplot.add_line(patches.Line2D([xmin, xmax], [x_axis_ypos, x_axis_ypos], 
     257                subplot.add_line(patches.lines.Line2D([xmin, xmax], [x_axis_ypos, x_axis_ypos], 
    258258                                 color=self.__color, linewidth=float(self.__linewidth))) 
    259259            #draw y axis line? 
    260260            if self.__draw_y_axis: 
    261                 subplot.add_line(patches.Line2D([y_axis_xpos, y_axis_xpos],[ymin, ymax], 
     261                subplot.add_line(patches.lines.Line2D([y_axis_xpos, y_axis_xpos],[ymin, ymax], 
    262262                                  color=self.__color, linewidth=float(self.__linewidth))) 
    263263        else: #draw them both 
    264             subplot.add_line(patches.Line2D([xmin, xmax], [x_axis_ypos, x_axis_ypos], 
     264            subplot.add_line(patches.lines.Line2D([xmin, xmax], [x_axis_ypos, x_axis_ypos], 
    265265                             color=self.__color, linewidth=float(self.__linewidth))) 
    266             subplot.add_line(patches.Line2D([y_axis_xpos, y_axis_xpos],[ymin, ymax], 
     266            subplot.add_line(patches.lines.Line2D([y_axis_xpos, y_axis_xpos],[ymin, ymax], 
    267267                              color=self.__color, linewidth=float(self.__linewidth))) 
    268268 
     
    331331            subplot.text(x, xlabel, s, fontsize=int(self.__fontsize), horizontalalignment="center",  
    332332                        color=self.__tick_color, verticalalignment="top") 
    333             subplot.add_line(patches.Line2D([x, x], [x_axis_ypos, x_axis_ypos + xltheight], 
     333            subplot.add_line(patches.lines.Line2D([x, x], [x_axis_ypos, x_axis_ypos + xltheight], 
    334334                        color=self.__color, linewidth=float(self.__linewidth))) 
    335335 
    336336        #now draw the x-axis minor tick marks 
    337337        for x in xtslminor: 
    338             subplot.add_line(patches.Line2D([x, x], [x_axis_ypos, x_axis_ypos + xstheight], 
     338            subplot.add_line(patches.lines.Line2D([x, x], [x_axis_ypos, x_axis_ypos + xstheight], 
    339339                        color=self.__color, linewidth=float(self.__linewidth))) 
    340340 
     
    347347            subplot.text(ylabel, y, s, fontsize=int(self.__fontsize), verticalalignment="center", 
    348348                        color=self.__tick_color, horizontalalignment="right") 
    349             subplot.add_line(patches.Line2D([y_axis_xpos, y_axis_xpos + yltheight], [y, y], 
     349            subplot.add_line(patches.lines.Line2D([y_axis_xpos, y_axis_xpos + yltheight], [y, y], 
    350350                    color=self.__color, linewidth=float(self.__linewidth))) 
    351351             
    352352        #now draw the x-axis minor tick marks 
    353353        for y in ytslminor: 
    354             subplot.add_line(patches.Line2D([y_axis_xpos, y_axis_xpos + ystheight], [y, y], 
     354            subplot.add_line(patches.lines.Line2D([y_axis_xpos, y_axis_xpos + ystheight], [y, y], 
    355355                color=self.__color, linewidth=float(self.__linewidth))) 
    356356 
     
    369369        #border horizontal axis: 
    370370        #bottom: 
    371         subplot.add_line(patches.Line2D([xmins, xmaxs], [ymins, ymins], 
     371        subplot.add_line(patches.lines.Line2D([xmins, xmaxs], [ymins, ymins], 
    372372                                        color=self.__color, linewidth=float(self.__linewidth))) 
    373373        #top: 
    374         subplot.add_line(patches.Line2D([xmins, xmaxs], [ymaxs, ymaxs], 
     374        subplot.add_line(patches.lines.Line2D([xmins, xmaxs], [ymaxs, ymaxs], 
    375375                                        color=self.__color, linewidth=float(self.__linewidth))) 
    376376        #border vertical axis: 
    377377        #left: 
    378         subplot.add_line(patches.Line2D([xmins, xmins], [ymins, ymaxs], 
     378        subplot.add_line(patches.lines.Line2D([xmins, xmins], [ymins, ymaxs], 
    379379                                        color=self.__color, linewidth=float(self.__linewidth))) 
    380380        #right: 
    381         subplot.add_line(patches.Line2D([xmaxs, xmaxs], [ymins, ymaxs], 
     381        subplot.add_line(patches.lines.Line2D([xmaxs, xmaxs], [ymins, ymaxs], 
    382382                                        color=self.__color, linewidth=float(self.__linewidth))) 
    383383 
     
    427427        if axes_with_no_ticks: 
    428428            #the x axis line 
    429             subplot.add_line(patches.Line2D([xmins, xmaxs], [x_axis_ypos, x_axis_ypos], 
     429            subplot.add_line(patches.lines.Line2D([xmins, xmaxs], [x_axis_ypos, x_axis_ypos], 
    430430                                            color=self.__color, linewidth=float(self.__linewidth))) 
    431431 
    432432            #the y axis line 
    433             subplot.add_line(patches.Line2D([y_axis_xpos, y_axis_xpos],[ymins, ymaxs], 
     433            subplot.add_line(patches.lines.Line2D([y_axis_xpos, y_axis_xpos],[ymins, ymaxs], 
    434434                                            color=self.__color, linewidth=float(self.__linewidth))) 
    435435            
     
    443443        #now draw the x-axis minor tick marks 
    444444        for x in xtslminor: 
    445             subplot.add_line(patches.Line2D([x, x], [ymins, xstheight + ymins], 
     445            subplot.add_line(patches.lines.Line2D([x, x], [ymins, xstheight + ymins], 
    446446                        color=self.__color, linewidth=float(self.__linewidth))) 
    447             subplot.add_line(patches.Line2D([x, x], [ymaxs, ymaxs - xstheight], 
     447            subplot.add_line(patches.lines.Line2D([x, x], [ymaxs, ymaxs - xstheight], 
    448448                        color=self.__color, linewidth=float(self.__linewidth))) 
    449449 
     
    458458        #now draw the x-axis minor tick marks 
    459459        for y in ytslminor: 
    460             subplot.add_line(patches.Line2D([xmins, ystheight + xmins], [y, y], 
     460            subplot.add_line(patches.lines.Line2D([xmins, ystheight + xmins], [y, y], 
    461461                color=self.__color, linewidth=float(self.__linewidth))) 
    462             subplot.add_line(patches.Line2D([xmaxs, xmaxs - ystheight], [y, y], 
     462            subplot.add_line(patches.lines.Line2D([xmaxs, xmaxs - ystheight], [y, y], 
    463463                color=self.__color, linewidth=float(self.__linewidth))) 
    464464 
     
    529529            subplot.text(xr, -2*xlabel + ymaxs, s, fontsize=int(self.__fontsize), 
    530530                         horizontalalignment="center", verticalalignment="top") 
    531             subplot.add_line(patches.Line2D([xr, xr], [ymins, xstheight + ymins], 
     531            subplot.add_line(patches.lines.Line2D([xr, xr], [ymins, xstheight + ymins], 
    532532                        color=self.__color, linewidth=float(self.__linewidth))) 
    533             subplot.add_line(patches.Line2D([xr, xr], [ymaxs, ymaxs - xstheight], 
     533            subplot.add_line(patches.lines.Line2D([xr, xr], [ymaxs, ymaxs - xstheight], 
    534534                        color=self.__color, linewidth=float(self.__linewidth))) 
    535535                     
     
    542542            subplot.text(-2*ylabel + xmaxs, yr, s, fontsize=int(self.__fontsize),  
    543543                         verticalalignment="center", horizontalalignment="left") 
    544             subplot.add_line(patches.Line2D([xmins, ystheight + xmins], [yr, yr], 
     544            subplot.add_line(patches.lines.Line2D([xmins, ystheight + xmins], [yr, yr], 
    545545                color=self.__color, linewidth=float(self.__linewidth))) 
    546             subplot.add_line(patches.Line2D([xmaxs, xmaxs - ystheight], [yr, yr], 
     546            subplot.add_line(patches.lines.Line2D([xmaxs, xmaxs - ystheight], [yr, yr], 
    547547                color=self.__color, linewidth=float(self.__linewidth))) 
    548548 
  • sage/plot/plot.py

    r7799 r7831  
    988988        color = options['rgbcolor'] 
    989989        width = float(options['width']) 
    990         subplot.bar(self.ind, self.datalist, color=color, width=width) 
     990        # it is critical to make numpy arrays of type float below, 
     991        # or bar will go boom: 
     992        import numpy 
     993        ind = numpy.array(self.ind, dtype=float) 
     994        datalist = numpy.array(self.datalist, dtype=float) 
     995        subplot.bar(ind, datalist, color=color, width=width) 
    991996 
    992997 
     
    10321037        del options['thickness'] 
    10331038        del options['rgbcolor'] 
    1034         p = patches.Line2D(self.xdata, self.ydata, **options) 
     1039        p = patches.lines.Line2D(self.xdata, self.ydata, **options) 
    10351040        options = self.options() 
    10361041        a = float(options['alpha']) 
     
    11601165            print "The possible color maps include: %s"%possibilities 
    11611166            raise RuntimeError, "Color map %s not known"%cmap 
    1162         subplot.imshow(self.xy_data_array, cmap=cmap, interpolation='nearest') 
     1167         
     1168        subplot.imshow(self.xy_data_array, cmap=cmap, interpolation='nearest', extent=(0,self.xrange[1],0,self.yrange[1])) 
    11631169 
    11641170# Below is the base class that is used to make 'field plots'. 
     
    14211427        sage: G.axes(False) 
    14221428        sage: G.show() 
     1429 
     1430    We color the edges and vertices of a Dodecahedral graph: 
     1431        sage: g = graphs.DodecahedralGraph() 
     1432        sage: g.show(edge_colors={(1.0, 0.8571428571428571, 0.0): g.edges()}) 
     1433     
    14231434    """ 
    14241435    def __init__(self, graph, pos=None, vertex_labels=True, vertex_size=300, vertex_colors=None, edge_colors=None, scaling_term=0.05): 
     
    14851496                NX.draw_networkx_nodes(G=self.__nxg, pos=self.__pos, ax=subplot, node_size=vertex_size) 
    14861497            else: 
     1498                from numpy import array 
    14871499                for i in self.__vertex_colors: 
    1488                     NX.draw_networkx_nodes(G=self.__nxg, nodelist=self.__vertex_colors[i], node_color=i, pos=self.__pos, ax=subplot, node_size=vertex_size) 
     1500                    NX.draw_networkx_nodes(G=self.__nxg, nodelist=self.__vertex_colors[i], 
     1501                                           node_color=i if isinstance(i, str) else [float(z) for z in i], 
     1502                                           pos=self.__pos, ax=subplot, node_size=vertex_size) 
    14891503            if self.__edge_colors is None: 
    14901504                NX.draw_networkx_edges(G=self.__nxg, pos=self.__pos, ax=subplot, node_size=vertex_size) 
    14911505            else: 
    14921506                for i in self.__edge_colors: 
    1493                     NX.draw_networkx_edges(G=self.__nxg, pos=self.__pos, edgelist=self.__edge_colors[i], edge_color=i, ax=subplot, node_size=vertex_size) 
     1507                    NX.draw_networkx_edges(G=self.__nxg, pos=self.__pos, edgelist=self.__edge_colors[i], 
     1508                                           edge_color=i if isinstance(i, str) else [float(z) for z in i], 
     1509                                           ax=subplot, node_size=vertex_size) 
    14941510            if self.__vertex_labels: 
    14951511                labels = {} 
     
    15891605    def __call__(self, mat, **kwds): 
    15901606        from sage.matrix.all import is_Matrix  
    1591         from matplotlib.numerix import array #is this needed? 
     1607        from matplotlib.numerix import array 
    15921608        if not is_Matrix(mat) or (isinstance(mat, (list, tuple)) and isinstance(mat[0], (list, tuple))): 
    15931609            raise TypeError, "mat must be of type Matrix or a two dimensional array" 
     
    16011617            xrange = (0, len(mat[0])) 
    16021618            yrange = (0, len(mat)) 
    1603         xy_data_array = [array(r) for r in mat] 
     1619        xy_data_array = [array(r, dtype=float) for r in mat] 
    16041620        return self._from_xdata_ydata(xy_data_array, xrange, yrange, options=options) 
    16051621 
     
    20242040    A matrix over ZZ colored with different grey levels: 
    20252041     
    2026         sage: M1 = Matrix(ZZ,3,4,[[1,3,5,1],[2,4,5,6],[1,3,5,7]])  
    2027         sage: MP1 = matrix_plot(M1) 
    2028         sage: MP1.show() 
     2042        sage: show(matrix_plot(matrix([[1,3,5,1],[2,4,5,6],[1,3,5,7]]))) 
    20292043 
    20302044    Here we make a random matrix over RR and use cmap='hsv' 
    20312045    to color the matrix elements different RGB colors: 
    20322046 
    2033         sage: n = 22 
    2034         sage: L = [n*random() for i in range(n*n)] 
    2035         sage: M2 = Matrix(RR, n, n, L) 
    2036         sage: MP2 = matrix_plot(M2, cmap='hsv') 
    2037         sage: MP2.show() 
     2047        sage: show(matrix_plot(random_matrix(RDF, 50), cmap='hsv')) 
     2048 
     2049    Another random plot, but over GF(389): 
     2050        sage: show(matrix_plot(random_matrix(GF(389), 10), cmap='Oranges')) 
    20382051    """ 
    20392052    def _reset(self): 
Note: See TracChangeset for help on using the changeset viewer.