@@ -543,6 +543,60 @@ def test_poly3dcollection_alpha():
543543 ax .add_collection3d (c2 )
544544
545545
546+ @mpl3d_image_comparison (['add_collection3d_zs_array.png' ])
547+ def test_add_collection3d_zs_array ():
548+ theta = np .linspace (- 4 * np .pi , 4 * np .pi , 100 )
549+ z = np .linspace (- 2 , 2 , 100 )
550+ r = z ** 2 + 1
551+ x = r * np .sin (theta )
552+ y = r * np .cos (theta )
553+
554+ points = np .column_stack ([x , y , z ]).reshape (- 1 , 1 , 3 )
555+ segments = np .concatenate ([points [:- 1 ], points [1 :]], axis = 1 )
556+
557+ fig = plt .figure ()
558+ ax = fig .gca (projection = '3d' )
559+
560+ norm = plt .Normalize (0 , 2 * np .pi )
561+ # 2D LineCollection from x & y values
562+ lc = LineCollection (segments [:, :, :2 ], cmap = 'twilight' , norm = norm )
563+ lc .set_array (np .mod (theta , 2 * np .pi ))
564+ # Add 2D collection at z values to ax
565+ line = ax .add_collection3d (lc , zs = segments [:, :, 2 ])
566+
567+ assert line is not None
568+
569+ ax .set_xlim (- 5 , 5 )
570+ ax .set_ylim (- 4 , 6 )
571+ ax .set_zlim (- 2 , 2 )
572+
573+
574+ @mpl3d_image_comparison (['add_collection3d_zs_scalar.png' ])
575+ def test_add_collection3d_zs_scalar ():
576+ theta = np .linspace (0 , 2 * np .pi , 100 )
577+ z = 1
578+ r = z ** 2 + 1
579+ x = r * np .sin (theta )
580+ y = r * np .cos (theta )
581+
582+ points = np .column_stack ([x , y ]).reshape (- 1 , 1 , 2 )
583+ segments = np .concatenate ([points [:- 1 ], points [1 :]], axis = 1 )
584+
585+ fig = plt .figure ()
586+ ax = fig .gca (projection = '3d' )
587+
588+ norm = plt .Normalize (0 , 2 * np .pi )
589+ lc = LineCollection (segments , cmap = 'twilight' , norm = norm )
590+ lc .set_array (theta )
591+ line = ax .add_collection3d (lc , zs = z )
592+
593+ assert line is not None
594+
595+ ax .set_xlim (- 5 , 5 )
596+ ax .set_ylim (- 4 , 6 )
597+ ax .set_zlim (0 , 2 )
598+
599+
546600@mpl3d_image_comparison (['axes3d_labelpad.png' ], remove_text = False )
547601def test_axes3d_labelpad ():
548602 fig = plt .figure ()
0 commit comments