Draw the path with updated gc.
(self, renderer, gc, tpath, affine, rgbFace)
| 423 | self._gc = kwargs |
| 424 | |
| 425 | def draw_path(self, renderer, gc, tpath, affine, rgbFace): |
| 426 | """Draw the path with updated gc.""" |
| 427 | # Do not modify the input! Use copy instead. |
| 428 | gc0 = renderer.new_gc() |
| 429 | gc0.copy_properties(gc) |
| 430 | |
| 431 | gc0 = self._update_gc(gc0, self._gc) |
| 432 | trans = affine + self._offset_transform(renderer) |
| 433 | |
| 434 | theta = -np.radians(self._angle) |
| 435 | trans_matrix = np.array([[np.cos(theta), -np.sin(theta)], |
| 436 | [np.sin(theta), np.cos(theta)]]) |
| 437 | |
| 438 | # Convert spacing parameter to pixels. |
| 439 | spacing_px = renderer.points_to_pixels(self._spacing) |
| 440 | |
| 441 | # Transform before evaluation because to_polygons works at resolution |
| 442 | # of one -- assuming it is working in pixel space. |
| 443 | transpath = affine.transform_path(tpath) |
| 444 | |
| 445 | # Evaluate path to straight line segments that can be used to |
| 446 | # construct line ticks. |
| 447 | polys = transpath.to_polygons(closed_only=False) |
| 448 | |
| 449 | for p in polys: |
| 450 | x = p[:, 0] |
| 451 | y = p[:, 1] |
| 452 | |
| 453 | # Can not interpolate points or draw line if only one point in |
| 454 | # polyline. |
| 455 | if x.size < 2: |
| 456 | continue |
| 457 | |
| 458 | # Find distance between points on the line |
| 459 | ds = np.hypot(x[1:] - x[:-1], y[1:] - y[:-1]) |
| 460 | |
| 461 | # Build parametric coordinate along curve |
| 462 | s = np.concatenate(([0.0], np.cumsum(ds))) |
| 463 | s_total = s[-1] |
| 464 | |
| 465 | num = int(np.ceil(s_total / spacing_px)) - 1 |
| 466 | # Pick parameter values for ticks. |
| 467 | s_tick = np.linspace(spacing_px/2, s_total - spacing_px/2, num) |
| 468 | |
| 469 | # Find points along the parameterized curve |
| 470 | x_tick = np.interp(s_tick, s, x) |
| 471 | y_tick = np.interp(s_tick, s, y) |
| 472 | |
| 473 | # Find unit vectors in local direction of curve |
| 474 | delta_s = self._spacing * .001 |
| 475 | u = (np.interp(s_tick + delta_s, s, x) - x_tick) / delta_s |
| 476 | v = (np.interp(s_tick + delta_s, s, y) - y_tick) / delta_s |
| 477 | |
| 478 | # Normalize slope into unit slope vector. |
| 479 | n = np.hypot(u, v) |
| 480 | mask = n == 0 |
| 481 | n[mask] = 1.0 |
| 482 |
nothing calls this directly
no test coverage detected