Classes | |
class | PlotConfig |
Functions | |
def | save_png_eps (plot, wp, name, plot_cfg=None) |
def | round_half_up (value, ndigit=0) |
def | magnitude (value) |
def | get_bound (value, up=False) |
def | get_optimal_bounds (low_value, up_value) |
Common used functions for plotting based on matplotlib. @author : Liangjun Zhu @changelog: - 18-10-29 - lj - Extract from other packages. - 18-11-18 - lj - Add getting value bounds related functions. = 19-01-07 - lj - Add PlotConfig for basic plot settings for matplotlib
def seims.utility.plot.get_bound | ( | value, | |
up = False |
|||
) |
Calculate the optimal up or low bound. Examples: >>> get_bound(0.00175) # order: -3 -> ndigits: [3] + [0.0] [0.001, 0.0] >>> get_bound(0.00175, up=True) # order: -3 -> ndigits: [3] + [10^-2] [0.002, 0.01] >>> get_bound(0.0125) # order: -2 -> ndigits: [2] + [0.0] [0.01, 0.0] >>> get_bound(0.0125, up=True) # order: -2 -> ndigits: [2] + [10^-1] [0.02, 0.1] >>> get_bound(0.1) # order: -1 -> ndigits: [1] + [0.0] [0.1, 0.0] >>> get_bound(0.1, up=True) # order: -1 -> ndigits: [1] + [10^0] [0.2, 1.0] >>> get_bound(1.5) # order: 0 -> ndigits: [0] + [0] [1.0, 0.0] >>> get_bound(1.5, up=True) # order: 0 -> ndigits: [0] + orders: [1] [2.0, 10.0] >>> get_bound(5.0) [5.0, 0.0] >>> get_bound(5.0, up=True) [6.0, 10.0] >>> get_bound(12.5) # order: 1 ->, ndigits: [0, -1] + [0] [12.0, 10.0, 0.0] >>> get_bound(12.5, up=True) # order: 1 ->, ndigits: [0, -1] + orders: [2] [13.0, 20.0, 100.0] >>> get_bound(125.5) # order: 2 -> ndigits: [0, -1, -2] + orders: [1] + [0.0] [125.0, 120.0, 100.0, 10.0, 0.0] >>> get_bound(125.5, up=True) # order: 2 -> ndigits: [0, -1, -2] + orders: [3] [126.0, 130.0, 200.0, 1000.0] >>> get_bound(988, up=True) # order: 2 -> ndigits: [0, -1, -2] + orders: [3] [989.0, 990.0, 1000.0, 1000.0] >>> get_bound(-125.5) # equals to -1 * get_bound(125.5, up=True) [-126.0, -130.0, -200.0, -1000.0] >>> get_bound(-125.5, up=True) [-125.0, -120.0, -100.0, -10.0, 0.0] Returns: List of bounds with the same order and higher (or lower) orders of the input value.
def seims.utility.plot.get_optimal_bounds | ( | low_value, | |
up_value | |||
) |
Calculate the optimal bounds of given lower and upper values for plotting. Examples: >>> get_optimal_bounds(1.2, 5.5) (1.0, 6.0) >>> get_optimal_bounds(0.12, 0.55) # doctest: +ELLIPSIS (0.1, 0.6...) >>> get_optimal_bounds(5, 158) (0.0, 160.0) >>> get_optimal_bounds(5, 58) (0.0, 60.0) >>> get_optimal_bounds(5, 55) (0.0, 56.0) >>> get_optimal_bounds(5, 89) (0.0, 90.0) >>> get_optimal_bounds(5, 121) (0.0, 130.0) >>> get_optimal_bounds(0.5, 58) (0.0, 60.0) >>> get_optimal_bounds(121, 288) (120.0, 290.0) >>> get_optimal_bounds(1210, 2880) (1200.0, 2900.0) >>> get_optimal_bounds(0.025, 0.11) (0.0, 0.2) >>> get_optimal_bounds(0.0025, 0.11) (0.0, 0.2) >>> get_optimal_bounds(0.00025, 0.11) (0.0, 0.2)
def seims.utility.plot.magnitude | ( | value | ) |
Get the order of magnitude of a numeric value. Examples: >>> magnitude(-0.0125) -2 >>> magnitude(0.125) -1 >>> magnitude(0.12) -1 >>> magnitude(0.1) -1 >>> magnitude(0.0) 0 >>> magnitude(3.5) 0 >>> magnitude(11) 1 >>> magnitude(111) 2
def seims.utility.plot.round_half_up | ( | value, | |
ndigit = 0 |
|||
) |
Since Python builtin function round() cannot properly round up by half, use decimal module instead.. References: https://stackoverflow.com/questions/33019698/how-to-properly-round-up-half-float-numbers-in-python
def seims.utility.plot.save_png_eps | ( | plot, | |
wp, | |||
name, | |||
plot_cfg = None |
|||
) |
Save figures, both png and eps formats