Plot Base
puma.plot_base.PlotLineObject
dataclass
#
Base data class defining properties of a plot object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xmin
|
float
|
Minimum value of the x-axis, by default None |
None
|
xmax
|
float
|
Maximum value of the x-axis, by default None |
None
|
colour
|
str
|
Colour of the object, by default None |
None
|
label
|
str
|
Label of object, by default None |
None
|
linestyle
|
str
|
Linestyle following numpy style, by default None |
None
|
alpha
|
float
|
Value for visibility of the plot lines, by default None |
None
|
marker
|
str
|
Marker that is used in the plot. For example an x. By default None |
None
|
markersize
|
int
|
Size of the marker. By default None |
None
|
markeredgewidth
|
int
|
Edge width of the marker. By default None |
None
|
is_marker
|
bool
|
Bool, to give info about if this is a marker or a line. By default None |
None
|
args_to_store
property
#
Returns the arguments that need to be stored/loaded.
Returns:
Type | Description |
---|---|
dict[str, typing.Any]
|
Dict with the arguments |
decode
staticmethod
#
Inverse of encode, turning tags back into real objects.
Source code in puma/plot_base.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
encode
staticmethod
#
Return a JSON/YAML-safe version of obj, tagging special types.
Source code in puma/plot_base.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
load
classmethod
#
Load the needed attributes for the class from file and init.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str | pathlib.Path
|
Path in which the attributes are stored. |
required |
Returns:
Type | Description |
---|---|
Class Instance
|
Instance of class with the given attributes. |
Raises:
Type | Description |
---|---|
ValueError
|
If the given file is neither json nor a yaml file. |
Source code in puma/plot_base.py
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 |
|
save
#
Store class attributes in a file.
Saving can be performed to a yaml and a json file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str | pathlib.Path
|
Path to which the class object attributes are written. |
required |
Source code in puma/plot_base.py
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 |
|
puma.plot_base.PlotObject
dataclass
#
Data base class defining properties of a plot object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title
|
str
|
Title of the plot, by default "" |
''
|
draw_errors
|
bool
|
Draw statistical uncertainty on the lines, by default True |
True
|
xmin
|
float
|
Minimum value of the x-axis, by default None |
None
|
xmax
|
float
|
Maximum value of the x-axis, by default None |
None
|
ymin
|
float
|
Minimum value of the y-axis, by default None |
None
|
ymax
|
float
|
Maximum value of the y-axis, by default None |
None
|
ymin_ratio
|
list
|
Set the lower y limit of each of the ratio subplots, by default None. |
None
|
ymax_ratio
|
list
|
Set the upper y limit of each of the ratio subplots, by default None. |
None
|
y_scale
|
float
|
Scaling up the y axis, e.g. to fit the ATLAS Tag. Applied if ymax not defined, by default 1.3 |
1.3
|
logx
|
bool
|
Set the log of x-axis, by default False |
False
|
logy
|
bool
|
Set log of y-axis of main panel, by default True |
True
|
xlabel
|
str
|
Label of the x-axis, by default None |
None
|
ylabel
|
str
|
Label of the y-axis, by default None |
None
|
ylabel_ratio
|
list
|
List of labels for the y-axis in the ratio plots, by default "Ratio" |
None
|
label_fontsize
|
int
|
Used fontsize in label, by default 12 |
12
|
fontsize
|
int
|
Used fontsize, by default 10 |
10
|
n_ratio_panels
|
int
|
Amount of ratio panels between 0 and 2, by default 0 |
0
|
vertical_split
|
bool
|
Set to False if you would like to split the figure horizonally. If set to True the figure is split vertically (e.g for pie chart). By default False. |
False
|
figsize
|
(float, float)
|
Tuple of figure size |
None
|
dpi
|
int
|
DPI used for plotting, by default 400 |
400
|
transparent
|
bool
|
Specify if the background of the plot should be transparent, by default False |
False
|
grid
|
bool
|
Set the grid for the plots. |
True
|
figure_layout
|
str
|
Set the layout that is used for the plot. By default "constrained" |
'constrained'
|
leg_fontsize
|
int
|
Fontsize of the legend, by default 10 |
None
|
leg_loc
|
str
|
Position of the legend in the plot, by default "upper right" |
'upper right'
|
leg_ncol
|
int
|
Number of legend columns, by default 1 |
1
|
leg_linestyle_loc
|
str
|
Position of the linestyle legend in the plot, by default "upper center" |
'upper center'
|
apply_atlas_style
|
bool
|
Apply ATLAS style for matplotlib, by default True |
True
|
use_atlas_tag
|
bool
|
Use the ATLAS Tag in the plots, by default True |
True
|
atlas_first_tag
|
str
|
First row of the ATLAS tag (i.e. the first row is "ATLAS |
'Simulation Internal'
|
atlas_second_tag
|
str
|
Second row of the ATLAS tag, by default "" |
None
|
atlas_fontsize
|
float
|
Fontsize of ATLAS label, by default 10 |
None
|
atlas_vertical_offset
|
float
|
Vertical offset of the ATLAS tag, by default 7 |
7
|
atlas_horizontal_offset
|
float
|
Horizontal offset of the ATLAS tag, by default 8 |
8
|
atlas_brand
|
str
|
|
'ATLAS'
|
atlas_tag_outside
|
bool
|
|
False
|
atlas_second_tag_distance
|
float
|
Distance between the |
0
|
plotting_done
|
bool
|
Bool that indicates if plotting is done. Only then |
False
|
__check_figsize
#
Check figsize
.
Raises:
Type | Description |
---|---|
ValueError
|
If shape of |
Source code in puma/plot_base.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
|
__check_yratio
#
Check yratio
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
yratio
|
list
|
List of min or max limits of ratio plots |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Source code in puma/plot_base.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
|
__post_init__
#
Check for allowed values.
Raises:
Type | Description |
---|---|
ValueError
|
If n_ratio_panels not in [0, 1, 2, 3] |
Source code in puma/plot_base.py
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 |
|
puma.plot_base.PlotBase
#
Bases: puma.plot_base.PlotObject
Base class for plotting.
Initialise class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
puma.plot_base.PlotBase(kwargs)
|
Keyword arguments from |
{}
|
Source code in puma/plot_base.py
444 445 446 447 448 449 450 451 452 453 454 455 456 |
|
atlasify
#
Apply ATLAS style to all axes using the atlasify package.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
Force ATLAS style also if class variable is False, by default False |
False
|
Source code in puma/plot_base.py
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 |
|
close_window
#
Properly close the Tkinter window and exit the main loop.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
tkinter.Tk
|
The Tkinter root window instance to be closed. |
required |
Source code in puma/plot_base.py
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 |
|
draw_vlines
#
Drawing working points in plot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xs
|
list
|
List of working points x values to draw |
required |
labels
|
list
|
List with labels for the vertical lines. Must be the same order as the xs. If None, the xvalues * 100 will be used as labels. By default None |
None
|
ys
|
list
|
List with the y height of the vertical lines in percent of the upper plot (0 is bottom, 1 is top). Must be the same order as the xs and the labels. By default None |
None
|
same_height
|
bool
|
Working point lines on same height, by default False |
False
|
colour
|
str
|
Colour of the vertical line, by default "#000000" (black) |
'#000000'
|
linestyle
|
str
|
Linestyle of the vertical line, by default "dashed" |
'dashed'
|
fontsize
|
int
|
Fontsize of the vertical line text. By default 10. |
10
|
Source code in puma/plot_base.py
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 |
|
initialise_figure
#
Initialising matplotlib.figure.Figure for different scenarios depending on how many ratio panels are requested.
Source code in puma/plot_base.py
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 |
|
is_running_in_jupyter
#
Detect if running inside a Jupyter notebook.
Source code in puma/plot_base.py
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 |
|
make_legend
#
Drawing legend on axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handles
|
list
|
List of matplotlib.lines.Line2D object returned when plotting |
required |
ax_mpl
|
matplotlib.axis.Axes
|
|
required |
labels
|
list
|
Plot labels. If None, the labels are extracted from the |
None
|
**kwargs
|
kwargs
|
Keyword arguments which can be passed to matplotlib axis |
{}
|
Source code in puma/plot_base.py
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 |
|
make_linestyle_legend
#
Create a legend to indicate what different linestyles correspond to.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
linestyles
|
list
|
List of the linestyles to draw in the legend |
required |
labels
|
list
|
List of the corresponding labels. Has to be in the same order as the linestyles |
required |
loc
|
str
|
Location of the legend (matplotlib supported locations), by default None |
None
|
bbox_to_anchor
|
tuple
|
Allows to specify the precise position of this legend. Either a 2-tuple (x, y) or a 4-tuple (x, y, width, height), by default None |
None
|
axis_for_legend
|
matplotlib.Axes.axis
|
Axis on which to draw the legend, by default None |
None
|
Source code in puma/plot_base.py
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 |
|
savefig
#
Save plot to disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plot_name
|
str
|
File name of the plot |
required |
transparent
|
bool
|
Specify if plot background is transparent, by default False |
None
|
dpi
|
int
|
DPI for plotting, by default 400 |
None
|
**kwargs
|
kwargs
|
Keyword arguments passed to |
{}
|
Source code in puma/plot_base.py
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 |
|
set_log
#
Set log scale of the axes.
For the y-axis, only the main panel is set. For the x-axes also set the ratio panels.
Source code in puma/plot_base.py
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 |
|
set_ratio_label
#
Associate the rejection class to a ratio panel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ratio_panel
|
int
|
Index of the ratio panel to label. |
required |
label
|
str
|
y-axis label of the ratio panel. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the requested ratio panel does not exist. |
Source code in puma/plot_base.py
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 |
|
set_tick_params
#
Set x-axis label.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
labelsize
|
int
|
Label size of x- and y- axis ticks, by default None. If None then using global fontsize |
None
|
**kwargs
|
kwargs
|
Keyword arguments passed to |
{}
|
Source code in puma/plot_base.py
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 |
|
set_title
#
Set title of top panel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title
|
str
|
Title of top panel, if None using the value form the class variables, by default None |
None
|
**kwargs
|
kwargs
|
Keyword arguments passed to |
{}
|
Source code in puma/plot_base.py
579 580 581 582 583 584 585 586 587 588 589 590 |
|
set_xlabel
#
Set x-axis label.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label
|
str
|
x-axis label, by default None |
None
|
**kwargs
|
kwargs
|
Keyword arguments passed to |
{}
|
Source code in puma/plot_base.py
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 |
|
set_xlim
#
Set limits of x-axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xmin
|
float
|
Min of x-axis, by default None |
None
|
xmax
|
float
|
Max of x-axis, by default None |
None
|
**kwargs
|
kwargs
|
Keyword arguments passed to |
{}
|
Source code in puma/plot_base.py
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 |
|
set_y_lim
#
Set limits of y-axis.
Source code in puma/plot_base.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
|
set_ylabel
#
Set y-axis label.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ax_mpl
|
matplotlib.axes.Axes
|
matplotlib axis object |
required |
label
|
str
|
x-axis label, by default None |
None
|
align
|
str
|
Alignment of y-axis label, by default "right" |
'right'
|
**kwargs
|
Keyword arguments passed to |
{}
|
|
kwargs
|
Keyword arguments passed to |
{}
|
Source code in puma/plot_base.py
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 |
|
show
#
Show the plot using tkinter in command line and detect Jupyter to avoid issues.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
auto_close_after
|
int | None
|
After how many milliseconds, the window is automatically closed, by default None |
None
|
Source code in puma/plot_base.py
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 |
|