plot_utils
Utilities for plotting.
ATTRIBUTE | DESCRIPTION |
---|---|
colors |
list of colors used in plotting |
plt_params |
Plotting parameters to use in plotting functions |
Classes¶
bcolors
dataclass
¶
Functions¶
set_size ¶
set_size(
width: float,
fraction: int = 1,
ratio: float | None = None,
subplots: tuple[int, int] = (1, 1),
) -> tuple[float, float]
Set figure dimensions to avoid scaling in LaTeX.
PARAMETER | DESCRIPTION |
---|---|
width |
Document textwidth or columnwidth in pts
TYPE:
|
fraction |
Fraction of the width which you wish the figure to occupy, by default 1
TYPE:
|
ratio |
Ratio of the height to width of the figure. If None, the golden ratio (sqrt(5)-1)/2 is used, by default None
TYPE:
|
subplots |
The number of rows and columns of subplots in the figure, by default (1, 1) |
RETURNS | DESCRIPTION |
---|---|
fig_dim
|
Dimensions of figure in inches. The dimensions are calculated based on the parameters, and the height is further adjusted based on the number of subplots.
TYPE:
|
Source code in src/ptarcade/plot_utils.py
set_custom_tick_options ¶
set_custom_tick_options(
ax: plt.axis,
left: bool = True,
right: bool = True,
bottom: bool = True,
top: bool = True,
label_size: int = 8,
width: float = 0.5,
length: float = 3.5,
)
Sets custom tick options for a matplotlib axis.
PARAMETER | DESCRIPTION |
---|---|
ax |
The axis to which the tick options will be applied.
TYPE:
|
left |
If True, left ticks will be visible. Default is True.
TYPE:
|
right |
If True, right ticks will be visible. Default is True.
TYPE:
|
bottom |
If True, bottom ticks will be visible. Default is True.
TYPE:
|
top |
If True, top ticks will be visible. Default is True.
TYPE:
|
label_size |
Controls the font size for ticks labels. Default is 8.
TYPE:
|
width |
Sets the width of the ticks. Default is 0.5.
TYPE:
|
length |
Sets the length of the ticks. Default is 3.5.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
|
Source code in src/ptarcade/plot_utils.py
plot_chains ¶
plot_chains(
chain: NDArray,
params: list[str],
params_name: dict[str, str] = None,
label_size: int = 13,
save: bool = False,
model_name: str | None = None,
) -> None
Plot the MCMC (Markov chain Monte Carlo) chain for the parameters specified by params.
PARAMETER | DESCRIPTION |
---|---|
chain |
A numpy array containing the MCMC chain to be plotted. Each row corresponds to a step in the chain, and each column corresponds to a parameter.
TYPE:
|
params |
A list with the names of the parameters appearing in the chain.
TYPE:
|
params_name |
A dictionary with keys being the names of the parameters in the params list to be plotted, and values being the formatted parameters name to be shown in the plots. Default is None, which plots all the common parameters + the MCMC parameters without any formatting.
TYPE:
|
label_size |
Controls the font size for the axis and ticks labels. Default is 13.
TYPE:
|
save |
If set to True, the plot is saved in the folder "./plots/". Default is False.
TYPE:
|
model_name |
A string with the model name. Used to name the output files. Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
|
RAISES | DESCRIPTION |
---|---|
Warning
|
If some of the requested parameters do not appear in the parameter list. |
Source code in src/ptarcade/plot_utils.py
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 |
|
create_ax_labels ¶
Format the axes for posterior plots.
This function fetches the current figure and all its axes, sets custom tick options and labels for all axes according to the names of the parameters.
PARAMETER | DESCRIPTION |
---|---|
par_names |
A list of names of the parameters for each of the axes. |
labelsize |
The font size of the labels. Default is 8. If there is only one parameter, this value is set to 12.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
|
Notes¶
- The function assumes that the number of axes in the current figure matches the number of parameter names provided. If this is not the case, the behavior is undefined.
- A label with the name 'A' and alpha=0 is set for the y-axis in the case of a single parameter to prevent padding issues.
Source code in src/ptarcade/plot_utils.py
level_to_sigma ¶
Convert confidence level to standard deviation (sigma).
This function uses the inverse of the cumulative distribution function (CDF) for a normal distribution to convert a confidence level to the equivalent number of standard deviations (sigma).
PARAMETER | DESCRIPTION |
---|---|
level |
The confidence level to convert. This should be a fraction between 0 and 1.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float
|
The number of standard deviations corresponding to the provided confidence level. |
RAISES | DESCRIPTION |
---|---|
SystemExit
|
If the provided level is not between 0 and 1. |
Source code in src/ptarcade/plot_utils.py
plot_bhb_prior ¶
Plot the prior distribution for SMBHB signal.
PARAMETER | DESCRIPTION |
---|---|
plot |
The plot object to which the priors will be added.
This object should have methods
TYPE:
|
bhb_prior |
The specific BHB prior to be used, choices are "NG15" and "IPTA2".
TYPE:
|
levels |
A list of threshold levels. The sigma equivalent of these levels will be plotted.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
|
Source code in src/ptarcade/plot_utils.py
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 |
|
corner_plot_settings ¶
corner_plot_settings(
levels: list[float] | None,
samples: list[MCSamples],
one_column: bool,
legend_size: int = 12,
fig_width_pt: float | None = None,
) -> plots.GetDistPlotSettings
Configure the settings for corner plots.
PARAMETER | DESCRIPTION |
---|---|
levels |
The list of confidence levels for which the HPI should be computed. Each value in the list should be between 0 and 1. Default is None. |
samples |
A list of instances of the MCSamples class, each containing multivariate Monte Carlo samples on which the function is operating. |
one_column |
Whether to set the figure width for a one-column format. If False, a wider format is used.
TYPE:
|
legend_size |
Sets the font size of the legend captions. Default is 12.
TYPE:
|
fig_width_pt |
If provided, the figure width in points. This parameter can be used to override the default figure widths for one- or two-column formats. Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
GetDistPlotSettings
|
An instance of the GetDistPlotSettings class, with the corner plot settings configured as specified. |
Source code in src/ptarcade/plot_utils.py
oned_plot_settings ¶
Configure the settings for one-dimensional (1D) plots.
PARAMETER | DESCRIPTION |
---|---|
legend_size |
The size for the legend font.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
GetDistPlotSettings
|
An instance of the GetDistPlotSettings class, with the 1D plot settings configured as specified. |
Source code in src/ptarcade/plot_utils.py
plot_k_bounds ¶
plot_k_bounds(
plot: plots.GetDistPlotter.triangle_plot,
samples: list[MCSamples],
k_levels: list[NDArray],
) -> None
Add the k-ratio bounds to an existing plot.
PARAMETER | DESCRIPTION |
---|---|
plot |
The plot to which the k-ratio bounds should be added.
TYPE:
|
samples |
A list of instances of the MCSamples class, each containing multivariate Monte Carlo samples on which the function is operating. |
k_levels |
A list of 1D or 2D arrays representing the K-ratio bounds for each sample. Each array should contain the parameter names and corresponding K-ratio bound.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
|
Source code in src/ptarcade/plot_utils.py
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 |
|
plot_hpi ¶
plot_hpi(
plot: plots.GetDistPlotter.triangle_plot,
samples: list[MCSamples],
hpi_points: list[array_like],
) -> None
Add the highest posterior interval (HPI) to an existing plot.
PARAMETER | DESCRIPTION |
---|---|
plot |
The plot to which the HPI should be added.
TYPE:
|
samples |
A list of instances of the MCSamples class, each containing multivariate Monte Carlo samples on which the function is operating. |
hpi_points |
A list of arrays representing the HPI for each sample. Each array should contain the parameter name and corresponding HPI.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None
|
|
Source code in src/ptarcade/plot_utils.py
print_stats ¶
print_stats(
k_levels: list[array_like],
hpi_points: list[array_like],
bayes_est: list[dict],
max_pos: list[dict],
levels: list[float],
) -> None
Print the statistical summary for each sample.
PARAMETER | DESCRIPTION |
---|---|
k_levels |
A list of arrays representing the K-ratio bounds for each sample. Each array should contain the parameter name and corresponding K-ratio bound.
TYPE:
|
hpi_points |
A list of arrays representing the highest posterior interval (HPI) for each sample. Each array should contain the parameter name and corresponding HPI.
TYPE:
|
bayes_est |
A list of dictionaries, each containing the Bayes estimator for each parameter in the sample. |
max_pos |
A list of dictionaries, each containing the maximum posterior value for each parameter in the sample. |
levels |
The list of confidence levels for which the HPI should be computed. Each value in the list should be between 0 and 1. |
RETURNS | DESCRIPTION |
---|---|
None
|
|
Source code in src/ptarcade/plot_utils.py
plot_posteriors ¶
plot_posteriors(
chains: list[array_like],
params: list[list[str]],
par_to_plot: list[list[str]] | None = None,
par_names: list[list[str]] | None = None,
model_id: list[int] | None = None,
samples_name: list[str] | None = None,
hpi_levels: list[float] = [0.68, 0.95],
k_ratio: list[float] | None = None,
bf: list[float] | None = None,
ranges: dict[str, array_like] = {},
levels: list[float] | None = None,
bhb_prior: str | bool = False,
one_column: bool = False,
fig_width_pt: float | None = None,
labelsize: float = 8,
legend_size: float = 12,
verbose: bool = False,
save: bool = False,
plots_dir: Path | str = "./plots",
model_name: str | None = None,
) -> tuple[matplotlib.figure.Figure, matplotlib.axes.Axes]
Plot posterior distributions for the chosen parameters in the chains.
PARAMETER | DESCRIPTION |
---|---|
chains |
list of array_like's. Contains all the chains to be plotted.
TYPE:
|
params |
list of lists[str]. Contains the name of the parameters appearing in the chains. |
par_to_plot |
list of lists[str]. Contains the parameter to plot from each chain. |
par_names |
Contains the LaTeX formatted names for the plotted parameters of each model. If not specified the name in the par files will be used. |
model_id |
Assuming that the data are generated using hypermodels, specifies the model for which to plot the posteriors (default is None and in this case nmodel is taken to be 0). |
samples_name |
Contains the name of the models associated to each chain, and it's used to create the legend. If not specified, the labels in the legend will be Sample 1, Sample 2, etc. |
hpi_levels |
The list of confidence levels for which the highest posterior interval (HPI) should be computed. Each value in the list should be between 0 and 1. |
k_ratio |
The list of K-ratio bounds for each chain. Each value in the list should be between 0 and 1. |
bf |
Bayes factor for each chain, used to calculate K-ratio bounds. |
ranges |
The parameter ranges to display on the plot. Keys should be parameter names, and values should be tuples or lists specifying the lower and upper bounds of the range.
TYPE:
|
levels |
The list of confidence levels for which the contour should be computed. Each value in the list should be between 0 and 1. |
bhb_prior |
String indicating the bhb prior to plot (possible choiches are NG15 and IPTA2.
TYPE:
|
one_column |
Whether to display the plot in one column format.
TYPE:
|
fig_width_pt |
The width of the figure in points.
TYPE:
|
labelsize |
The fontsize for the labels on the plot.
TYPE:
|
labelsize |
The fontsize for the labels on the plot.
TYPE:
|
verbose |
If set to True, the function will print statistical summaries of the data.
TYPE:
|
save |
If set to True, the function will save the plot to a PDF file.
TYPE:
|
plots_dir |
The directory to save plots in. The directory will be created if needed. |
model_name |
Model name used to name the output files. If not specified the plot will be saved as 'corner.pdf'.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
fig
|
The figure containing the plot.
TYPE:
|
axs
|
The axes of the figure. |
Source code in src/ptarcade/plot_utils.py
745 746 747 748 749 750 751 752 753 754 755 756 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 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 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 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 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 |
|