r""" A collection of `~.path.Path`\s, as created by e.g. `~.Axes.scatter`.
| 1125 | |
| 1126 | |
| 1127 | class PathCollection(_CollectionWithSizes): |
| 1128 | r""" |
| 1129 | A collection of `~.path.Path`\s, as created by e.g. `~.Axes.scatter`. |
| 1130 | """ |
| 1131 | |
| 1132 | def __init__(self, paths, sizes=None, **kwargs): |
| 1133 | """ |
| 1134 | Parameters |
| 1135 | ---------- |
| 1136 | paths : list of `.path.Path` |
| 1137 | The paths that will make up the `.Collection`. |
| 1138 | sizes : array-like |
| 1139 | The factor by which to scale each drawn `~.path.Path`. One unit |
| 1140 | squared in the Path's data space is scaled to be ``sizes**2`` |
| 1141 | points when rendered. |
| 1142 | **kwargs |
| 1143 | Forwarded to `.Collection`. |
| 1144 | """ |
| 1145 | |
| 1146 | super().__init__(**kwargs) |
| 1147 | self.set_paths(paths) |
| 1148 | self.set_sizes(sizes) |
| 1149 | self.stale = True |
| 1150 | |
| 1151 | def get_paths(self): |
| 1152 | return self._paths |
| 1153 | |
| 1154 | def legend_elements(self, prop="colors", num="auto", |
| 1155 | fmt=None, func=lambda x: x, **kwargs): |
| 1156 | """ |
| 1157 | Create legend handles and labels for a PathCollection. |
| 1158 | |
| 1159 | Each legend handle is a `.Line2D` representing the Path that was drawn, |
| 1160 | and each label is a string that represents the Path. |
| 1161 | |
| 1162 | This is useful for obtaining a legend for a `~.Axes.scatter` plot; |
| 1163 | e.g.:: |
| 1164 | |
| 1165 | scatter = plt.scatter([1, 2, 3], [4, 5, 6], c=[7, 2, 3], num=None) |
| 1166 | plt.legend(*scatter.legend_elements()) |
| 1167 | |
| 1168 | creates three legend elements, one for each color with the numerical |
| 1169 | values passed to *c* as the labels. |
| 1170 | |
| 1171 | Also see the :ref:`automatedlegendcreation` example. |
| 1172 | |
| 1173 | Parameters |
| 1174 | ---------- |
| 1175 | prop : {"colors", "sizes"}, default: "colors" |
| 1176 | If "colors", the legend handles will show the different colors of |
| 1177 | the collection. If "sizes", the legend will show the different |
| 1178 | sizes. To set both, use *kwargs* to directly edit the `.Line2D` |
| 1179 | properties. |
| 1180 | num : int, None, "auto" (default), array-like, or `~.ticker.Locator` |
| 1181 | Target number of elements to create. |
| 1182 | If None, use all unique elements of the mappable array. If an |
| 1183 | integer, target to use *num* elements in the normed range. |
| 1184 | If *"auto"*, try to determine which option better suits the nature |
no outgoing calls
searching dependent graphs…