Overview of the API
This part of the project documentation focuses on
an information-oriented approach. Use it as a
reference for the technical implementation of the
calculator
project code.
configuration
configuration
BackendConfiguration
Source code in plotex/configuration/configuration.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 |
|
__fetch_content(url)
fetches the config params from the url if not locally present
Raises:
Type | Description |
---|---|
Exception
|
if issue in fetching and decoding |
Returns:
Type | Description |
---|---|
returns the content from the url |
Source code in plotex/configuration/configuration.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
__generate_content_path()
creates the config by using a cached file, or fetching from the internet if cached file not present
Returns:
Type | Description |
---|---|
the file path of the config file |
Source code in plotex/configuration/configuration.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
__init__(url=None, override=False, **kwargs)
initializing the configuration class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
the url of the config to create a new config, defaults to None |
None
|
|
override |
if the config from the specified link already exists, whether to create it again (used if in-place changes have been made to the url) |
False
|
|
kwargs |
other keyword arguments can include arguments for theme, style, palette etc. |
{}
|
Source code in plotex/configuration/configuration.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
initialize()
initializes the configuration file by setting the style from the config file
Source code in plotex/configuration/configuration.py
90 91 92 93 94 95 96 97 98 99 100 101 |
|
reset()
reset the parameters to the original matplotlib ones
Source code in plotex/configuration/configuration.py
85 86 87 |
|
main
Plotex
a facade over various different functions in the module for a direct one-point access
Source code in plotex/main.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 |
|
__init__(**kwargs)
initialize the controller
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
parameters for the config file, the params include
|
{}
|
Source code in plotex/main.py
10 11 12 13 14 15 16 17 18 19 20 21 |
|
init(**kwargs)
initialize the controller
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs |
parameters for the config file, the params include
|
{}
|
Source code in plotex/main.py
24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
remove_ticks(xtick=True, ytick=True)
remove the tick marks
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xtick |
remove ticks on x-axis, defaults to True |
True
|
|
ytick |
remove ticks on y-axis, defaults to True |
True
|
Source code in plotex/main.py
95 96 97 98 99 100 101 102 |
|
set_lim(ax, xlims=(None, None), ylims=(None, None))
set the starting and ending points of the x and y axes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ax |
the matplotlib axis object |
required | |
xlims |
tuple containing the (min, max) values of the \ x axis, defaults to (None, None) |
(None, None)
|
|
ylims |
tuple containing the (min, max) values of the \ y axis, defaults to (None, None) |
(None, None)
|
Source code in plotex/main.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
skeleton(width=None, publisher=None, width_in_pts=True, reinitialize=True, fraction=1, subplots=(1, 1), **kwargs)
finds the ideal size of the plot and adjusts the text sizes according to the required dimensions
this is a dummy function wrapped over the get_figure
function from Sizing to enable direct access
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width |
the width, defaults to None |
None
|
|
publisher |
the name of the publisher, defaults to None |
None
|
|
width_in_pts |
whether the width is in points, defaults to True |
True
|
|
reinitialize |
whether to reinitialize the config to itys defaults, defaults to True |
True
|
|
fraction |
the fraction of the width supplied to use, defaults to 1 |
1
|
|
subplots |
(nrows, ncols), defaults to (1, 1) |
(1, 1)
|
Returns:
Type | Description |
---|---|
fig, axes if return_size is False, else (width, height) |
Source code in plotex/main.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
update_textsize(reinitialize=True, **kwargs)
This function changes the font size of various text elements in the plot such as xlabel, ylabel, title, ticks, etc., by a specified offset. Uses deterministic and probabilistic matching to determine and map the keyword argument to the required property
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reinitialize |
initialize size params to those created by
|
True
|
|
**kwargs |
flexible keyword arguments specified by the user, where the name of the argument is the key and the offset is the value. |
{}
|
Source code in plotex/main.py
64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
update_textweight(reinitialize=False, **kwargs)
This function changes the font weight of various text elements in the plot such as xlabel, ylabel, title. The values are 'light', 'normal', 'bold'. Uses deterministic and probabilistic matching to determine and map the keyword \ argument to the required property
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reinitialize |
initialize size params to those created by
|
False
|
|
**kwargs |
flexible keyword arguments specified by the user, where the name of the argument is the key and the weight is the value. |
{}
|
Source code in plotex/main.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
plotsize
figsize
Sizing
Source code in plotex/plotsize/figsize.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 |
|
__cache_width(publisher, width)
caches the publisher:width
mapping
Parameters:
Name | Type | Description | Default |
---|---|---|---|
publisher |
str
|
the publisher |
required |
width |
float
|
the width in pts |
required |
Source code in plotex/plotsize/figsize.py
95 96 97 98 99 100 101 102 103 104 105 |
|
__find_matching_param(key, main_params, special_params={})
find the matching paramater to the key in the matplotlib.rcParams file specified by the main_params and special_params
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
the key with which we search |
required | |
main_params |
the main dictionary, with keys as rcParams keys and values as their shortened versions |
required | |
special_params |
direct mapping to handle exceptions where probabilstic matching might fail, defaults to {} |
{}
|
Returns:
Type | Description |
---|---|
the found parameter, or None if not found |
Source code in plotex/plotsize/figsize.py
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 |
|
__get_width_publisher(publisher, width=None)
get the width in pts given the name of the publisher
Parameters:
Name | Type | Description | Default |
---|---|---|---|
publisher |
str
|
the name of the publisher |
required |
width |
float
|
if width is specified, then it is cached |
None
|
Returns:
Name | Type | Description |
---|---|---|
float | the width in pts |
Source code in plotex/plotsize/figsize.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
__init__(config=None, **config_kwargs)
initialize the sizing class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
the config file, defaults to None |
None
|
Source code in plotex/plotsize/figsize.py
16 17 18 19 20 21 22 23 24 25 26 27 |
|
__load_params()
load the current saved copy of the rcParams
Source code in plotex/plotsize/figsize.py
47 48 49 50 |
|
__read_width(publisher)
reads the width from the config file for the supplied publisher. If not found, then use the ACL format width
Parameters:
Name | Type | Description | Default |
---|---|---|---|
publisher |
str
|
the publisher name |
required |
Returns:
Name | Type | Description |
---|---|---|
float | the width in pts |
Source code in plotex/plotsize/figsize.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
__save_params()
save a copy of the current rcParams
Source code in plotex/plotsize/figsize.py
42 43 44 |
|
adjust_font_size(subplots, fraction, **kwargs)
adjust the font_size based on the fraction and number of columns and saves the adjusted params
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subplots |
at uple of (nrow, ncols) |
required | |
fraction |
fraction of the total width to use |
required |
Source code in plotex/plotsize/figsize.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
convert_width_to_inches(width=None, publisher=None)
convert width from pts to inches
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width |
the given width in pts, defaults to None |
None
|
|
publisher |
the name of the publisher, defaults to None |
None
|
Returns:
Type | Description |
---|---|
the width in inches |
Source code in plotex/plotsize/figsize.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
|
get_size(width=None, publisher=None, width_in_pts=True, reinitialize=True, fraction=1, subplots=(1, 1), **kwargs)
finds the ideal size of the plot and adjusts the text sizes according to the required dimensions if both publisher and width are specified, then the publisher:width is cached
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width |
the width, defaults to None |
None
|
|
publisher |
the name of the publisher, defaults to None |
None
|
|
width_in_pts |
whether the width is in points, defaults to True |
True
|
|
reinitialize |
whether to reinitialize the config to itys defaults, defaults to True |
True
|
|
fraction |
the fraction of the width supplied to use, defaults to 1 |
1
|
|
subplots |
(nrows, ncols), defaults to (1, 1) |
(1, 1)
|
Returns:
Type | Description |
---|---|
figsize (width, height) |
Source code in plotex/plotsize/figsize.py
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 |
|
remove_ticks(xtick=True, ytick=True)
remove the tick marks
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xtick |
remove ticks on x-axis, defaults to True |
True
|
|
ytick |
remove ticks on y-axis, defaults to True |
True
|
Source code in plotex/plotsize/figsize.py
222 223 224 225 226 227 228 229 230 231 232 |
|
set_lim(ax, xlims=(None, None), ylims=(None, None))
set the starting and ending points of the x and y axes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ax |
the matplotlib axis object |
required | |
xlims |
tuple containing the (min, max) values of the x axis, defaults to (None, None) |
(None, None)
|
|
ylims |
tuple containing the (min, max) values of the y axis, defaults to (None, None) |
(None, None)
|
Source code in plotex/plotsize/figsize.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
update_textsize(reinitialize=True, **kwargs)
This function changes the font size of various text elements in the plot such as xlabel, ylabel, title, sticks, etc., by a specified offset. Uses deterministic and probabilistic matching to determine and map the keyword argument to the required property
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reinitialize |
initialize size params to those created by
|
True
|
|
**kwargs |
flexible keyword arguments specified by the user, where the name of |
{}
|
the argument is the key and the offset is the value.
Source code in plotex/plotsize/figsize.py
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 |
|
update_textweight(reinitialize=False, **kwargs)
This function changes the font weight of various text elements in the plot such as xlabel, ylabel, title. The values are 'light', 'normal', 'bold'. Uses deterministic and probabilistic matching to determine and map the keyword argument to the required property
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reinitialize |
initialize size params to those created by
|
False
|
|
**kwargs |
flexible keyword arguments specified by the user, where the name of |
{}
|
the argument is the key and the weight is the value.
Source code in plotex/plotsize/figsize.py
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 |
|
utils
general
check_if_exists(fpath)
checks if fpath exists
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fpath |
str
|
the file path to check |
required |
:return bool: whether the path exists
Source code in plotex/utils/general.py
32 33 34 35 36 37 38 39 |
|
combine_hash(fpath, hashed)
combines the file name with the hashcode and returns the absolute path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fpath |
fpath |
required | |
hashed |
ahash code |
required |
Returns:
Type | Description |
---|---|
the absolute combine path |
Source code in plotex/utils/general.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
find_value_from_keys(main_dict, keys)
traverses the specified key list, and if any key is found in the dictionary, returns the corresponding value, else None
Parameters:
Name | Type | Description | Default |
---|---|---|---|
main_dict |
the dictionary to search in |
required | |
keys |
the list of keys |
required |
Returns:
Type | Description |
---|---|
the value if found, else None |
Source code in plotex/utils/general.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
save(save_path, fig=None, plt=None, format='pdf')
utility function to save the figure
Parameters:
Name | Type | Description | Default |
---|---|---|---|
save_path |
the save path for the figure (including the extension) |
required | |
fig |
the figure object, defaults to None |
None
|
|
plt |
the plt object, defaults to None |
None
|
|
format |
the format of the output plot, defaults to 'pdf' |
'pdf'
|
Source code in plotex/utils/general.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
save_file(content, fpath)
saves the supplied content in a text file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content |
str/dict
|
the content |
required |
fpath |
str
|
the file path to save at |
required |
Source code in plotex/utils/general.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
hashing
hash_url(url)
generate a hash for the url
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
the url string |
required |
Returns:
Type | Description |
---|---|
the generated hash |
Source code in plotex/utils/hashing.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
plotting
custom_legend(ax, text, xy=(0.5, 0.5), box=True, box_bgcolor=(1.0, 1, 1, 1), box_edgecolor=(0.0, 0.0, 0.0, 0.1))
create a custom legend/text (without color strip)
Args:
ax: mpl axes object
text: the text to add (str or list); if list added with `
` xy: the (x,y) offset fraction, relative to the BOTTOM-LEFT point, defaults to (0.5, 0.5) box: whether to add a bounding box, defaults to True box_bgcolor: the background color of the box, defaults to (1.0, 1, 1, 1) box_edgecolor: the edge color of the box, defaults to (0.0, 0.0, 0.0, 0.1)
Returns:
`ax`, the axis object
Source code in plotex/utils/plotting.py
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 |
|
optimize_labels(labels, values)
optimizes the bar chart labels by interweaving the labels based on their length to minimize overlap
Parameters:
Name | Type | Description | Default |
---|---|---|---|
labels |
the original labels |
required | |
values |
the original values |
required |
Returns:
Type | Description |
---|---|
optimized labels, values |
Source code in plotex/utils/plotting.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
set_text(plt=None, ax=None, xlabel=None, ylabel=None, title=None, xticklocs=None, xticklabels=None, xtickrot=None, yticklocs=None, yticklabels=None, ytickrot=None)
set xlabel/ylabel/xticks/yticks/title (including rotation of ticks)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plt |
plt
|
the matplotlib pyplot object |
None
|
ax |
matplotlib.axes.Axes
|
axis on which to label |
None
|
xlabel |
the xlabel string, defaults to None |
None
|
|
ylabel |
the ylabel string, defaults to None |
None
|
|
title |
the title string, defaults to None |
None
|
|
xticklocs |
the location of xticks, defaults to None |
None
|
|
xticklabels |
the labels of xticks, defaults to None |
None
|
|
xtickrot |
the rotation angle in degrees of xtick labels, defaults to None |
None
|
|
yticklocs |
the location of yticks, defaults to None |
None
|
|
yticklabels |
the labels of yticks, defaults to None |
None
|
|
ytickrot |
the rotation angle in degrees of ytick labels, defaults to None |
None
|
Source code in plotex/utils/plotting.py
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 |
|