curvey.curves¤
curves
¤
Sequences of curves
Curves
¤
A container of Curve
s
The constructor accepts an iterator of Curve
s:
Curves
can be iterated over:
Curves
can be indexed with:
-
an int:
curves[i]
returns theCurve
at thei
ith position -
a slice or numpy index-like array:
curves[::2]
returns a newCurves
containing every second curve -
a string:
curves['param']
returns an array of the curve metadata orCurve
attribute associated with eachCurve
in theCurves
-
a function:
curves[fn]
is equivalent toarray([fn(c) for c in curves])
Use Curves.subplots
or Curves.superimposed
to plot every curve in the Curves
at once.
Use Curves.plot
to plot Curve
metadata values against eachother.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
curves |
Iterable[Curve] | None
|
A iterable of |
None
|
Source code in src\curvey\curves.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
|
curves: list[Curve] = []
instance-attribute
¤
The Curve
s contained in this Curves
n: int
property
¤
Number of curves in the sequence
__add__(other: Curves | list[Curve]) -> Curves
¤
Concatenate two Curves
to form a new sequence
Source code in src\curvey\curves.py
__getitem__(idx: str | int | slice | ArrayLike | collections.abc.Callable) -> Curve | Curves | ndarray
¤
Convenience method to index the sequence
Curves[int]
returns the curve stored at that index.
Curves[str]
returns a ndarray
of n
metadata values.
Curves[fn]
for fn: Callable[[Curve], Any]
returns a ndarray
of the values
of that function called on the n
curves in the sequence.
Otherwise, Curves[idx]
returns a new Curves
for that index,
obeying list slicing and numpy smart indexing behavior. E.g. sequence[::3]
returns
a new curve sequence for every third curve in the original sequence.
Source code in src\curvey\curves.py
__iter__() -> Iterator[Curve]
¤
Iterate over curves in the sequence
The index of the curve is stored in the 'idx' metadata parameter.
Use Curves.iter_curves
to supply a custom name for index, if necessary.
Source code in src\curvey\curves.py
__len__() -> int
¤
append(curve: Curve)
¤
get_data(data: BareMetadata, default: Any = nan, allow_default: bool = True, allow_property: bool = True) -> ndarray
¤
Concatenate curve metadata into an array of length n
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
BareMetadata
|
One of:
|
required |
allow_property |
bool
|
If true, |
True
|
allow_default |
bool
|
If true, and the requested data is only available on a subset of curves, return
|
True
|
default |
Any
|
The default value if named parameter |
nan
|
Source code in src\curvey\curves.py
get_named_data(data: BareMetadata | NamedMetadata, **kwargs) -> tuple[str, ndarray]
¤
Get curve metadata (name, values) pairs
If data
is just a name, return (name, values).
If data
is something that can reasonably interpreted as values
,
try to figure out a reasonable name for them.
Source code in src\curvey\curves.py
iter_curves(idx: str = 'idx') -> Iterator[Curve]
¤
Iterate over curves in the sequence
The index of the curve is stored in the idx
metadata parameter. This might be useful for
tracking the original index in a subset.
from curvey import Curves
orig = Curves(Curve.circle(3) for _ in range(6))
every_other = Curves(orig.iter_curves('orig_idx'))[::2]
every_other['orig_idx']
Source code in src\curvey\curves.py
keys(mode: Literal['intersection', 'union'] = 'union') -> set[str]
¤
Unique curve metadata parameter names
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mode |
Literal['intersection', 'union']
|
If 'union', return keys that are present on any |
'union'
|
Source code in src\curvey\curves.py
plot(y: Metadata, x: Metadata | None = None, ax: Axes | None = None, label_axes: bool | None = None, label: str | bool | None = True, **kwargs)
¤
Plot metadata values against each other.
By default, the independent variable y
is 'time', if it's present.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
y |
Metadata
|
The name of the parameter to plot on the y-axis.
Can also be a function |
required |
x |
Metadata | None
|
The name of the parameter to plot on the x-axis, or alternative type as described for
|
None
|
label_axes |
bool | None
|
If true, set x and y labels. Defaults to true if a new axes is created. |
None
|
label |
str | bool | None
|
Name to label the plot with, for use in matplotlib legend. Defaults to the name
of the |
True
|
ax |
Axes | None
|
The matplotlib axes to plot in. Defaults to the current axes. |
None
|
**kwargs |
Remaining kwargs are passed to |
{}
|
Source code in src\curvey\curves.py
subplots(n_rows: int | None = 1, n_cols: int | None = None, axis: str | None = 'scaled', show_axes=False, plot_fn: Callable[[Curve], None] | None = None, subtitle: str | Callable[[Curve], str] | None = None, share_xy=True, figsize: tuple[float, float] = (15, 5), idx: str = 'idx', axs: Sequence[Axes] | None = None, hide_unused: bool = True)
¤
Plot each curve in the sequence in a different subplot
Parameters:
Name | Type | Description | Default |
---|---|---|---|
figsize |
tuple[float, float]
|
The size of the overall superfigure. |
(15, 5)
|
n_rows |
int | None
|
Number of rows. |
1
|
n_cols |
int | None
|
Number of columns. By default, |
None
|
axis |
str | None
|
Argument to |
'scaled'
|
show_axes |
Whether to show each subplot axes, i.e. border and x/y ticks, etc. |
False
|
|
plot_fn |
Callable[[Curve], None] | None
|
By default this just dispatches to |
None
|
subtitle |
str | Callable[[Curve], str] | None
|
A convenience argument to put a title over each subplot. If |
None
|
share_xy |
Whether each subplot should share x/y limits. |
True
|
|
idx |
str
|
The index of the curve in this collection is stored in the curve metadata property with this name. |
'idx'
|
axs |
Sequence[Axes] | None
|
Array of matplotlib axes to use for subplots. If supplied, |
None
|
hide_unused |
bool
|
If n_axs > n_plots, hide the unused axes. |
True
|
Returns:
Name | Type | Description |
---|---|---|
axes |
|
Source code in src\curvey\curves.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
|
superimposed(ax: Axes | None = None, plot_fn: Callable[[Curve], Any] | None = None, color: Metadata | None = None, clim: tuple[float, float] | None = None, idx: str = 'idx') -> list[Any]
¤
Plot every curve in the same axes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ax |
Axes | None
|
Matlplotlib axes to plot in. Default current axes. |
None
|
plot_fn |
Callable[[Curve], Any] | None
|
Function |
None
|
color |
Metadata | None
|
The name of a curve metadata parameter to color by. If |
None
|
clim |
tuple[float, float] | None
|
Range to scale color data to. |
None
|
idx |
str
|
The index of the curve in this collection is stored in this curve's metadata. |
'idx'
|
Returns:
Type | Description |
---|---|
list[Any]
|
List of objects returned by |