@@ -505,6 +505,60 @@ def test_poly3dcollection_alpha():
505505 ax .add_collection3d (c2 )
506506
507507
508+ @mpl3d_image_comparison (['add_collection3d_zs_array.png' ])
509+ def test_add_collection3d_zs_array ():
510+ theta = np .linspace (- 4 * np .pi , 4 * np .pi , 100 )
511+ z = np .linspace (- 2 , 2 , 100 )
512+ r = z ** 2 + 1
513+ x = r * np .sin (theta )
514+ y = r * np .cos (theta )
515+
516+ points = np .array ([x , y , z ]).T .reshape (- 1 , 1 , 3 )
517+ segments = np .concatenate ([points [:- 1 ], points [1 :]], axis = 1 )
518+
519+ fig = plt .figure ()
520+ ax = fig .gca (projection = '3d' )
521+
522+ norm = plt .Normalize (0 , 2 * np .pi )
523+ # 2D LineCollection from x & y values
524+ lc = LineCollection (segments [:, :, :2 ], cmap = 'twilight' , norm = norm )
525+ lc .set_array (np .mod (theta , 2 * np .pi ))
526+ # Add 2D collection at z values to ax
527+ line = ax .add_collection3d (lc , zs = segments [:, :, 2 ])
528+
529+ assert line is not None
530+
531+ ax .set_xlim (- 5 , 5 )
532+ ax .set_ylim (- 4 , 6 )
533+ ax .set_zlim (- 2 , 2 )
534+
535+
536+ @mpl3d_image_comparison (['add_collection3d_zs_scalar.png' ])
537+ def test_add_collection3d_zs_scalar ():
538+ theta = np .linspace (0 , 2 * np .pi , 100 )
539+ z = 1
540+ r = z ** 2 + 1
541+ x = r * np .sin (theta )
542+ y = r * np .cos (theta )
543+
544+ points = np .array ([x , y ]).T .reshape (- 1 , 1 , 2 )
545+ segments = np .concatenate ([points [:- 1 ], points [1 :]], axis = 1 )
546+
547+ fig = plt .figure ()
548+ ax = fig .gca (projection = '3d' )
549+
550+ norm = plt .Normalize (0 , 2 * np .pi )
551+ lc = LineCollection (segments , cmap = 'twilight' , norm = norm )
552+ lc .set_array (theta )
553+ line = ax .add_collection3d (lc , zs = z )
554+
555+ assert line is not None
556+
557+ ax .set_xlim (- 5 , 5 )
558+ ax .set_ylim (- 4 , 6 )
559+ ax .set_zlim (0 , 2 )
560+
561+
508562@mpl3d_image_comparison (['axes3d_labelpad.png' ], remove_text = False )
509563def test_axes3d_labelpad ():
510564 fig = plt .figure ()
0 commit comments