The simple.plotting Namespace
The plotting submodule contains everything related to data visualisation.
Matplotlib is used as the foundation for all plotting and this library can be used to further customise the plots here,
for example via the plt object.
simple.plotting.default_colors
module-attribute
default_colors = EndlessList(['#D55E00', '#56B4E9', '#009E73', '#E69F00', '#CC79A7', '#0072B2', '#F0E442'])
An [Endlesslist][simple.plot.EndlessList] containing the default colors used by simple plotting functions.
simple.plotting.default_linestyles
module-attribute
default_linestyles = EndlessList(['-', (0, (4, 4)), (0, (2, 1)), (0, (4, 2, 1, 2)), (0, (4, 2, 1, 1, 1, 2)), (0, (4, 2, 1, 1, 1, 1, 1, 2)), (0, (2, 1, 2, 2, 1, 2)), (0, (2, 1, 2, 2, 1, 1, 1, 2)), (0, (2, 1, 2, 2, 1, 1, 1, 1, 1, 2)), (0, (2, 1, 2, 1, 2, 2, 1, 2)), (0, (2, 1, 2, 1, 2, 2, 1, 1, 1, 2)), (0, (2, 1, 2, 1, 2, 2, 1, 1, 1, 1, 1, 2))])
[Endlesslist][simple.plot.EndlessList] default line styles used by simple plotting functions.
simple.plotting.default_markers
module-attribute
default_markers = EndlessList(['o', 's', '^', 'D', 'P', 'X', 'v', '<', '>', '*', 'p', 'd', 'H'])
[Endlesslist][simple.plot.EndlessList] default marker styles used by simple plotting functions.
simple.plotting.add_weights
add_weights(modeldata, axis, weights=1, *, sum_weights=True, norm_weights=True, default_attrname=None, unit=None, default_value=0, mask=None, mask_na=True, axisname='w')
Add weights to the specified axis of each datapoint in the modeldata dictionary.
This function appends a new array of weights (under axisname) to each datapoint
in modeldata. The weights can be a constant or a string referring to data to be individually
retrieved from each model. Optionally, the weights can be summed, normalized, and masked for missing data.
The 'mask' and 'mask_na' arguments should be the same as those used to generate modeldata to ensure
consistent results.
Parameters:
-
modeldata(dict) –The data dictionary returned from
get_data. It should be a dict of models, each containing a list of datapoint dictionaries. -
axis(str) –The axis in the datapoints that the weights correspond to (e.g., 'x', 'y').
-
weights((int, float, str), default:1) –The weights to add. Can be: - A scalar to apply uniformly, - A string key that will be used to retrieve data from each model individually.
-
sum_weights(bool, default:True) –If True and
weightsis a string consisting of multiple keys, the values for the different keys are summed together and used for each datapoint for a given model. Default is True. -
norm_weights(bool, default:True) –If True, normalise weights along the specified axis. Default is True.
-
default_attrname(str or None, default:None) –Attribute name to use when fetching weights if not included in labels. Optional.
-
unit(str or None, default:None) –Unit to assign to the fetched weight values. Optional.
-
default_value(float, default:0) –Default value to assign if weights are missing. Default is 0.
-
mask(str or None, default:None) –Optional mask to apply to the data when computing or assigning weights.
-
mask_na(bool, default:True) –If True, mask values will be replaced with NaNs. If False, masked values are omitted.
-
axisname(str, default:'w') –The name under which the weight data will be stored in each datapoint. Default is 'w'.
Returns:
-
dict–The modified
modeldata, with weight arrays added to each datapoint.
Raises:
-
ValueError–If the number of weight arrays does not match the number of datapoints and they cannot be broadcast.
Source code in simple/plotting.py
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 | |
simple.plotting.create_legend
create_legend(ax, outside=False, outside_margin=0.01, kwargs=None)
Add a legend to a plot.
Parameters:
-
ax–The working axes. Accepted values are any matplotlib Axes object or plt instance.
-
outside(bool, default:False) –If
Truethe legend will be drawn just outside the upper left corner of the plot. This will overwrite anylocandbbox_to_anchorarguments inkwargs. -
outside_margin–Margin between the plot and the legend. Relative to the width of the plot.
-
**kwargs–Any valid argument for matplotlibs
legendfunction.
Source code in simple/plotting.py
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 | |
simple.plotting.create_rose_plot
create_rose_plot(ax=None, *, xscale=1, yscale=1, segment=None, rres=None)
Create a plot with a rose projection.
The rose ax is a subclass of matplotlibs polar axes.
Parameters:
-
ax–A matplotlib axes object, or an object with a
gca()method (e.g.plt). If the axes does not have a rose projection, it will be destroyed and replaced by a new [RoseAxes][(]simple.roseaxes.RoseAxes]. -
xscale–The scale of the x axis.
-
yscale–The scale of the y axis.
-
segment–Which segment of the rose diagram to show. Options are
N,E,S,W,NE,SE,SW,NWandNone. IfNonethe entire circle is shown. -
rres–The resolution of lines drawn along the radius
r. The number of points in a line is calculated as
Returns:
-
RoseAxes–The new rose ax.
Source code in simple/plotting.py
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 | |
simple.plotting.create_subplots
create_subplots(mosaic, update_fig=True, kwargs=None)
Create a series of subplots.
See matplotlib's documentation for a more thorough description of the mosaic argument and other possible arguments.
Parameters:
-
mosaic–A visual layout of how you want your subplots to be arranged. This can either be a nested list of strings or a single string with each subplot represented by a single character, where
;represent a new row. -
update_fig–If
True(default), the figure will be updated using any kwargs prefixed withfig_. -
kwargs–Keyword arguments to go with the
mosaicargument. Kwargs prefixed withfig_will be used with [update_figure][simple.plot.update_figure] to update the figure.
Returns:
-
dict–A dictionary containing the subplots.
Source code in simple/plotting.py
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 | |
simple.plotting.get_axes
get_axes(axes, projection=None)
Return the axes that should be used for plotting.
Parameters:
-
axes–Must either be
None, in which caseplt.gca()will be returned, a matplotlib axes instance, or any object that has a.gca()method. If subplots have been created using [create_subplots][simple.plot.create_subplots] the name of a subplot can also be given. -
projection–If given, an exception is raised if
axesdoes not have this projection.
Source code in simple/plotting.py
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 | |
simple.plotting.get_data
get_data(models, axis_names, *, where=None, latex_labels=True, key=None, default_attrname=None, unit=None, default_value=np.nan, key_in_label=None, numer_in_label=None, denom_in_label=None, model_in_label=None, unit_in_label=None, attrname_in_label=None, axis_name_in_label=None, label=True, prefix_label=None, suffix_label=None, mask=None, mask_na=True, kwargs=None)
Get one or more datasets from a group of models together with suitable labels.
Each data point is a dictionary that contains a value for each of the axis given in axis_names plus a label describing the data point. The value for each axis is determined by the key argument. This argument has two possible components; the name of the attribute and the index, or key, to be applied this, or the default_attrname, attribute.
The name of the attribute must start with a . followed by the path to the attribute relative to the Model
object using successive . for nested attributes, e.g. .intnorm.eRi.
The index, or key, part of the key can either be an integer, a slice or a sequence of keys seperated by ,.
The keys will be parsed into either Isotope, Ratio, or
Element strings. If a key is given it is assumed that the attribute contains an isotope
key array. Therefore, Element strings will be replaced with all the isotopes of that element
present in the attribute (Across all models) and Ratio strings will return the numerator value divided by the
denominator value.
If the attribute name is given in key then the index, or key, part must be enclosed in square brackets, e.g.
.intnorm.eRi[105Pd]. If the default_attrname should be used then key should only contain the index, or key.
By the default the label for each data point only contains the information is not shared with all other data points. Information that is shared between all data points is instead included in the axis labels.
Parameters:
-
models–A collection of models to plot. A subselection of these models can be made using the where argument.
-
axis_names– -
where(str, default:None) –If given will be used to create a subselection of models. Any kwargs prefixed with
where_will be supplied as keyword arguments. See [ModelCollection.where][(]simple.models.ModelCollection.where] for more details. -
latex_labels(bool, default:True) –Whether to use the latex formatting in the labels, when available.
-
key((str, int, slice), default:None) –This can either be a valid index to the default_attrname array or the path, with or without a valid index, of a different attribute. Accepts either single universal value or a list of values, one for each axis (See below for details).
-
default_attrname–The name of the default attribute to use if xkey and ykey are indexes. By default, the default key array is used. Accepts either single universal value or a list of values, one for each axis (See below for details).
-
unit–The desired unit for the xkey and ykey. Different units for xkey and ykey can be specified by supplying a
(<xkey_unit>, <ykey_unit>)sequence. Accepts either single universal value or a list of values, one for each axis (See below for details). -
default_value–The value given to invalid indexes of arrays. Must have a shape compatible with the size of the indexed array. Accepts either single universal value or a list of values, one for each axis (See below for details).
-
key_in_label(bool, default:None) –Whether to include the key index in the label. Accepts either single universal value or a list of values, one for each axis (See below for details).
-
numer_in_label(bool, default:None) –Whether to include the numerator of a key index in the label. Accepts either single universal value or a list of values, one for each axis (See below for details).
-
denom_in_label(bool, default:None) –Whether to include the denominator of a key index in the label. Accepts either single universal value or a list of values, one for each axis (See below for details).
-
model_in_label(bool, default:None) –Whether to include the model name in the label. Accepts either single universal value or a list of values, one for each axis (See below for details).
-
unit_in_label(bool, default:None) –Whether to include the unit in the label. Accepts either single universal value or a list of values, one for each axis (See below for details).
-
attrname_in_label(bool, default:None) –Whether to include the attribute name in the label. By default the name is only included if it is different from the default_attrname. Accepts a single universal value or a list of values, one for each axis (See below for details).
-
axis_name_in_label(bool, default:None) –Whether to include the axis name in the label. Accepts either single universal value or a value for each axis (See below for details).
-
label((str, bool, None), default:True) –The label for individual datapoints. Accepts either a single universal value or a list of values, one per data point (See below for details).
-
prefix_label–Text to be added to the beginning of each data point label. Accepts either a single universal value or a list of values, one per data point (See below for details).
-
suffix_label–Text to be added at the end of each data point label. Accepts either a single universal value or a list of values, one per data point (See below for details).
-
mask((str, int, slice), default:None) –Can be used to apply a mask to the data which is plotted. See the
get_maskfunction of the Model object. Accepts either a single universal value or a list of values, one per model (See below for details). -
mask_na(bool, default:True) –If
Truemasked values will be replaced bynp.nanvalues. Only works if all arrays in a dataset have a float based datatype. Accepts either a single universal value or a list of values, one per model (See below for details). -
**kwargs–
One per axis arguments
These arguments allow you to set a different value for each axis in axis_names. This can be either a single value used for all the axis or a sequence of values, one per axis.
It is also possible to define the value for a specific axis by including a keyword argument consiting
of the axis name followed directly by the argument name. The value specified this way will take presidence over
the value given by the argument itself. For example xkey=102Pd will set the key argument for
the x axis to 102Pd.
One per data point arguments
These arguments allow you to set a different value for each data point. The number of data points is equal to the number of models multiplied by the number of datasets generated. This can be either a single value used for all the axis or a sequence of values, one per data point.
One per model arguments
These arguments allow you to set a different value for each model in models. This can be either a single value used for all the axis or a sequence of values, one per model.
Returns:
-
–
Tuple[dict, dict]: Two dictionaries containing:
-
A dictionary with the data points for each model, mapped to the model name
-
A dictionary containing labels for each axis, mapped to the axis name.
-
Examples:
Here is an example of how the return data can be used.
model_datapoints, axis_labels = simple.get_data(models, 'x, y', xkey=..., ykey=...)
# Set the axis labels
plt.set_xlabel(axis_labels['x'])
plt.set_ylabel(axis_labels['y'])
# Iterate though the data and plot it
for model_name, datapoints in model_datapoints.items():
for dp in datapoints:
plt.plot(dp['x'], dp['y'], label=dp['label'])
Source code in simple/plotting.py
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 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 | |
simple.plotting.get_models
get_models(models, where=None, **where_kwargs)
Return a selection of models.
If models is a ModelCollection a new ModelCollection will be returned. Otherwise a list of Models will be returned.
Parameters:
-
models–A collection of models or a list/tuple of models.
-
where(str, default:None) –Only models fitting this criteria will be selected. If not given all models are selected.
-
**where_kwargs–Keyword arguments to go with the
wherestring.
Source code in simple/plotting.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
simple.plotting.hist
hist(models, xkey=None, ykey=None, weights=1, r=None, *, sum_weights=True, norm_weights=True, bins=True, fill=None, rescale=False, default_attrname=None, unit=None, weights_default_attrname=None, weights_unit=None, weights_default_value=0, where=None, mask=None, mask_na=True, ax=None, legend=None, update_ax=True, update_fig=True, kwargs=None)
Make a traditional histogram of xkey or ykey, or a circular histogram for the slope of ykey/xkey on axis, for each model in models.
This function retrieves data using get_data and plots it using matplotlib
plot for 1d histograms and
SIMPLE's RoseAxes.mhist for 2d histograms. It supports
optional filtering, masking, and per-model or per-dataset styling. Additional arguments can be passed using
keyword prefixes to control axes, figure appearance, legends, and more.
This function is split into two stages: hist_get_data and
[hist_draw][simple.plotting.hist_draw], which can be used independently.
Parameters:
-
models(ModelCollection) –A collection of models to plot. A subset can be selected using the where argument.
-
xkey, ykey(str, int, or slice) –Keys or indices used to retrieve the x and y data arrays. These may refer to array indices (relative to default_attrname) or full attribute paths. See
get_datafor more information. If only xkey or ykey is specified then a traditional histogram is drawn. If both are specified, then a circular histogram of the slopes is drawn. -
weights(float or str, default:1) –Weighting factor for the histogram. See
add_weightsfor details. -
r(float, default:None) –Radius of the circular histogram. If None, the radius is automatically determined. A sequence of values can be passed, one for each dataset.
-
sum_weights(bool, default:True) –Whether to sum the weights if multiple weight datasets are present. See
add_weightsfor details. -
norm_weights(bool, default:True) –Whether to normalise the weights to sum to 1. See
add_weightsfor details. -
default_attrname(str, default:None) –Name of the default attribute used when xkey or ykey is an index.
-
unit(str or tuple, default:None) –Desired unit(s) for the x and y axes. Use a tuple
(xunit, yunit)for different units. -
where(str, default:None) –Filter expression to select a subset of models. See
ModelCollection.where. -
mask(str, int, or slice, default:None) –Optional mask to apply to the data. See the
get_maskmethod on model instances. -
mask_na(bool, default:True) –If True, masked values are replaced with
np.nan. Only applies if xkey and ykey are float-based. -
ax(Axes or None, default:None) –The axes to plot on. If None, defaults to
plt.gca(). -
legend(bool, default:None) –Whether to add a legend. If
None, a legend is shown if at least one datapoint has a label. Legend made usingcreate_legend. -
update_ax, update_fig(bool) –Whether to apply
ax_<keyword>andfig_<keyword>arguments usingupdate_axes. -
kwargs(dict, default:None) –Keyword arguments can be provided either explicitly via
kwargsor implicitly via**kwargs. If the same keyword is provided in both, the value in kwargs takes precedence. A description of accepted keywords is provided below.
Accepted keyword arguments
Direct keywords:
- Any keyword accepted by simple.get_data().
- color: Can be a list of colours, True for defaults, or False to use black.
- linestyle: Can be a list of styles, True for defaults, or False to disable lines.
- color_by_model, linestyle_by_model: If True every dataset for each model will be
plotted with the same colour/linestyle value. If False, the corresponding datasets for each model
will be plotted with the same value. If None the default behaviour is used.
Prefixed keywords:
- plt_<keyword>: Keywords passed to the primary plotting function, axline.
- where_<keyword>: Keywords passed to the model filtering function, ModelCollection.where.
- weights_<keyword>: Keywords passed to add_weights.
- ax_<keyword>: Keywords passed to update_axes.
- fig_<keyword>: Keywords passed to [update_fig][simple.plotting.update_fig].
- legend_<keyword>: Keywords passed to create_legend.
- histogram_<keyword>: Keywords for numpys
histogram function. Only
used for 1-d histograms.
- rose_<keyword>: Keywords passed to [create_rose_plot][simple.roseaxes.create_rose_plot]. Only used
for 2-d histograms (and only if the figure is not already a RoseAxes instance).
Axis and data labels
Axis labels are automatically inferred based on shared and unique elements in the data. You can override them
using ax_xlabel and ax_ylabel in kwargs. Datapoint labels can be overridden with a list of labels
(one per line in the legend).
Shortcuts and default values
This function includes shortcut variants with predefined default values:
plot.intnorm: setsdefault_attrname="intnorm.eRi"andunit=Noneplot.stdnorm: setsdefault_attrname="stdnorm.Ri"andunit=Noneplot.abundance: setsdefault_attrname="abundance"andunit=None
Default argument values can also be updated through plot.update_kwargs(). Values defined in the function
signature are used only if not overridden there. You can retrieve the default arguments using plot.kwargs
Returns:
-
–
matplotlib.axes.Axes: The axes object used for plotting.
Source code in simple/plotting.py
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 | |
simple.plotting.hist_draw1d
hist_draw1d(modeldata, axis_labels, axis, *, bins=20, fill=None, rescale=False, ax=None, legend=None, update_ax=True, update_fig=True, kwargs=None)
Render the standard histogram using matplotlib.
This function handles the styling, axes setup, and drawing logic of hist. See the
documentation of this function for a description of the arguments.
Returns:
-
–
matplotlib Axes: The axes on which the data was plotted.
Source code in simple/plotting.py
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 | |
simple.plotting.hist_draw2d
hist_draw2d(modeldata, axis_labels, r=None, *, bins=72, fill=None, rescale=False, ax=None, legend=None, update_ax=True, update_fig=True, kwargs=None)
Render a circular histogram using on a Rose Axes.
This function handles the styling, axes setup, and drawing logic of hist. See the
documentation of this function for a description of the arguments.
Returns:
-
–
matplotlib Axes: The axes on which the data was plotted.
Source code in simple/plotting.py
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 | |
simple.plotting.hist_get_data
hist_get_data(models, xkey, ykey, weights=1, *, sum_weights=True, norm_weights=True, default_attrname=None, unit=None, where=None, mask=None, mask_na=True, kwargs=None)
Retrieve model data and axis labels for plotting.
This function performs the data preparation step of hist. See the documentation of this
function for a description of the arguments.
Returns:
-
tuple–- modeldata (dict): Structured data for plotting.
- axis_labels (dict): Suggested axis labels.
- axis (str): Axis to plot on.
xoryfor 1d histograms,xyfor 2d histograms.
Source code in simple/plotting.py
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 | |
simple.plotting.parse_lscm
parse_lscm(linestyle=False, color=False, marker=False)
Convert the linestyle, color and marker arguments into [EndlessList][simple.plot.EndlessList]
objects for plotting.
Parameters:
-
linestyle–Either a single line style or a list of line styles. If
Truethen the [default line styles][simple.plot.default_linestyles] is returned. IfFalseorNonea list containing only the no line sentinel is returned. -
color–Single colour or a list of colours. If
Truethen the [default colors][simple.plot.default_colors] is returned. IfFalseorNonea list containing only the color black is returned. -
marker–Either a marker shape or a list of marker shapes. If
Truethen the [default marker shapes][simple.plot.default_markers] shapes is returned. IfFalseorNonea list containing only the no marker sentinel is returned.
Returns:
-
(EndlessList, EndlessList, EndlessList)–linestyles, colors, markers
Source code in simple/plotting.py
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 | |
simple.plotting.plot
plot(models, xkey, ykey, *, default_attrname=None, unit=None, where=None, mask=None, mask_na=True, ax=None, legend=None, update_ax=True, update_fig=True, hist=False, hist_size=0.3, hist_pad=0.05, kwargs=None)
Plot xkey against ykey for each model in models.
This function retrieves data using get_data and plots it using matplotlib. It supports
optional filtering, masking, and per-model or per-dataset styling. Additional arguments can be passed using
keyword prefixes to control axes, figure appearance, legends, and more.
This function is split into two stages: plot_get_data and
plot_draw, which can be used independently.
Parameters:
-
models(ModelCollection) –A collection of models to plot. A subset can be selected using the where argument.
-
xkey, ykey(str, int, or slice) –Keys or indices used to retrieve the x and y data arrays. These may refer to array indices (relative to default_attrname) or full attribute paths. See
get_datafor more. -
default_attrname(str, default:None) –Name of the default attribute used when xkey or ykey is an index.
-
unit(str or tuple, default:None) –Desired unit(s) for the x and y axes. Use a tuple
(xunit, yunit)for different units. where (str): Filter expression to select a subset of models. SeeModelCollection.where. -
mask(str, int, or slice, default:None) –Optional mask to apply to the data. See the
get_maskmethod on model instances. -
mask_na(bool, default:True) –If True, masked values are replaced with
np.nan. Only applies if xkey and ykey are float-based. -
ax(Axes or None, default:None) –The axes to plot on. If None, defaults to
plt.gca(). -
legend(bool, default:None) –Whether to add a legend. If
None, a legend is shown if at least one datapoint has a label. Legend made usingcreate_legend. -
update_ax, update_fig(bool) –Whether to apply
ax_<keyword>andfig_<keyword>arguments usingupdate_axes. -
hist(bool, default:False) –Whether to show marginal histograms along the axis.
-
hist_size(float, default:0.3) –Relative size of the histogram axes.
-
hist_pad(float, default:0.05) –Padding between the main plot and histogram axes.
-
kwargs(dict, default:None) –Keyword arguments can be provided either explicitly via
kwargsor implicitly via**kwargs. If the same keyword is provided in both, the value in kwargs takes precedence. A description of accepted keywords is provided below. -
Accepted keyword arguments–Direct keywords: - Any keyword accepted by
simple.get_data. -color: Can be a list of colours,Truefor defaults, orFalseto use black. -linestyle: Can be a list of styles,Truefor defaults, orFalseto disable lines. -marker: Can be a list of markers,Truefor defaults, orFalseto disable markers. -color_by_model,linestyle_by_model,marker_by_model: IfTrueevery dataset for each model will be plotted with the same colour/linestyle/maker value. IfFalse, the corresponding datasets for each model will be plotted with the same value. IfNonethe default behaviour is used. -yhist,xhist: IfTrue, show a histogram along the specified axis. Takes precedence over `hist'.Prefixed keywords: -
plt_<keyword>: Keywords passed to the primary plotting function,axline. -where_<keyword>: Keywords passed to the model filtering function,ModelCollection.where. -ax_<keyword>: Keywords passed toupdate_axes. -fig_<keyword>: Keywords passed to [update_fig][simple.plotting.update_fig]. -legend_<keyword>: Keywords passed tocreate_legend. -hist_<keyword>: Default keywords forxhist_<keyword>andyhist_<keyword>. -xhist_<keyword>: Keywords passed to [axhist][simple.plotting.axhist] for the x axis. -yhist_<keyword>: Keywords passed to [axhist][simple.plotting.axhist] for the y axis.
Axis and data labels
Axis labels are automatically inferred based on shared and unique elements in the data. You can override them
using ax_xlabel and ax_ylabel in kwargs. Datapoint labels can be overridden with a list of labels
(one per line in the legend).
Shortcuts and default values
This function includes shortcut variants with predefined argument:
plot.intnorm: setsdefault_attrname="intnorm.eRi"andunit=Noneplot.stdnorm: setsdefault_attrname="stdnorm.Ri"andunit=Noneplot.abundance: setsdefault_attrname="abundance"andunit=None
Default argument values can also be updated through plot.update_kwargs(). Values defined in the function
signature are used only if not overridden there. You can retrieve the default arguments using plot.kwargs
Returns:
-
–
matplotlib.axes.Axes: The axes object used for plotting.
Source code in simple/plotting.py
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
simple.plotting.plot_draw
plot_draw(modeldata, axis_labels, *, ax=None, legend=None, update_ax=True, update_fig=True, hist=False, hist_size=0.3, hist_pad=0.05, kwargs=None)
Render the plot using matplotlib.
This function handles the styling, axes setup, and drawing logic of plot. See the
documentation of this function for a description of the arguments.
Returns:
-
–
matplotlib Axes: The axes on which the data was plotted.
Source code in simple/plotting.py
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 | |
simple.plotting.plot_get_data
plot_get_data(models, xkey, ykey, *, default_attrname=None, unit=None, where=None, mask=None, mask_na=True, kwargs=None)
Retrieve model data and axis labels for plotting.
This function performs the data preparation step of plot. See the documentation of this
function for a description of the arguments.
Returns:
-
tuple–- modeldata (dict): Structured data for plotting.
- axis_labels (dict): Suggested axis labels.
Source code in simple/plotting.py
1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 | |
simple.plotting.slope
slope(models, xkey, ykey, xycoord=(0, 0), *, arrow=True, arrow_position=0.9, default_attrname=None, unit=None, where=None, mask=None, mask_na=True, ax=None, legend=None, update_ax=True, update_fig=True, kwargs=None)
Plot the slope of ykey/xkey for each model in models.
This function retrieves data using get_data and plots it using matplotlib
axline. It supports
optional filtering, masking, and per-model or per-dataset styling. Additional arguments can be passed using
keyword prefixes to control axes, figure appearance, legends, and more.
This function is split into two stages: slope_get_data and
slope_draw, which can be used independently.
Parameters:
-
models(ModelCollection) –A collection of models to plot. A subset can be selected using the where argument.
-
xkey, ykey(str, int, or slice) –Keys or indices used to retrieve the x and y data arrays. These may refer to array indices (relative to default_attrname) or full attribute paths. See
get_datafor more information. -
xycoord(tuple, default:(0, 0)) –Coordinates to a point the slope passes through. Defaults to
(0, 0). -
arrow(bool, default:True) –Whether to draw arrows indicating the direction of the endmember given by the x and y coordinates.
-
arrow_position(float, default:0.9) –Relative position of the arrow on the line. Defaults to 0.9.
-
default_attrname(str, default:None) –Name of the default attribute used when xkey or ykey is an index.
-
unit(str or tuple, default:None) –Desired unit(s) for the x and y axes. Use a tuple
(xunit, yunit)for different units. -
where(str, default:None) –Filter expression to select a subset of models. See
ModelCollection.where. -
mask(str, int, or slice, default:None) –Optional mask to apply to the data. See the
get_maskmethod on model instances. -
mask_na(bool, default:True) –If True, masked values are replaced with
np.nan. Only applies if xkey and ykey are float-based. -
ax(Axes or None, default:None) –The axes to plot on. If None, defaults to
plt.gca(). -
legend(bool, default:None) –Whether to add a legend. If
None, a legend is shown if at least one datapoint has a label. Legend made usingcreate_legend. -
update_ax, update_fig(bool) –Whether to apply
ax_<keyword>andfig_<keyword>arguments usingupdate_axes. -
kwargs(dict, default:None) –Keyword arguments can be provided either explicitly via
kwargsor implicitly via**kwargs. If the same keyword is provided in both, the value in kwargs takes precedence. A description of accepted keywords is provided below.
Accepted keyword arguments
Direct keywords:
- Any keyword accepted by simple.get_data.
- color: Can be a list of colours, True for defaults, or False to use black.
- linestyle: Can be a list of styles, True for defaults, or False to disable lines.
- color_by_model, linestyle_by_model: If True every dataset for each model will be
plotted with the same colour/linestyle value. If False, the corresponding datasets for each model
will be plotted with the same value. If None the default behaviour is used.
Prefixed keywords:
- plt_<keyword>: Keywords passed to the primary plotting function, axline.
- where_<keyword>: Keywords passed to the model filtering function, ModelCollection.where.
- ax_<keyword>: Keywords passed to update_axes.
- fig_<keyword>: Keywords passed to [update_fig][simple.plotting.update_fig].
- legend_<keyword>: Keywords passed to create_legend.
- arrow_<keyword>: Keywords passed to matplotlib.axes.Axes.arrow.
Axis and data labels
Axis labels are automatically inferred based on shared and unique elements in the data. You can override them
using ax_xlabel and ax_ylabel in kwargs. Datapoint labels can be overridden with a list of labels
(one per line in the legend).
Shortcuts and default values
This function includes shortcut variants with predefined argument:
slope.intnorm: setsdefault_attrname="intnorm.eRi"andunit=Noneslope.stdnorm: setsdefault_attrname="stdnorm.Ri"andunit=Noneslope.abundance: setsdefault_attrname="abundance"andunit=None
Default argument values can also be updated through slope.update_kwargs(). Values defined in the function
signature are used only if not overridden there. You can retrieve the default arguments using slope.kwargs.
Returns:
-
–
matplotlib.axes.Axes: The axes object used for plotting.
Source code in simple/plotting.py
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 | |
simple.plotting.slope_draw
slope_draw(modeldata, axis_labels, xycoord=(0, 0), *, arrow=True, arrow_position=0.9, ax=None, legend=None, update_ax=True, update_fig=True, kwargs=None)
Render the plot using matplotlib.
This function handles the styling, axes setup, and drawing logic of [slope][simple.plotting.s;p[e]. See the
documentation of this function for a description of the arguments.
Returns:
-
–
matplotlib Axes: The axes on which the data was plotted.
Source code in simple/plotting.py
1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 | |
simple.plotting.slope_get_data
slope_get_data(models, xkey, ykey, *, default_attrname=None, unit=None, where=None, mask=None, mask_na=True, kwargs=None)
Retrieve model data and axis labels for plotting.
This function performs the data preparation step of slope. See the documentation of this
function for a description of the arguments.
Returns:
-
tuple–- modeldata (dict): Structured data for plotting.
- axis_labels (dict): Suggested axis labels.
Source code in simple/plotting.py
1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 | |
simple.plotting.update_axes
update_axes(ax, kwargs, *, update_ax=True, update_fig=True)
Updates the axes and figure objects.
Keywords beginning with ax_<name>, xax_<name>, yax_<name> and fig_<name> will be stripped
from kwargs. These will then be used to call the set_<name> or <name> method of the axes, axis or
figure object.
If the value mapped to the above arguments is:
- A bool it is used to determine whether to call the method. The boolean itself will not be passed to
the method.
- A tuple then the contents of the tuple is unpacked and used as arguments for the method call.
- A dict then the contents of the dictionary is unpacked and used as keyword arguments for the method call.
- Any other type of value will be passed as the first argument to the method call. To pass one of the above types
as a single argument use a tuple, e.g. (True, ).
Additional keyword arguments can be passed to methods by mapping e.g. <ax|xax|yax|fig>_kw_<name>_<keyword>
kwargs to the value. These additional keyword arguments are only used if the
<ax|xax|yax|fig>_<name> kwargs exists.
The figure will not be updated if ax is a subplot created by simple.create_subplots.
Source code in simple/plotting.py
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 | |
simple.plotting.update_figure
update_figure(fig, kwargs, *, update_fig=True)
Updates the figure object only. See update_axes for more details.
Source code in simple/plotting.py
981 982 983 984 985 986 987 988 989 990 991 992 | |