mirror of
https://github.com/Richard-Sti/csiborgtools_public.git
synced 2025-05-14 06:31:11 +00:00
Better plots (#73)
* Edits paths of saved files * Add upper threshold options * Add upper threshold options * add latex_float option * Add weighted stats * add new plot
This commit is contained in:
parent
de7def61d5
commit
fbf9c2a4b7
5 changed files with 225 additions and 39 deletions
|
@ -16,3 +16,38 @@
|
|||
dpi = 600
|
||||
fout = "../plots/"
|
||||
mplstyle = ["science"]
|
||||
|
||||
|
||||
def latex_float(*floats, n=2):
|
||||
"""
|
||||
Convert a float or a list of floats to a LaTeX string(s). Taken from [1].
|
||||
|
||||
Parameters
|
||||
----------
|
||||
floats : float or list of floats
|
||||
The float(s) to be converted.
|
||||
n : int, optional
|
||||
The number of significant figures to be used in the LaTeX string.
|
||||
|
||||
Returns
|
||||
-------
|
||||
latex_floats : str or list of str
|
||||
The LaTeX string(s) representing the float(s).
|
||||
|
||||
References
|
||||
----------
|
||||
[1] https://stackoverflow.com/questions/13490292/format-number-using-latex-notation-in-python # noqa
|
||||
"""
|
||||
latex_floats = [None] * len(floats)
|
||||
for i, f in enumerate(floats):
|
||||
float_str = "{0:.{1}g}".format(f, n)
|
||||
if "e" in float_str:
|
||||
base, exponent = float_str.split("e")
|
||||
latex_floats[i] = r"{0} \times 10^{{{1}}}".format(base,
|
||||
int(exponent))
|
||||
else:
|
||||
latex_floats[i] = float_str
|
||||
|
||||
if len(floats) == 1:
|
||||
return latex_floats[0]
|
||||
return latex_floats
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue