From 746bf073b3db02b86ba7626b2d88292ab0e67d6b Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sat, 11 Jul 2026 01:51:46 -0400 Subject: [PATCH] Fix minor linting issues Mostly unused imports, and single-line `if`. --- scripts/adjustements.py | 1 - scripts/anatomy.py | 2 +- scripts/annotate.py | 2 -- scripts/colors.py | 4 ++-- scripts/legend.py | 1 - scripts/linestyles.py | 6 ++---- scripts/markers.py | 9 +++------ scripts/plot-variations.py | 8 ++++---- scripts/styles.py | 1 - scripts/tick-multiple-locator.py | 1 - scripts/tip-colorbar.py | 1 - scripts/tip-dotted.py | 2 -- scripts/tip-font-family.py | 1 - 13 files changed, 12 insertions(+), 27 deletions(-) diff --git a/scripts/adjustements.py b/scripts/adjustements.py index 26f95592..eeb434e1 100644 --- a/scripts/adjustements.py +++ b/scripts/adjustements.py @@ -8,7 +8,6 @@ import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.patches as mpatches -from matplotlib.collections import PatchCollection ROOT_DIR = pathlib.Path(__file__).parent.parent diff --git a/scripts/anatomy.py b/scripts/anatomy.py index e8f95cce..a8daf883 100644 --- a/scripts/anatomy.py +++ b/scripts/anatomy.py @@ -30,7 +30,7 @@ def minor_tick(x, pos): if not x % 1.0: return "" - return "%.2f" % x + return f"{x:.2f}" ax.xaxis.set_major_locator(MultipleLocator(1.000)) diff --git a/scripts/annotate.py b/scripts/annotate.py index 65353684..c5d692ab 100644 --- a/scripts/annotate.py +++ b/scripts/annotate.py @@ -4,8 +4,6 @@ # ----------------------------------------------------------------------------- import pathlib -import numpy as np -import matplotlib as mpl import matplotlib.pyplot as plt diff --git a/scripts/colors.py b/scripts/colors.py index c72d1d92..86e3a706 100644 --- a/scripts/colors.py +++ b/scripts/colors.py @@ -26,8 +26,8 @@ 'raw' : ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'], 'rgba' : [(1, 0, 0), (1, 0, 0, 0.75), (1, 0, 0, 0.50), (1, 0, 0, 0.25)], 'HexRGBA' : ["#FF0000", "#FF0000BB", "#FF000088", "#FF000044"], - 'cycle' : ["C%d" % i for i in range(10)], - 'grey' : ["%1.1f" % (i/10) for i in range(11)], + 'cycle' : [f"C{i}" for i in range(10)], + 'grey' : [f"{i/10:1.1f}" for i in range(11)], 'name' : ["DarkRed", "Firebrick", "Crimson", "IndianRed", "Salmon" ] } for name, colors in palettes.items(): diff --git a/scripts/legend.py b/scripts/legend.py index 5faf885f..c78b6730 100644 --- a/scripts/legend.py +++ b/scripts/legend.py @@ -4,7 +4,6 @@ # ----------------------------------------------------------------------------- import pathlib -import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt diff --git a/scripts/linestyles.py b/scripts/linestyles.py index 6f9deaa3..17736fee 100644 --- a/scripts/linestyles.py +++ b/scripts/linestyles.py @@ -33,9 +33,7 @@ def split(n_segment): for x0, x1, style in zip(X0, X1, styles): ax.plot([x0, x1], [y, y], color="C1", linestyle=style, solid_capstyle="round", dash_capstyle="round", linewidth=3) - if isinstance(style, str): text = '"%s"' % style - else: text = '%s' % str(style) - text = text.replace(' ', '') + text = f'{style!r}'.replace(' ', '') ax.text((x0+x1)/2, y-0.2, text, size=8, ha="center", va="top", family="Source Code Pro") ax.text(X0[0]-0.25, y+0.2, "linestyle or ls", family="Source Code Pro", @@ -51,7 +49,7 @@ def split(n_segment): linewidth=7, linestyle="--", alpha=.25) ax.plot([x0, x1], [y, y], color="C1", linewidth=7, linestyle="--", dash_capstyle=style) - ax.text((x0+x1)/2, y-0.2, '"%s"' % style, family="Source Code Pro", + ax.text((x0+x1)/2, y-0.2, f'{style!r}', family="Source Code Pro", size=10, ha="center", va="top") ax.text(X0[0]-0.25, y+0.2, "capstyle or dash_capstyle", family="Source Code Pro", size=14, ha="left", va="baseline") diff --git a/scripts/markers.py b/scripts/markers.py index 0780d12b..0b787e00 100644 --- a/scripts/markers.py +++ b/scripts/markers.py @@ -26,13 +26,10 @@ "1", "2", "3", "4", "+", "x", "|", "_", 4, 5, 6, 7, ".", "o", "s", "P", "X", "*", "p", "D", "<", ">", "^", "v", ] for x, y, marker in zip(X, Y, markers): - if y == 3: fc = "white" - else: fc = "C1" + fc = "white" if y == 3 else "C1" plt.scatter(x, 1+y, s=100, marker=marker, fc=fc, ec="C1", lw=0.5) - if y == 1: marker = "\$%s\$" % marker - if isinstance(marker, str): text = "'%s'" % marker - else: text = '%s' % marker + text = f"{marker!r}".replace("$", r"\$") plt.text(x, 1+y-0.4, text, size="x-small", ha="center", va="top", family="Monospace") @@ -50,7 +47,7 @@ Y = y*np.ones(len(X)) ax.plot(X, Y, linewidth=1, color="black", marker=".", mfc="white", mec="black", mew="1", markevery=mark) - ax.text((X[0]+X[-1])/2, y-0.2, '%s' % str(mark), + ax.text((X[0]+X[-1])/2, y-0.2, str(mark), size="x-small", ha="center", va="top") plt.text(.7, 1, "markevery", diff --git a/scripts/plot-variations.py b/scripts/plot-variations.py index 65b9ff1a..b07bf655 100644 --- a/scripts/plot-variations.py +++ b/scripts/plot-variations.py @@ -81,13 +81,13 @@ ax1.plot(X, Y1, color="C1", linewidth=0.75) ax1.set_ylim(0, 4), ax1.set_yticks(np.arange(1, 4)) ax1.grid() -ax1.tick_params(axis=u'both', which=u'both', length=0) +ax1.tick_params(axis='both', which='both', length=0) Y2 = 2+1*np.cos(2*X) ax2.plot(X, Y2, color="C0", linewidth=0.75) ax2.set_ylim(0, 4), ax2.set_yticks(np.arange(1, 4)) ax2.grid() -ax2.tick_params(axis=u'both', which=u'both', length=0) +ax2.tick_params(axis='both', which='both', length=0) fig.savefig(ROOT_DIR / "figures/plot-vsplit.pdf") # Basic line plot (hsplit) @@ -99,13 +99,13 @@ ax1.plot(Y1, X, color="C1", linewidth=0.75) ax1.set_xlim(0, 4), ax1.set_xticks(np.arange(1, 4)) ax1.grid() -ax1.tick_params(axis=u'both', which=u'both', length=0) +ax1.tick_params(axis='both', which='both', length=0) Y2 = 2+1*np.cos(2*X) ax2.plot(Y2, X, color="C0", linewidth=0.75) ax2.set_xlim(0, 4), ax2.set_xticks(np.arange(1, 4)) ax2.grid() -ax2.tick_params(axis=u'both', which=u'both', length=0) +ax2.tick_params(axis='both', which='both', length=0) fig.savefig(ROOT_DIR / "figures/plot-hsplit.pdf") # Basic line plot (title) diff --git a/scripts/styles.py b/scripts/styles.py index bedf9d92..bbcfe16d 100644 --- a/scripts/styles.py +++ b/scripts/styles.py @@ -5,7 +5,6 @@ import pathlib import numpy as np -import matplotlib as mpl import matplotlib.pyplot as plt diff --git a/scripts/tick-multiple-locator.py b/scripts/tick-multiple-locator.py index 2976a635..30324001 100644 --- a/scripts/tick-multiple-locator.py +++ b/scripts/tick-multiple-locator.py @@ -5,7 +5,6 @@ # ---------------------------------------------------------------------------- import pathlib -import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.ticker as ticker diff --git a/scripts/tip-colorbar.py b/scripts/tip-colorbar.py index 9e8da791..941eb81b 100644 --- a/scripts/tip-colorbar.py +++ b/scripts/tip-colorbar.py @@ -9,7 +9,6 @@ import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt -import matplotlib.patheffects as path_effects ROOT_DIR = pathlib.Path(__file__).parent.parent diff --git a/scripts/tip-dotted.py b/scripts/tip-dotted.py index 8f52a2cc..16f1e5cd 100644 --- a/scripts/tip-dotted.py +++ b/scripts/tip-dotted.py @@ -6,8 +6,6 @@ # Scripts to generate all the basic plots import pathlib -import numpy as np -import matplotlib as mpl import matplotlib.pyplot as plt diff --git a/scripts/tip-font-family.py b/scripts/tip-font-family.py index 53564ac3..ab3543ac 100644 --- a/scripts/tip-font-family.py +++ b/scripts/tip-font-family.py @@ -5,7 +5,6 @@ # ---------------------------------------------------------------------------- import pathlib -import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as ticker