| 457 | |
| 458 | @image_comparison(['polycollection_close.png'], remove_text=True, style='mpl20') |
| 459 | def test_polycollection_close(): |
| 460 | from mpl_toolkits.mplot3d import Axes3D |
| 461 | plt.rcParams['axes3d.automargin'] = True |
| 462 | |
| 463 | vertsQuad = [ |
| 464 | [[0., 0.], [0., 1.], [1., 1.], [1., 0.]], |
| 465 | [[0., 1.], [2., 3.], [2., 2.], [1., 1.]], |
| 466 | [[2., 2.], [2., 3.], [4., 1.], [3., 1.]], |
| 467 | [[3., 0.], [3., 1.], [4., 1.], [4., 0.]]] |
| 468 | |
| 469 | fig = plt.figure() |
| 470 | ax = fig.add_axes(Axes3D(fig)) |
| 471 | |
| 472 | colors = ['r', 'g', 'b', 'y', 'k'] |
| 473 | zpos = list(range(5)) |
| 474 | |
| 475 | poly = mcollections.PolyCollection( |
| 476 | vertsQuad * len(zpos), linewidth=0.25) |
| 477 | poly.set_alpha(0.7) |
| 478 | |
| 479 | # need to have a z-value for *each* polygon = element! |
| 480 | zs = [] |
| 481 | cs = [] |
| 482 | for z, c in zip(zpos, colors): |
| 483 | zs.extend([z] * len(vertsQuad)) |
| 484 | cs.extend([c] * len(vertsQuad)) |
| 485 | |
| 486 | poly.set_color(cs) |
| 487 | |
| 488 | ax.add_collection3d(poly, zs=zs, zdir='y') |
| 489 | |
| 490 | # axis limit settings: |
| 491 | ax.set_xlim3d(0, 4) |
| 492 | ax.set_zlim3d(0, 3) |
| 493 | ax.set_ylim3d(0, 4) |
| 494 | |
| 495 | |
| 496 | @check_figures_equal() |