(
frame: DataFrame,
class_column,
ax: Axes | None = None,
samples: int = 200,
color=None,
colormap=None,
**kwds,
)
| 221 | |
| 222 | |
| 223 | def andrews_curves( |
| 224 | frame: DataFrame, |
| 225 | class_column, |
| 226 | ax: Axes | None = None, |
| 227 | samples: int = 200, |
| 228 | color=None, |
| 229 | colormap=None, |
| 230 | **kwds, |
| 231 | ) -> Axes: |
| 232 | import matplotlib.pyplot as plt |
| 233 | |
| 234 | def function(amplitudes): |
| 235 | def f(t): |
| 236 | x1 = amplitudes[0] |
| 237 | result = x1 / np.sqrt(2.0) |
| 238 | |
| 239 | # Take the rest of the coefficients and resize them |
| 240 | # appropriately. Take a copy of amplitudes as otherwise numpy |
| 241 | # deletes the element from amplitudes itself. |
| 242 | coeffs = np.delete(np.copy(amplitudes), 0) |
| 243 | coeffs = np.resize(coeffs, (int((coeffs.size + 1) / 2), 2)) |
| 244 | |
| 245 | # Generate the harmonics and arguments for the sin and cos |
| 246 | # functions. |
| 247 | harmonics = np.arange(0, coeffs.shape[0]) + 1 |
| 248 | trig_args = np.outer(harmonics, t) |
| 249 | |
| 250 | result += np.sum( |
| 251 | coeffs[:, 0, np.newaxis] * np.sin(trig_args) |
| 252 | + coeffs[:, 1, np.newaxis] * np.cos(trig_args), |
| 253 | axis=0, |
| 254 | ) |
| 255 | return result |
| 256 | |
| 257 | return f |
| 258 | |
| 259 | n = len(frame) |
| 260 | class_col = frame[class_column] |
| 261 | classes = frame[class_column].drop_duplicates() |
| 262 | df = frame.drop(class_column, axis=1) |
| 263 | t = np.linspace(-np.pi, np.pi, samples) |
| 264 | used_legends: set[str] = set() |
| 265 | |
| 266 | color_values = get_standard_colors( |
| 267 | num_colors=len(classes), colormap=colormap, color_type="random", color=color |
| 268 | ) |
| 269 | colors = dict(zip(classes, color_values, strict=False)) |
| 270 | if ax is None: |
| 271 | ax = plt.gca() |
| 272 | ax.set_xlim(-np.pi, np.pi) |
| 273 | for i in range(n): |
| 274 | row = df.iloc[i].values |
| 275 | f = function(row) |
| 276 | y = f(t) |
| 277 | kls = class_col.iat[i] |
| 278 | label = pprint_thing(kls) |
| 279 | if label not in used_legends: |
| 280 | used_legends.add(label) |
nothing calls this directly
no test coverage detected