diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7cf9ce9..f644f05 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,32 +1,32 @@ repos: -# - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks -# rev: v2.1.0 -# hooks: -# - id: pretty-format-yaml -# args: [--autofix, --indent, '2'] - repo: https://github.com/psf/black - rev: 21.12b0 + rev: 22.1.0 hooks: - id: black args: [--safe, --quiet, --line-length=100] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.0.1 + rev: v4.1.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - id: debug-statements +- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.3.0 + hooks: + - id: pretty-format-yaml + args: [--autofix, --indent, '2', --preserve-quotes] - repo: https://github.com/humitos/mirrors-autoflake.git rev: v1.1 hooks: - id: autoflake args: [--in-place, --remove-unused-variable] - repo: https://github.com/asottile/reorder_python_imports - rev: v2.6.0 + rev: v2.7.1 hooks: - id: reorder-python-imports - repo: https://github.com/asottile/pyupgrade - rev: v2.29.1 + rev: v2.31.0 hooks: - id: pyupgrade args: [--py36-plus] @@ -34,7 +34,7 @@ repos: rev: 4.0.1 hooks: - id: flake8 - args: ["--ignore=E722", --max-line-length=110, "--per-file-ignores=*/__init__.py:F401"] + args: [--max-line-length=100, "--ignore=E722", "--per-file-ignores=*/__init__.py:F401"] - repo: https://github.com/asottile/setup-cfg-fmt rev: v1.20.0 hooks: diff --git a/.readthedocs.yml b/.readthedocs.yml index 2d6875a..90a2357 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -3,7 +3,7 @@ # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details sphinx: - configuration: docs/conf.py + configuration: docs/conf.py version: 2 @@ -12,6 +12,6 @@ conda: python: install: - - method: pip - path: . + - method: pip + path: . system_packages: true diff --git a/GooseMPL/__init__.py b/GooseMPL/__init__.py index 38af19f..b9354fc 100644 --- a/GooseMPL/__init__.py +++ b/GooseMPL/__init__.py @@ -194,9 +194,9 @@ def latex_float(number, fmt="{0:.2g}"): if "e" in float_str: base, exponent = float_str.split("e") if base == "1": - return fr"10^{{{int(exponent)}}}" + return rf"10^{{{int(exponent)}}}" else: - return fr"{base} \times 10^{{{int(exponent)}}}" + return rf"{base} \times 10^{{{int(exponent)}}}" return float_str @@ -254,7 +254,7 @@ def log_ticks( exp_lower, exp_upper = lim ticks = np.logspace(exp_lower, exp_upper, exp_upper - exp_lower + 1, base=base) - labels = [fr"${base}^{{{np.log10(i):.0f}}}$" for i in ticks] + labels = [rf"${base}^{{{np.log10(i):.0f}}}$" for i in ticks] if keep is not None: keep = np.array(keep) @@ -356,7 +356,7 @@ def log_minorticks( for i in range(exp_lower, exp_upper): - t = (10 ** i) * np.arange(2, 10, dtype=float) + t = (10**i) * np.arange(2, 10, dtype=float) if i < 0: t = np.around(t, -i) @@ -743,9 +743,10 @@ def plot(x, y, units="absolute", axis=None, **kwargs): :options: **units** ([``'absolute'``] | ``'relative'``) - The type of units in which the coordinates are specified. Relative coordinates correspond - to a fraction of the relevant axis. If you use relative coordinates, be sure to set the - limits and scale before calling this function! + The type of units in which the coordinates are specified. + Relative coordinates correspond to a fraction of the relevant axis. + If you use relative coordinates, be sure to set the limits and scale before calling + this function! ... Any ``plt.plot(...)`` option. @@ -783,9 +784,10 @@ def text(x, y, text, units="absolute", axis=None, **kwargs): :options: **units** ([``'absolute'``] | ``'relative'``) - The type of units in which the coordinates are specified. Relative coordinates correspond - to a fraction of the relevant axis. If you use relative coordinates, be sure to set the - limits and scale before calling this function! + The type of units in which the coordinates are specified. + Relative coordinates correspond to a fraction of the relevant axis. + If you use relative coordinates, be sure to set the limits and scale before calling + this function! ... Any ``plt.text(...)`` option. @@ -820,7 +822,8 @@ def diagonal_powerlaw( The power-law exponent. **ll, lr, tl, tr** (````) - Coordinates of the lower-left, or the lower-right, or the top-left, or the top-right corner. + Coordinates of the lower-left, or the lower-right, or the top-left, + or the top-right corner. **width, height** (````) Width or the height. @@ -912,9 +915,10 @@ def annotate_powerlaw(text, exp, startx, starty, width=None, rx=0.5, ry=0.5, **k E.g. ``rx = 0.5, ry = 0.5`` corresponds to the middle of the line. **units** ([``'relative'``] | ``'absolute'``) - The type of units in which the coordinates are specified. Relative coordinates correspond - to a fraction of the relevant axis. If you use relative coordinates, be sure to set the - limits and scale before calling this function! + The type of units in which the coordinates are specified. + Relative coordinates correspond to a fraction of the relevant axis. + If you use relative coordinates, be sure to set the limits and scale before calling + this function! **axis** ([``plt.gca()``] | ...) Specify the axis to which to apply the limits. @@ -965,11 +969,11 @@ def annotate_powerlaw(text, exp, startx, starty, width=None, rx=0.5, ry=0.5, **k [starty, endy] = rel2abs_y([starty, endy], axis) # determine multiplication constant - const = starty / (startx ** exp) + const = starty / (startx**exp) # get end x/y-coordinate if endx is not None: - endy = const * endx ** exp + endy = const * endx**exp else: endx = (endy / const) ** (1 / exp) @@ -999,9 +1003,10 @@ def plot_powerlaw(exp, startx, starty, width=None, **kwargs): Definition of the end coordinate (only on of these options is needed). **units** ([``'relative'``] | ``'absolute'``) - The type of units in which the coordinates are specified. Relative coordinates correspond - to a fraction of the relevant axis. If you use relative coordinates, be sure to set the - limits and scale before calling this function! + The type of units in which the coordinates are specified. + Relative coordinates correspond to a fraction of the relevant axis. + If you use relative coordinates, be sure to set the limits and scale before calling + this function! **axis** ([``plt.gca()``] | ...) Specify the axis to which to apply the limits. @@ -1057,11 +1062,11 @@ def plot_powerlaw(exp, startx, starty, width=None, **kwargs): [starty, endy] = rel2abs_y([starty, endy], axis) # determine multiplication constant - const = starty / (startx ** exp) + const = starty / (startx**exp) # get end x/y-coordinate if endx is not None: - endy = const * endx ** exp + endy = const * endx**exp else: endx = (endy / const) ** (1 / exp) @@ -1075,8 +1080,8 @@ def plot_powerlaw(exp, startx, starty, width=None, **kwargs): def grid_powerlaw(exp, insert=0, skip=0, end=-1, step=0, axis=None, **kwargs): r""" - Draw a power-law grid: a grid that respects a certain power-law exponent. The grid-lines start from - the positions of the ticks. + Draw a power-law grid: a grid that respects a certain power-law exponent. + The grid-lines start from the positions of the ticks. :arguments: @@ -1399,9 +1404,9 @@ def fit_powerlaw( xl = np.logspace(np.log10(xl[0]), np.log10(xl[-1]), 1000) xu = np.logspace(np.log10(xu[0]), np.log10(xu[-1]), 1000) - yp = prefactor * xp ** exponent - yl = prefactor * xl ** exponent - yu = prefactor * xu ** exponent + yp = prefactor * xp**exponent + yl = prefactor * xl**exponent + yu = prefactor * xu**exponent details["handle"] = axis.plot(xp, yp, **kwargs) @@ -2016,7 +2021,8 @@ def histogram(data, return_edges=True, **kwargs): def histogram_cumulative(data, **kwargs): r""" Compute cumulative histogram. - See `numpy.histrogram `__ + See `numpy.histrogram + `__ :extra options: @@ -2204,8 +2210,16 @@ def patch(*args, **kwargs): fig,ax = plt.subplots() - p = gplt.patch(coor=coor+disp,conn=conn,axis=ax,cindex=stress,cmap='YlOrRd',edgecolor=None) - _ = gplt.patch(coor=coor ,conn=conn,axis=ax) + p = gplt.patch( + coor=coor + disp, + conn=conn, + axis=ax, + cindex=stress, + cmap='YlOrRd', + edgecolor=None + ) + + _ = gplt.patch(coor=coor, conn=conn, axis=ax) cbar = fig.colorbar(p,axis=ax,aspect=10) @@ -2222,7 +2236,8 @@ def patch(*args, **kwargs): Matrix with on each row the coordinates (positions) of each node. **conn** (```` | ```` (nested)) - Matrix with on each row the number numbers (rows in ``coor``) which form an element (patch). + Matrix with on each row the number numbers (rows in ``coor``) + which form an element (patch). :options: @@ -2233,8 +2248,8 @@ def patch(*args, **kwargs): Specify an axis to include to plot in. By default the current axis is used. **autoscale** ([``True``] | ``False``) - Automatically update the limits of the plot (currently automatic limits of Collections are - not supported by matplotlib). + Automatically update the limits of the plot + (currently automatic limits of Collections are not supported by matplotlib). :recommended options: diff --git a/docs/examples/goosempl/fit_powerlaw.py b/docs/examples/goosempl/fit_powerlaw.py index 04845b4..ea3542a 100644 --- a/docs/examples/goosempl/fit_powerlaw.py +++ b/docs/examples/goosempl/fit_powerlaw.py @@ -15,7 +15,7 @@ ax.set_ylim([1e-2, 1e4]) x = np.logspace(1, 3, 1000) -y = 0.001 * x ** 2.0 +y = 0.001 * x**2.0 y = y + 0.1 * np.random.random(x.shape) - 0.05 ax.plot(x, y) diff --git a/docs/examples/goosempl/fit_powerlaw_yerr.py b/docs/examples/goosempl/fit_powerlaw_yerr.py index c71ca5b..bbbd2d1 100644 --- a/docs/examples/goosempl/fit_powerlaw_yerr.py +++ b/docs/examples/goosempl/fit_powerlaw_yerr.py @@ -15,7 +15,7 @@ ax.set_ylim([1e-2, 1e4]) x = np.logspace(1, 3, 10) -y = 0.001 * x ** 2.0 +y = 0.001 * x**2.0 yerr = 0.1 * np.random.random(x.shape) * x sign = np.random.random(x.shape) sign = sign / np.abs(sign) diff --git a/docs/examples/goosempl/histogram.py b/docs/examples/goosempl/histogram.py index a648419..09331db 100644 --- a/docs/examples/goosempl/histogram.py +++ b/docs/examples/goosempl/histogram.py @@ -10,7 +10,7 @@ def distribution(a=100, b=3, g=-0.3, size=10000): r = np.random.random(size=size) - return (a ** g + (b ** g - a ** g) * r) ** (1.0 / g) + return (a**g + (b**g - a**g) * r) ** (1.0 / g) data = distribution() diff --git a/docs/examples/goosempl/histogram_powerlaw.py b/docs/examples/goosempl/histogram_powerlaw.py index 720b2b2..7b882bb 100644 --- a/docs/examples/goosempl/histogram_powerlaw.py +++ b/docs/examples/goosempl/histogram_powerlaw.py @@ -10,7 +10,7 @@ def distribution(a=100, b=3, g=-0.3, size=10000): r = np.random.random(size=size) - return (a ** g + (b ** g - a ** g) * r) ** (1.0 / g) + return (a**g + (b**g - a**g) * r) ** (1.0 / g) data = distribution() diff --git a/docs/examples/goosempl/ticks_log.py b/docs/examples/goosempl/ticks_log.py index 3b6c013..549c244 100644 --- a/docs/examples/goosempl/ticks_log.py +++ b/docs/examples/goosempl/ticks_log.py @@ -9,7 +9,7 @@ fig, ax = plt.subplots() x = np.logspace(1, 3, 1000) -y = 0.001 * x ** 2.0 +y = 0.001 * x**2.0 ax.plot(x, y) diff --git a/docs/examples/pyplot/image.py b/docs/examples/pyplot/image.py index 1f69edc..80eb768 100644 --- a/docs/examples/pyplot/image.py +++ b/docs/examples/pyplot/image.py @@ -4,7 +4,7 @@ plt.style.use(["goose", "goose-latex"]) x, y = np.meshgrid(np.linspace(0, 1, 100), np.linspace(0, 1, 100)) -d = np.sqrt(x ** 2 + y ** 2) +d = np.sqrt(x**2 + y**2) fig, ax = plt.subplots() diff --git a/docs/examples/pyplot/image_subplots.py b/docs/examples/pyplot/image_subplots.py index c2d1d10..8ca145a 100644 --- a/docs/examples/pyplot/image_subplots.py +++ b/docs/examples/pyplot/image_subplots.py @@ -7,7 +7,7 @@ # --- some data ---- a, b = np.meshgrid(np.linspace(0, 1, 100), np.linspace(0, 1, 100)) -d = np.sqrt(a ** 2 + b ** 2) +d = np.sqrt(a**2 + b**2) # --- open figure with three axes --- diff --git a/docs/examples/pyplot/image_subplots_bottom.py b/docs/examples/pyplot/image_subplots_bottom.py index a465a93..fb24088 100644 --- a/docs/examples/pyplot/image_subplots_bottom.py +++ b/docs/examples/pyplot/image_subplots_bottom.py @@ -7,7 +7,7 @@ # --- some data ---- a, b = np.meshgrid(np.linspace(0, 1, 100), np.linspace(0, 1, 100)) -d = np.sqrt(a ** 2 + b ** 2) +d = np.sqrt(a**2 + b**2) # --- open figure with three axes --- diff --git a/docs/examples/pyplot/legend_background.py b/docs/examples/pyplot/legend_background.py index 9d6248e..fd02dd2 100644 --- a/docs/examples/pyplot/legend_background.py +++ b/docs/examples/pyplot/legend_background.py @@ -7,7 +7,7 @@ for i in range(10): x = [0, 1] y = [i / 10, (i + 10) / 10] - ax.plot(x, y, label=fr"$i = {i:d}$") + ax.plot(x, y, label=rf"$i = {i:d}$") ax.legend(loc="center right", facecolor="white", framealpha=1) diff --git a/docs/examples/pyplot/plot-cmap.py b/docs/examples/pyplot/plot-cmap.py index b3935e0..ff5c493 100644 --- a/docs/examples/pyplot/plot-cmap.py +++ b/docs/examples/pyplot/plot-cmap.py @@ -11,7 +11,7 @@ fig, ax = plt.subplots() for i, n in enumerate(np.linspace(0, 2, N)): - y = np.sin(x) * x ** n + y = np.sin(x) * x**n ax.plot(x, y, color=cmap(i)) ax.set_xlabel(r"$x$") diff --git a/docs/examples/pyplot/plot-cycler.py b/docs/examples/pyplot/plot-cycler.py index dc12b0e..86a9ee9 100644 --- a/docs/examples/pyplot/plot-cycler.py +++ b/docs/examples/pyplot/plot-cycler.py @@ -13,7 +13,7 @@ fig, ax = plt.subplots() for n in np.linspace(0, 2, N): - y = np.sin(x) * x ** n + y = np.sin(x) * x**n ax.plot(x, y) ax.set_xlabel(r"$x$") diff --git a/docs/examples/pyplot/tick-formatter.py b/docs/examples/pyplot/tick-formatter.py index c6ba15f..d0b07aa 100644 --- a/docs/examples/pyplot/tick-formatter.py +++ b/docs/examples/pyplot/tick-formatter.py @@ -5,7 +5,7 @@ plt.style.use(["goose", "goose-latex"]) x = np.linspace(0, 10, 101) -y = x ** 2.0 +y = x**2.0 fig, ax = plt.subplots() diff --git a/test/main.py b/test/main.py index acd7ed6..30110fe 100644 --- a/test/main.py +++ b/test/main.py @@ -130,7 +130,7 @@ class Test_fit_powerlaw(unittest.TestCase): def test_prefactor_exponent(self): x = np.linspace(0, 1, 1000) - y = 1.2 * x ** 3.4 + y = 1.2 * x**3.4 prefactor, exponent, _ = gplt.fit_powerlaw(x, y) self.assertTrue(np.isclose(prefactor, 1.2)) self.assertTrue(np.isclose(exponent, 3.4)) @@ -138,7 +138,7 @@ def test_prefactor_exponent(self): def test_prefactor(self): x = np.linspace(0, 1, 1000) - y = 1.2 * x ** 3.4 + y = 1.2 * x**3.4 prefactor, exponent, _ = gplt.fit_powerlaw(x, y, exponent=3.4) self.assertTrue(np.isclose(prefactor, 1.2)) self.assertTrue(np.isclose(exponent, 3.4)) @@ -146,7 +146,7 @@ def test_prefactor(self): def test_exponent(self): x = np.linspace(0, 1, 1000) - y = 1.2 * x ** 3.4 + y = 1.2 * x**3.4 prefactor, exponent, _ = gplt.fit_powerlaw(x, y, prefactor=1.2) self.assertTrue(np.isclose(prefactor, 1.2)) self.assertTrue(np.isclose(exponent, 3.4))