Ticket #3392: matplotlib-sage.3.patch
| File matplotlib-sage.3.patch, 11.1 kB (added by jason, 5 months ago) |
|---|
-
a/sage/plot/axes.py
old new 245 245 return oppaxis, step, tslminor, tslmajor 246 246 247 247 def _draw_axes(self, subplot, axes, xmin, xmax, ymin, ymax, x_axis_ypos, y_axis_xpos): 248 from matplotlib import patches248 from matplotlib import lines 249 249 if isinstance(axes, (list, tuple)) and len(axes) == 2 and \ 250 250 (axes[0] in [True, False]) and (axes[1] in [True, False]): 251 251 self.__draw_x_axis = axes[0] 252 252 self.__draw_y_axis = axes[1] 253 253 #draw the x-axes? 254 254 if self.__draw_x_axis: 255 subplot.add_line( patches.lines.Line2D([xmin, xmax], [x_axis_ypos, x_axis_ypos],255 subplot.add_line(lines.Line2D([xmin, xmax], [x_axis_ypos, x_axis_ypos], 256 256 color=self.__color, linewidth=float(self.__linewidth))) 257 257 #draw y axis line? 258 258 if self.__draw_y_axis: 259 subplot.add_line( patches.lines.Line2D([y_axis_xpos, y_axis_xpos],[ymin, ymax],259 subplot.add_line(lines.Line2D([y_axis_xpos, y_axis_xpos],[ymin, ymax], 260 260 color=self.__color, linewidth=float(self.__linewidth))) 261 261 else: #draw them both 262 subplot.add_line( patches.lines.Line2D([xmin, xmax], [x_axis_ypos, x_axis_ypos],262 subplot.add_line(lines.Line2D([xmin, xmax], [x_axis_ypos, x_axis_ypos], 263 263 color=self.__color, linewidth=float(self.__linewidth))) 264 subplot.add_line( patches.lines.Line2D([y_axis_xpos, y_axis_xpos],[ymin, ymax],264 subplot.add_line(lines.Line2D([y_axis_xpos, y_axis_xpos],[ymin, ymax], 265 265 color=self.__color, linewidth=float(self.__linewidth))) 266 266 267 267 def _draw_axes_labels(self, subplot, axes_labels, xmin, xmax, ymin, ymax, xstep, ystep, x_axis_ypos, y_axis_xpos, pad=0.2): … … 310 310 xlabel : "where the xlabel is drawn" 311 311 312 312 """ 313 from matplotlib import patches313 from matplotlib import lines 314 314 xmin = float(xmin); xmax=float(xmax); ymin=float(ymin); ymax=float(ymax) 315 315 yspan = ymax - ymin 316 316 xspan = xmax - xmin … … 338 338 s = self._format_tick_string(x) 339 339 subplot.text(x, xlabel, s, fontsize=int(self.__fontsize), horizontalalignment="center", 340 340 color=self.__tick_label_color, verticalalignment="top") 341 subplot.add_line( patches.lines.Line2D([x, x], [x_axis_ypos, x_axis_ypos + xltheight],341 subplot.add_line(lines.Line2D([x, x], [x_axis_ypos, x_axis_ypos + xltheight], 342 342 color=self.__color, linewidth=float(self.__linewidth))) 343 343 344 344 #now draw the x-axis minor tick marks 345 345 for x in xtslminor: 346 subplot.add_line( patches.lines.Line2D([x, x], [x_axis_ypos, x_axis_ypos + xstheight],346 subplot.add_line(lines.Line2D([x, x], [x_axis_ypos, x_axis_ypos + xstheight], 347 347 color=self.__color, linewidth=float(self.__linewidth))) 348 348 349 349 #the y-axis ticks and labels … … 354 354 s = self._format_tick_string(y) 355 355 subplot.text(ylabel, y, s, fontsize=int(self.__fontsize), verticalalignment="center", 356 356 color=self.__tick_label_color, horizontalalignment="right") 357 subplot.add_line( patches.lines.Line2D([y_axis_xpos, y_axis_xpos + yltheight], [y, y],357 subplot.add_line(lines.Line2D([y_axis_xpos, y_axis_xpos + yltheight], [y, y], 358 358 color=self.__color, linewidth=float(self.__linewidth))) 359 359 360 360 #now draw the x-axis minor tick marks 361 361 for y in ytslminor: 362 subplot.add_line( patches.lines.Line2D([y_axis_xpos, y_axis_xpos + ystheight], [y, y],362 subplot.add_line(lines.Line2D([y_axis_xpos, y_axis_xpos + ystheight], [y, y], 363 363 color=self.__color, linewidth=float(self.__linewidth))) 364 364 365 365 # now draw the x and y axis labels … … 375 375 Draw a frame around a graphic at the given 376 376 (scaled out) x and y min and max values. 377 377 """ 378 from matplotlib import patches378 from matplotlib import lines 379 379 #border horizontal axis: 380 380 #bottom: 381 subplot.add_line( patches.lines.Line2D([xmins, xmaxs], [ymins, ymins],381 subplot.add_line(lines.Line2D([xmins, xmaxs], [ymins, ymins], 382 382 color=self.__color, linewidth=float(self.__linewidth))) 383 383 #top: 384 subplot.add_line( patches.lines.Line2D([xmins, xmaxs], [ymaxs, ymaxs],384 subplot.add_line(lines.Line2D([xmins, xmaxs], [ymaxs, ymaxs], 385 385 color=self.__color, linewidth=float(self.__linewidth))) 386 386 #border vertical axis: 387 387 #left: 388 subplot.add_line( patches.lines.Line2D([xmins, xmins], [ymins, ymaxs],388 subplot.add_line(lines.Line2D([xmins, xmins], [ymins, ymaxs], 389 389 color=self.__color, linewidth=float(self.__linewidth))) 390 390 #right: 391 subplot.add_line( patches.lines.Line2D([xmaxs, xmaxs], [ymins, ymaxs],391 subplot.add_line(lines.Line2D([xmaxs, xmaxs], [ymins, ymaxs], 392 392 color=self.__color, linewidth=float(self.__linewidth))) 393 393 394 394 … … 403 403 centered axes with no tick marks. 404 404 405 405 """ 406 from matplotlib import patches406 from matplotlib import lines 407 407 xmin = float(xmin); xmax=float(xmax); ymin=float(ymin); ymax=float(ymax) 408 408 yspan = ymax - ymin 409 409 xspan = xmax - xmin … … 431 431 #these are the centered axes, like in regular plot, but with no ticks 432 432 if axes_with_no_ticks: 433 433 #the x axis line 434 subplot.add_line( patches.lines.Line2D([xmins, xmaxs], [x_axis_ypos, x_axis_ypos],434 subplot.add_line(lines.Line2D([xmins, xmaxs], [x_axis_ypos, x_axis_ypos], 435 435 color=self.__color, linewidth=float(self.__linewidth))) 436 436 437 437 #the y axis line 438 subplot.add_line( patches.lines.Line2D([y_axis_xpos, y_axis_xpos],[ymins, ymaxs],438 subplot.add_line(lines.Line2D([y_axis_xpos, y_axis_xpos],[ymins, ymaxs], 439 439 color=self.__color, linewidth=float(self.__linewidth))) 440 440 441 441 #the x-axis ticks and labels … … 447 447 448 448 #now draw the x-axis minor tick marks 449 449 for x in xtslminor: 450 subplot.add_line( patches.lines.Line2D([x, x], [ymins, xstheight + ymins],450 subplot.add_line(lines.Line2D([x, x], [ymins, xstheight + ymins], 451 451 color=self.__color, linewidth=float(self.__linewidth))) 452 subplot.add_line( patches.lines.Line2D([x, x], [ymaxs, ymaxs - xstheight],452 subplot.add_line(lines.Line2D([x, x], [ymaxs, ymaxs - xstheight], 453 453 color=self.__color, linewidth=float(self.__linewidth))) 454 454 455 455 … … 462 462 463 463 #now draw the x-axis minor tick marks 464 464 for y in ytslminor: 465 subplot.add_line( patches.lines.Line2D([xmins, ystheight + xmins], [y, y],465 subplot.add_line(lines.Line2D([xmins, ystheight + xmins], [y, y], 466 466 color=self.__color, linewidth=float(self.__linewidth))) 467 subplot.add_line( patches.lines.Line2D([xmaxs, xmaxs - ystheight], [y, y],467 subplot.add_line(lines.Line2D([xmaxs, xmaxs - ystheight], [y, y], 468 468 color=self.__color, linewidth=float(self.__linewidth))) 469 469 470 470 def _adjustments_for_frame(self, xmin, xmax, ymin, ymax): … … 501 501 the ith row and jth column of the matrix. 502 502 503 503 """ 504 from matplotlib import patches504 from matplotlib import lines 505 505 xmax = int(xmax) 506 506 ymax = int(ymax) 507 507 … … 558 558 horizontalalignment="center", verticalalignment="top") 559 559 subplot.text(xr, -2*xlabel + ymaxs, s, fontsize=int(self.__fontsize), 560 560 horizontalalignment="center", verticalalignment="top") 561 subplot.add_line( patches.lines.Line2D([xr, xr], [ymins, xstheight + ymins],561 subplot.add_line(lines.Line2D([xr, xr], [ymins, xstheight + ymins], 562 562 color=self.__color, linewidth=float(self.__linewidth))) 563 subplot.add_line( patches.lines.Line2D([xr, xr], [ymaxs, ymaxs - xstheight],563 subplot.add_line(lines.Line2D([xr, xr], [ymaxs, ymaxs - xstheight], 564 564 color=self.__color, linewidth=float(self.__linewidth))) 565 565 566 566 #the y-axis ticks and labels … … 571 571 verticalalignment="center", horizontalalignment="right") 572 572 subplot.text(-2*ylabel + xmaxs, yr, s, fontsize=int(self.__fontsize), 573 573 verticalalignment="center", horizontalalignment="left") 574 subplot.add_line( patches.lines.Line2D([xmins, ystheight + xmins], [yr, yr],574 subplot.add_line(lines.Line2D([xmins, ystheight + xmins], [yr, yr], 575 575 color=self.__color, linewidth=float(self.__linewidth))) 576 subplot.add_line( patches.lines.Line2D([xmaxs, xmaxs - ystheight], [yr, yr],576 subplot.add_line(lines.Line2D([xmaxs, xmaxs - ystheight], [yr, yr], 577 577 color=self.__color, linewidth=float(self.__linewidth))) 578 578 579 579 class GridLines(SageObject): … … 799 799 xlines, ylines = new_gridlines 800 800 801 801 # draw the grid lines 802 from matplotlib import patches802 from matplotlib import lines 803 803 # horizontal lines 804 804 for (yval, ykwds) in ylines: 805 805 subplot.add_line( 806 patches.lines.Line2D(points[0],[yval,yval],**ykwds)806 lines.Line2D(points[0],[yval,yval],**ykwds) 807 807 ) 808 808 # vertical lines 809 809 for (xval, xkwds) in xlines: 810 810 subplot.add_line( 811 patches.lines.Line2D([xval,xval],points[1],**xkwds)811 lines.Line2D([xval,xval],points[1],**xkwds) 812 812 ) 813 813 814 814 def _get_ticks_locations(self, interval, ticks="major"): -
a/sage/plot/plot.py
old new 2059 2059 This implicitly calls this function: 2060 2060 sage: line([(1,2), (3,-4), (2, 5), (1,2)]) 2061 2061 """ 2062 import matplotlib. patches as patches2062 import matplotlib.lines as lines 2063 2063 options = dict(self.options()) 2064 2064 del options['alpha'] 2065 2065 del options['thickness'] 2066 2066 del options['rgbcolor'] 2067 p = patches.lines.Line2D(self.xdata, self.ydata, **options)2067 p = lines.Line2D(self.xdata, self.ydata, **options) 2068 2068 options = self.options() 2069 2069 a = float(options['alpha']) 2070 2070 p.set_alpha(a)