Changeset 7831:89f6eb0997d3
Legend:
- Unmodified
- Added
- Removed
-
sage/plot/axes.py
r2450 r7831 255 255 #draw the x-axes? 256 256 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], 258 258 color=self.__color, linewidth=float(self.__linewidth))) 259 259 #draw y axis line? 260 260 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], 262 262 color=self.__color, linewidth=float(self.__linewidth))) 263 263 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], 265 265 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], 267 267 color=self.__color, linewidth=float(self.__linewidth))) 268 268 … … 331 331 subplot.text(x, xlabel, s, fontsize=int(self.__fontsize), horizontalalignment="center", 332 332 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], 334 334 color=self.__color, linewidth=float(self.__linewidth))) 335 335 336 336 #now draw the x-axis minor tick marks 337 337 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], 339 339 color=self.__color, linewidth=float(self.__linewidth))) 340 340 … … 347 347 subplot.text(ylabel, y, s, fontsize=int(self.__fontsize), verticalalignment="center", 348 348 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], 350 350 color=self.__color, linewidth=float(self.__linewidth))) 351 351 352 352 #now draw the x-axis minor tick marks 353 353 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], 355 355 color=self.__color, linewidth=float(self.__linewidth))) 356 356 … … 369 369 #border horizontal axis: 370 370 #bottom: 371 subplot.add_line(patches. Line2D([xmins, xmaxs], [ymins, ymins],371 subplot.add_line(patches.lines.Line2D([xmins, xmaxs], [ymins, ymins], 372 372 color=self.__color, linewidth=float(self.__linewidth))) 373 373 #top: 374 subplot.add_line(patches. Line2D([xmins, xmaxs], [ymaxs, ymaxs],374 subplot.add_line(patches.lines.Line2D([xmins, xmaxs], [ymaxs, ymaxs], 375 375 color=self.__color, linewidth=float(self.__linewidth))) 376 376 #border vertical axis: 377 377 #left: 378 subplot.add_line(patches. Line2D([xmins, xmins], [ymins, ymaxs],378 subplot.add_line(patches.lines.Line2D([xmins, xmins], [ymins, ymaxs], 379 379 color=self.__color, linewidth=float(self.__linewidth))) 380 380 #right: 381 subplot.add_line(patches. Line2D([xmaxs, xmaxs], [ymins, ymaxs],381 subplot.add_line(patches.lines.Line2D([xmaxs, xmaxs], [ymins, ymaxs], 382 382 color=self.__color, linewidth=float(self.__linewidth))) 383 383 … … 427 427 if axes_with_no_ticks: 428 428 #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], 430 430 color=self.__color, linewidth=float(self.__linewidth))) 431 431 432 432 #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], 434 434 color=self.__color, linewidth=float(self.__linewidth))) 435 435 … … 443 443 #now draw the x-axis minor tick marks 444 444 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], 446 446 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], 448 448 color=self.__color, linewidth=float(self.__linewidth))) 449 449 … … 458 458 #now draw the x-axis minor tick marks 459 459 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], 461 461 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], 463 463 color=self.__color, linewidth=float(self.__linewidth))) 464 464 … … 529 529 subplot.text(xr, -2*xlabel + ymaxs, s, fontsize=int(self.__fontsize), 530 530 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], 532 532 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], 534 534 color=self.__color, linewidth=float(self.__linewidth))) 535 535 … … 542 542 subplot.text(-2*ylabel + xmaxs, yr, s, fontsize=int(self.__fontsize), 543 543 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], 545 545 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], 547 547 color=self.__color, linewidth=float(self.__linewidth))) 548 548 -
sage/plot/plot.py
r7799 r7831 988 988 color = options['rgbcolor'] 989 989 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) 991 996 992 997 … … 1032 1037 del options['thickness'] 1033 1038 del options['rgbcolor'] 1034 p = patches. Line2D(self.xdata, self.ydata, **options)1039 p = patches.lines.Line2D(self.xdata, self.ydata, **options) 1035 1040 options = self.options() 1036 1041 a = float(options['alpha']) … … 1160 1165 print "The possible color maps include: %s"%possibilities 1161 1166 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])) 1163 1169 1164 1170 # Below is the base class that is used to make 'field plots'. … … 1421 1427 sage: G.axes(False) 1422 1428 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 1423 1434 """ 1424 1435 def __init__(self, graph, pos=None, vertex_labels=True, vertex_size=300, vertex_colors=None, edge_colors=None, scaling_term=0.05): … … 1485 1496 NX.draw_networkx_nodes(G=self.__nxg, pos=self.__pos, ax=subplot, node_size=vertex_size) 1486 1497 else: 1498 from numpy import array 1487 1499 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) 1489 1503 if self.__edge_colors is None: 1490 1504 NX.draw_networkx_edges(G=self.__nxg, pos=self.__pos, ax=subplot, node_size=vertex_size) 1491 1505 else: 1492 1506 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) 1494 1510 if self.__vertex_labels: 1495 1511 labels = {} … … 1589 1605 def __call__(self, mat, **kwds): 1590 1606 from sage.matrix.all import is_Matrix 1591 from matplotlib.numerix import array #is this needed?1607 from matplotlib.numerix import array 1592 1608 if not is_Matrix(mat) or (isinstance(mat, (list, tuple)) and isinstance(mat[0], (list, tuple))): 1593 1609 raise TypeError, "mat must be of type Matrix or a two dimensional array" … … 1601 1617 xrange = (0, len(mat[0])) 1602 1618 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] 1604 1620 return self._from_xdata_ydata(xy_data_array, xrange, yrange, options=options) 1605 1621 … … 2024 2040 A matrix over ZZ colored with different grey levels: 2025 2041 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]]))) 2029 2043 2030 2044 Here we make a random matrix over RR and use cmap='hsv' 2031 2045 to color the matrix elements different RGB colors: 2032 2046 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')) 2038 2051 """ 2039 2052 def _reset(self):
Note: See TracChangeset
for help on using the changeset viewer.
