Add a 3D collection object to the plot. 2D collection types are converted to a 3D version by modifying the object and adding z coordinate information, *zs* and *zdir*. Supported 2D collection types are: - `.PolyCollection` - `.LineCollectio
(self, col, zs=0, zdir='z', autolim=True, *,
axlim_clip=False)
| 3071 | return cset |
| 3072 | |
| 3073 | def add_collection3d(self, col, zs=0, zdir='z', autolim=True, *, |
| 3074 | axlim_clip=False): |
| 3075 | """ |
| 3076 | Add a 3D collection object to the plot. |
| 3077 | |
| 3078 | 2D collection types are converted to a 3D version by |
| 3079 | modifying the object and adding z coordinate information, |
| 3080 | *zs* and *zdir*. |
| 3081 | |
| 3082 | Supported 2D collection types are: |
| 3083 | |
| 3084 | - `.PolyCollection` |
| 3085 | - `.LineCollection` |
| 3086 | - `.PatchCollection` (currently not supporting *autolim*) |
| 3087 | |
| 3088 | Parameters |
| 3089 | ---------- |
| 3090 | col : `.Collection` |
| 3091 | A 2D collection object. |
| 3092 | zs : float or array-like, default: 0 |
| 3093 | The z-positions to be used for the 2D objects. |
| 3094 | zdir : {'x', 'y', 'z'}, default: 'z' |
| 3095 | The direction to use for the z-positions. |
| 3096 | autolim : bool, default: True |
| 3097 | Whether to update the data limits. |
| 3098 | axlim_clip : bool, default: False |
| 3099 | Whether to hide the scatter points outside the axes view limits. |
| 3100 | |
| 3101 | .. versionadded:: 3.10 |
| 3102 | """ |
| 3103 | had_data = self.has_data() |
| 3104 | |
| 3105 | zvals = np.atleast_1d(zs) |
| 3106 | zsortval = (np.min(zvals) if zvals.size |
| 3107 | else 0) # FIXME: arbitrary default |
| 3108 | |
| 3109 | # FIXME: use issubclass() (although, then a 3D collection |
| 3110 | # object would also pass.) Maybe have a collection3d |
| 3111 | # abstract class to test for and exclude? |
| 3112 | if type(col) is mcoll.PolyCollection: |
| 3113 | art3d.poly_collection_2d_to_3d(col, zs=zs, zdir=zdir, |
| 3114 | axlim_clip=axlim_clip) |
| 3115 | col.set_sort_zpos(zsortval) |
| 3116 | elif type(col) is mcoll.LineCollection: |
| 3117 | art3d.line_collection_2d_to_3d(col, zs=zs, zdir=zdir, |
| 3118 | axlim_clip=axlim_clip) |
| 3119 | col.set_sort_zpos(zsortval) |
| 3120 | elif type(col) is mcoll.PatchCollection: |
| 3121 | art3d.patch_collection_2d_to_3d(col, zs=zs, zdir=zdir, |
| 3122 | axlim_clip=axlim_clip) |
| 3123 | col.set_sort_zpos(zsortval) |
| 3124 | |
| 3125 | if autolim: |
| 3126 | if isinstance(col, art3d.Line3DCollection): |
| 3127 | # Handle ragged arrays by extracting coordinates separately |
| 3128 | all_points = np.concatenate(col._segments3d) |
| 3129 | self.auto_scale_xyz(all_points[:, 0], all_points[:, 1], |
| 3130 | all_points[:, 2], had_data=had_data) |