diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..a2292e8 --- /dev/null +++ b/.flake8 @@ -0,0 +1,5 @@ +[flake8] +ignore = E20,E22,E501,E701,F401,W + +[pep8] +select = E12,E231,E241,E251,E26,E30 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 27c2048..b940132 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,3 +9,7 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace + - repo: https://github.com/pycqa/flake8 + rev: 4.0.1 + hooks: + - id: flake8 diff --git a/docs/conf.py b/docs/conf.py index f4c70d1..cc15a6d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -5,8 +5,8 @@ html_title = 'Visualization with Python' project = "Matplotlib cheatsheets" copyright = ( - f"2012 - {datetime.datetime.now().year} The Matplotlib development team" - ) + f"2012 - {datetime.datetime.now().year} The Matplotlib development team" +) author = "Matplotlib Developers" # -- General configuration --------------------------------------------------- diff --git a/logos/mpl-logos2.py b/logos/mpl-logos2.py index 9ae6b5d..5547a06 100644 --- a/logos/mpl-logos2.py +++ b/logos/mpl-logos2.py @@ -155,6 +155,7 @@ def make_logo(height_px, lw_bars, lw_grid, lw_border, rgrid, with_text=False): return fig, ax + ############################################################################## # A large logo: diff --git a/requirements/requirements.in b/requirements/requirements.in index 00cad75..d1fcdd7 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -1,11 +1,13 @@ +autopep8 bump2version cartopy==0.19.0.post1 +flake8 matplotlib==3.4.2 +mpl-sphinx-theme pdfx pip-tools pre-commit scipy sphinx -mpl-sphinx-theme --no-binary shapely diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 52e79e2..37074d2 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with python 3.9 +# This file is autogenerated by pip-compile # To update, run: # # pip-compile requirements.in @@ -10,6 +10,8 @@ alabaster==0.7.12 # via sphinx appdirs==1.4.4 # via virtualenv +autopep8==1.6.0 + # via -r requirements.in babel==2.9.1 # via sphinx beautifulsoup4==4.9.3 @@ -44,12 +46,20 @@ docutils==0.17.1 # sphinx filelock==3.0.12 # via virtualenv +flake8==4.0.1 + # via -r requirements.in identify==2.2.2 # via pre-commit idna==3.3 # via requests imagesize==1.2.0 # via sphinx +importlib-metadata==4.2.0 + # via + # flake8 + # pep517 + # pre-commit + # virtualenv jinja2==3.0.2 # via sphinx kiwisolver==1.3.1 @@ -58,6 +68,8 @@ markupsafe==2.0.1 # via jinja2 matplotlib==3.4.2 # via -r requirements.in +mccabe==0.6.1 + # via flake8 mpl-sphinx-theme==0.0.6 # via -r requirements.in nodeenv==1.5.0 @@ -81,10 +93,16 @@ pip-tools==6.1.0 # via -r requirements.in pre-commit==2.11.1 # via -r requirements.in +pycodestyle==2.8.0 + # via + # autopep8 + # flake8 pycparser==2.20 # via cffi pydata-sphinx-theme==0.7.1 # via mpl-sphinx-theme +pyflakes==2.4.0 + # via flake8 pygments==2.10.0 # via sphinx pyparsing==2.4.7 @@ -134,12 +152,19 @@ sphinxcontrib-serializinghtml==1.1.5 # via sphinx toml==0.10.2 # via + # autopep8 # pep517 # pre-commit +typing-extensions==4.0.0 + # via importlib-metadata urllib3==1.26.7 # via requests virtualenv==20.4.3 # via pre-commit +zipp==3.6.0 + # via + # importlib-metadata + # pep517 # The following packages are considered to be unsafe in a requirements file: # pip diff --git a/scripts/adjustements.py b/scripts/adjustements.py index 8d4577c..807474f 100644 --- a/scripts/adjustements.py +++ b/scripts/adjustements.py @@ -10,39 +10,39 @@ fig = plt.figure(figsize=(4.25, 4.25 * 95/115)) -ax = fig.add_axes([0,0,1,1], frameon=False, aspect=1, - xlim=(0-5,100+10), ylim=(-10,80+5), xticks=[], yticks=[]) +ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1, + xlim=(0-5, 100+10), ylim=(-10, 80+5), xticks=[], yticks=[]) box = mpatches.FancyBboxPatch( - (0,0), 100, 83, mpatches.BoxStyle("Round", pad=0, rounding_size=2), + (0, 0), 100, 83, mpatches.BoxStyle("Round", pad=0, rounding_size=2), linewidth=1., facecolor="0.9", edgecolor="black") ax.add_artist(box) box = mpatches.FancyBboxPatch( - (0,0), 100, 75, mpatches.BoxStyle("Round", pad=0, rounding_size=0), + (0, 0), 100, 75, mpatches.BoxStyle("Round", pad=0, rounding_size=0), linewidth=1., facecolor="white", edgecolor="black") ax.add_artist(box) box = mpatches.Rectangle( - (5,5), 45, 30, zorder=10, + (5, 5), 45, 30, zorder=10, linewidth=1.0, facecolor="white", edgecolor="black") ax.add_artist(box) box = mpatches.Rectangle( - (5,40), 45, 30, zorder=10, + (5, 40), 45, 30, zorder=10, linewidth=1.0, facecolor="white", edgecolor="black") ax.add_artist(box) box = mpatches.Rectangle( - (55,5), 40, 65, zorder=10, + (55, 5), 40, 65, zorder=10, linewidth=1.0, facecolor="white", edgecolor="black") ax.add_artist(box) # Window button -X, Y = [5,10,15], [79,79,79] -plt.scatter(X, Y, s=75, zorder=10, +X, Y = [5, 10, 15], [79, 79, 79] +plt.scatter(X, Y, s=75, zorder=10, edgecolor="black", facecolor="white", linewidth=1) @@ -60,7 +60,7 @@ plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False) -def ext_arrow(p0,p1,p2,p3): +def ext_arrow(p0, p1, p2, p3): p0, p1 = np.asarray(p0), np.asarray(p1) p2, p3 = np.asarray(p2), np.asarray(p3) ax.arrow(*p0, *(p1-p0), zorder=20, linewidth=0, @@ -69,9 +69,10 @@ def ext_arrow(p0,p1,p2,p3): ax.arrow(*p3, *(p2-p3), zorder=20, linewidth=0, length_includes_head=True, width=.4, head_width=2, head_length=2, color="black") - plt.plot([p1[0],p2[0]], [p1[1],p2[1]], linewidth=.9, color="black") + plt.plot([p1[0], p2[0]], [p1[1], p2[1]], linewidth=.9, color="black") -def int_arrow(p0,p1): + +def int_arrow(p0, p1): p0, p1 = np.asarray(p0), np.asarray(p1) ax.arrow(*((p0+p1)/2), *((p1-p0)/2), zorder=20, linewidth=0, length_includes_head=True, width=.4, @@ -81,48 +82,47 @@ def int_arrow(p0,p1): head_width=2, head_length=2, color="black") - x = 0 y = 10 -ext_arrow( (x-4,y), (x,y), (x+5,y), (x+9,y) ) +ext_arrow( (x-4, y), (x, y), (x+5, y), (x+9, y) ) ax.text(x+9.5, y, "left", ha="left", va="center", size="x-small", zorder=20) x += 50 -ext_arrow( (x-4,y), (x,y), (x+5,y), (x+9,y) ) +ext_arrow( (x-4, y), (x, y), (x+5, y), (x+9, y) ) ax.text(x-4.5, y, "wspace", ha="right", va="center", size="x-small", zorder=20) x += 45 -ext_arrow( (x-4,y), (x,y), (x+5,y), (x+9,y) ) +ext_arrow( (x-4, y), (x, y), (x+5, y), (x+9, y) ) ax.text(x-4.5, y, "right", ha="right", va="center", size="x-small", zorder=20) y = 0 x = 25 -ext_arrow( (x,y-4), (x,y), (x,y+5), (x,y+9) ) +ext_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) ) ax.text(x, y+9.5, "bottom", ha="center", va="bottom", size="x-small", zorder=20) y += 35 -ext_arrow( (x,y-4), (x,y), (x,y+5), (x,y+9) ) +ext_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) ) ax.text(x, y-4.5, "hspace", ha="center", va="top", size="x-small", zorder=20) y += 35 -ext_arrow( (x,y-4), (x,y), (x,y+5), (x,y+9) ) +ext_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) ) ax.text(x, y-4.5, "top", ha="center", va="top", size="x-small", zorder=20) -int_arrow((0,-5), (100,-5)) +int_arrow((0, -5), (100, -5)) ax.text(50, -5, "figure width", backgroundcolor="white", zorder=30, ha="center", va="center", size="x-small") -int_arrow((105,0), (105,75)) +int_arrow((105, 0), (105, 75)) ax.text(105, 75/2, "figure height", backgroundcolor="white", zorder=30, - rotation = "vertical", ha="center", va="center", size="x-small") + rotation="vertical", ha="center", va="center", size="x-small") -int_arrow((55,62.5), (95,62.5)) +int_arrow((55, 62.5), (95, 62.5)) ax.text(75, 62.5, "axes width", backgroundcolor="white", zorder=30, ha="center", va="center", size="x-small") -int_arrow((62.5,5), (62.5,70)) +int_arrow((62.5, 5), (62.5, 70)) ax.text(62.5, 35, "axes height", backgroundcolor="white", zorder=30, - rotation = "vertical", ha="center", va="center", size="x-small") + rotation="vertical", ha="center", va="center", size="x-small") plt.savefig("../figures/adjustments.pdf") diff --git a/scripts/advanced-plots.py b/scripts/advanced-plots.py index 34bf1ab..025378a 100644 --- a/scripts/advanced-plots.py +++ b/scripts/advanced-plots.py @@ -8,21 +8,20 @@ import matplotlib as mpl import matplotlib.pyplot as plt -fig = plt.figure(figsize=(0.4,0.4)) +fig = plt.figure(figsize=(0.4, 0.4)) mpl.rcParams['axes.linewidth'] = 0.5 mpl.rcParams['xtick.major.size'] = 0.0 mpl.rcParams['ytick.major.size'] = 0.0 d = 0.01 -ax = fig.add_axes([d,d,1-2*d,1-2*d]) - +ax = fig.add_axes([d, d, 1-2*d, 1-2*d]) # Step plot # ----------------------------------------------------------------------------- X = np.linspace(0, 10, 16) -Y = 4+2*np.sin(2*X) +Y = 4 + 2*np.sin(2*X) ax.step(X, Y, color="C1", linewidth=0.75) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.grid(linewidth=0.125) plt.savefig("../figures/advanced-step.pdf") ax.clear() @@ -30,37 +29,36 @@ # Violin plot # ----------------------------------------------------------------------------- np.random.seed(10) -D = np.random.normal((3,5,4), (0.75, 1.00, 0.75), (200,3)) -VP = ax.violinplot(D, [2,4,6], widths=1.5, +D = np.random.normal((3, 5, 4), (0.75, 1.00, 0.75), (200, 3)) +VP = ax.violinplot(D, [2, 4, 6], widths=1.5, showmeans=False, showmedians=False, showextrema=False) for body in VP['bodies']: body.set_facecolor('C1') body.set_alpha(1) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) plt.savefig("../figures/advanced-violin.pdf") ax.clear() - # Boxplot # ----------------------------------------------------------------------------- np.random.seed(10) -D = np.random.normal((3,5,4), (1.25, 1.00, 1.25), (100,3)) -VP = ax.boxplot(D, positions=[2,4,6], widths=1.5, patch_artist=True, +D = np.random.normal((3, 5, 4), (1.25, 1.00, 1.25), (100, 3)) +VP = ax.boxplot(D, positions=[2, 4, 6], widths=1.5, patch_artist=True, showmeans=False, showfliers=False, - medianprops = {"color": "white", - "linewidth": 0.25}, - boxprops = {"facecolor": "C1", - "edgecolor": "white", - "linewidth": 0.25}, - whiskerprops = {"color": "C1", - "linewidth": 0.75}, - capprops = {"color": "C1", - "linewidth": 0.75}) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) + medianprops={"color": "white", + "linewidth": 0.25}, + boxprops={"facecolor": "C1", + "edgecolor": "white", + "linewidth": 0.25}, + whiskerprops={"color": "C1", + "linewidth": 0.75}, + capprops={"color": "C1", + "linewidth": 0.75}) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) plt.savefig("../figures/advanced-boxplot.pdf") @@ -69,13 +67,13 @@ # Barbs plot # ----------------------------------------------------------------------------- np.random.seed(1) -X = [[2,4,6]] -Y = [[1.5,3,2]] -U = -np.ones((1,3))*0 -V = -np.ones((1,3))*np.linspace(50,100,3) -ax.barbs(X,Y,U,V, barbcolor="C1", flagcolor="C1", length=5, linewidth=0.5) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +X = [[2, 4, 6]] +Y = [[1.5, 3, 2]] +U = -np.ones((1, 3)) * 0 +V = -np.ones((1, 3)) * np.linspace(50, 100, 3) +ax.barbs(X, Y, U, V, barbcolor="C1", flagcolor="C1", length=5, linewidth=0.5) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) plt.savefig("../figures/advanced-barbs.pdf") @@ -84,11 +82,12 @@ # Event plot # ----------------------------------------------------------------------------- np.random.seed(1) -X = [2,4,6] +X = [2, 4, 6] D = np.random.gamma(4, size=(3, 50)) -ax.eventplot(D, colors="C1", orientation="vertical", lineoffsets=X, linewidth=0.25) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.eventplot(D, colors="C1", orientation="vertical", lineoffsets=X, + linewidth=0.25) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) plt.savefig("../figures/advanced-event.pdf") @@ -97,28 +96,27 @@ # Errorbar plot # ----------------------------------------------------------------------------- np.random.seed(1) -X = [2,4,6] -Y = [4,5,4] +X = [2, 4, 6] +Y = [4, 5, 4] E = np.random.uniform(0.5, 1.5, 3) ax.errorbar(X, Y, E, color="C1", linewidth=0.75, capsize=1) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) plt.savefig("../figures/advanced-errorbar.pdf") ax.clear() - # Hexbin plot # ----------------------------------------------------------------------------- np.random.seed(1) -X = np.random.uniform(1.5,6.5,100) -Y = np.random.uniform(1.5,6.5,100) -C = np.random.uniform(0,1,10000) +X = np.random.uniform(1.5, 6.5, 100) +Y = np.random.uniform(1.5, 6.5, 100) +C = np.random.uniform(0, 1, 10000) ax.hexbin(X, Y, C, gridsize=4, linewidth=0.25, edgecolor="white", cmap=plt.get_cmap("Wistia"), alpha=1.0) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) plt.savefig("../figures/advanced-hexbin.pdf") @@ -127,10 +125,10 @@ # Hist plot # ----------------------------------------------------------------------------- np.random.seed(1) -X = 4 + np.random.normal(0,1.5,200) -ax.hist(X, bins=8, facecolor="C1", linewidth=0.25, edgecolor="white",) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 80), ax.set_yticks(np.arange(1,80,10)) +X = 4 + np.random.normal(0, 1.5, 200) +ax.hist(X, bins=8, facecolor="C1", linewidth=0.25, edgecolor="white") +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 80), ax.set_yticks(np.arange(1, 80, 10)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) plt.savefig("../figures/advanced-hist.pdf") @@ -143,8 +141,8 @@ X = np.random.uniform(-4, 4, 250) ax.xcorr(X, Y, usevlines=True, maxlags=6, normed=True, lw=1, color="C1") -ax.set_xlim(-8, 8), ax.set_xticks(np.arange(-8,8,2)) -ax.set_ylim(-.25, .25), ax.set_yticks(np.linspace(-.25,.25,9)) +ax.set_xlim(-8, 8), ax.set_xticks(np.arange(-8, 8, 2)) +ax.set_ylim(-.25, .25), ax.set_yticks(np.linspace(-.25, .25, 9)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) plt.savefig("../figures/advanced-xcorr.pdf") diff --git a/scripts/anatomy.py b/scripts/anatomy.py index c188381..35c5661 100644 --- a/scripts/anatomy.py +++ b/scripts/anatomy.py @@ -23,6 +23,7 @@ def minor_tick(x, pos): return "" return "%.2f" % x + ax.xaxis.set_major_locator(MultipleLocator(1.000)) ax.xaxis.set_minor_locator(AutoMinorLocator(4)) ax.yaxis.set_major_locator(MultipleLocator(1.000)) @@ -124,13 +125,13 @@ def text(x, y, text): color = '#000099' ax.annotate('Spines', xy=(4.0, 0.35), xytext=(3.3, 0.5), color=color, - weight='regular', # fontsize="large", fontname="Yanone Kaffeesatz", + weight='regular', # fontsize="large", fontname="Yanone Kaffeesatz", arrowprops=dict(arrowstyle='->', connectionstyle="arc3", color=color)) ax.annotate('', xy=(3.15, 0.0), xytext=(3.45, 0.45), color=color, - weight='regular', # fontsize="large", fontname="Yanone Kaffeesatz", + weight='regular', # fontsize="large", fontname="Yanone Kaffeesatz", arrowprops=dict(arrowstyle='->', connectionstyle="arc3", color=color)) diff --git a/scripts/animation.py b/scripts/animation.py index ace8d48..353808c 100644 --- a/scripts/animation.py +++ b/scripts/animation.py @@ -2,11 +2,15 @@ import matplotlib.pyplot as plt import matplotlib.animation as animation -T = np.linspace(0,2*np.pi,100) +T = np.linspace(0, 2*np.pi, 100) S = np.sin(T) line, = plt.plot(T, S) + + def animate(i): line.set_ydata(np.sin(T+i/50)) + + a=animation.FuncAnimation( plt.gcf(), animate, interval=5) # plt.show() diff --git a/scripts/annotate.py b/scripts/annotate.py index a544bc9..f138bc1 100644 --- a/scripts/annotate.py +++ b/scripts/annotate.py @@ -7,18 +7,17 @@ import matplotlib.pyplot as plt -fig = plt.figure(figsize=(6,1)) -#ax = plt.subplot(111, frameon=False, aspect=.1) +fig = plt.figure(figsize=(6, 1)) +# ax = plt.subplot(111, frameon=False, aspect=.1) # b = 0.0 -ax = fig.add_axes([0,0,1,1], frameon=False, aspect=1) +ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1) - -plt.scatter([5.5],[0.75], s=100, c="k") -plt.xlim(0,6), plt.ylim(0,1) +plt.scatter([5.5], [0.75], s=100, c="k") +plt.xlim(0, 6), plt.ylim(0, 1) plt.xticks([]), plt.yticks([]) -plt.annotate("Annotation", (5.5,.75), (0.1,.75), size=16, va="center", +plt.annotate("Annotation", (5.5, .75), (0.1, .75), size=16, va="center", arrowprops=dict(facecolor='black', shrink=0.05)) plt.text( 5.5, 0.6, "xy\nycoords", size=10, va="top", ha="center", color=".5") diff --git a/scripts/annotation-arrow-styles.py b/scripts/annotation-arrow-styles.py index cb01a81..6bff923 100644 --- a/scripts/annotation-arrow-styles.py +++ b/scripts/annotation-arrow-styles.py @@ -2,15 +2,18 @@ import matplotlib.patches as mpatches styles = mpatches.ArrowStyle.get_styles() + + def demo_con_style(ax, connectionstyle): ax.text(.05, .95, connectionstyle.replace(",", ",\n"), family="Source Code Pro", transform=ax.transAxes, ha="left", va="top", size="x-small") + (fig, axes) = plt.subplots(5, 3, figsize=(4, 2.5), frameon=False) for ax in axes.flatten(): ax.axis("off") -for i,(ax,style) in enumerate(zip(axes.flatten(), mpatches.ArrowStyle.get_styles())): +for i, (ax, style) in enumerate(zip(axes.flatten(), mpatches.ArrowStyle.get_styles())): x0, y0 = 0.8, 0.5 x1, y1 = 0.2, 0.5 ax.plot([x0, x1], [y0, y1], ".", color="0.25") @@ -24,7 +27,7 @@ def demo_con_style(ax, connectionstyle): connectionstyle="arc3,rad=0")) ax.text( (x1+x0)/2, y0-0.2, style, transform=ax.transAxes, - family = "Source Code Pro", ha="center", va="top") + family="Source Code Pro", ha="center", va="top") plt.savefig("../figures/annotation-arrow-styles.pdf") # plt.show() diff --git a/scripts/annotation-connection-styles.py b/scripts/annotation-connection-styles.py index 87c1198..64fa300 100644 --- a/scripts/annotation-connection-styles.py +++ b/scripts/annotation-connection-styles.py @@ -1,5 +1,6 @@ import matplotlib.pyplot as plt + def demo_con_style(ax, connectionstyle): x1, y1 = 0.3, 0.2 x2, y2 = 0.8, 0.6 @@ -16,6 +17,7 @@ def demo_con_style(ax, connectionstyle): family="Source Code Pro", transform=ax.transAxes, ha="left", va="top", size="x-small") + fig, axs = plt.subplots(3, 3, figsize=(5, 5)) demo_con_style(axs[0, 0], "arc3,rad=0") demo_con_style(axs[0, 1], "arc3,rad=0.3") diff --git a/scripts/basic-plots.py b/scripts/basic-plots.py index 4b58e58..d7a0c35 100644 --- a/scripts/basic-plots.py +++ b/scripts/basic-plots.py @@ -8,32 +8,32 @@ import matplotlib as mpl import matplotlib.pyplot as plt -fig = plt.figure(figsize=(0.4,0.4)) +fig = plt.figure(figsize=(0.4, 0.4)) mpl.rcParams['axes.linewidth'] = 0.5 mpl.rcParams['xtick.major.size'] = 0.0 mpl.rcParams['ytick.major.size'] = 0.0 d = 0.01 -ax = fig.add_axes([d,d,1-2*d,1-2*d]) +ax = fig.add_axes([d, d, 1 - 2 * d, 1 - 2 * d]) # Basic line plot # ----------------------------------------------------------------------------- X = np.linspace(0, 10, 100) -Y = 4+2*np.sin(2*X) +Y = 4 + 2*np.sin(2*X) ax.plot(X, Y, color="C1", linewidth=0.75) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.grid(linewidth=0.125) plt.savefig("../figures/basic-plot.pdf") ax.clear() +# Basic line plot (color)blaPwd -# Basic line plot (color) # ----------------------------------------------------------------------------- X = np.linspace(0, 10, 100) -Y = 4+2*np.sin(2*X) +Y = 4 + 2 * np.sin(2 * X) ax.plot(X, Y, color="black", linewidth=0.75) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.grid(linewidth=0.125) plt.savefig("../figures/basic-plot-color.pdf") ax.clear() @@ -41,12 +41,12 @@ # Basic scatter plot # ----------------------------------------------------------------------------- np.random.seed(3) -X = 4+np.random.normal(0, 1.25, 24) -Y = 4+np.random.normal(0, 1.25, len(X)) +X = 4 + np.random.normal(0, 1.25, 24) +Y = 4 + np.random.normal(0, 1.25, len(X)) ax.scatter(X, Y, 5, zorder=10, edgecolor="white", facecolor="C1", linewidth=0.25) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.grid(linewidth=0.125) plt.savefig("../figures/basic-scatter.pdf") ax.clear() @@ -58,23 +58,22 @@ Y = np.random.uniform(2, 7, len(X)) ax.bar(X, Y, bottom=0, width=1, edgecolor="white", facecolor="C1", linewidth=0.25) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) plt.savefig("../figures/basic-bar.pdf") ax.clear() - # Basic imshow plot # ----------------------------------------------------------------------------- np.random.seed(3) -I = np.zeros((8,8,4)) -I[:,:] = mpl.colors.to_rgba("C1") -I[...,3] = np.random.uniform(0.25,1.0,(8,8)) -ax.imshow(I, extent=[0,8,0,8], interpolation="nearest") -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +Z = np.zeros((8, 8, 4)) +Z[:, :] = mpl.colors.to_rgba("C1") +Z[..., 3] = np.random.uniform(0.25, 1.0, (8, 8)) +ax.imshow(Z, extent=[0, 8, 0, 8], interpolation="nearest") +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.grid(linewidth=0.25, color="white") plt.savefig("../figures/basic-imshow.pdf") ax.clear() @@ -83,50 +82,48 @@ # ----------------------------------------------------------------------------- np.random.seed(1) X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256)) -Z = (1 - X/2. + X**5 + Y**3)*np.exp(-X**2-Y**2) +Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2) Z = Z - Z.min() plt.pcolormesh(X, Y, Z, cmap='Oranges', shading='auto') ax.set_xlim(-3, 3), ax.set_xticks(np.arange(-3, 4)) -ax.set_ylim(-3, 3), ax.set_yticks(np.arange(-3,4)) +ax.set_ylim(-3, 3), ax.set_yticks(np.arange(-3, 4)) plt.savefig("../figures/basic-pcolormesh.pdf") ax.clear() # Basic contour plot # ----------------------------------------------------------------------------- -colors = np.zeros((5,4)) +colors = np.zeros((5, 4)) colors[:] = mpl.colors.to_rgba("C1") -colors[:,3] = np.linspace(0.15, 0.85, len(colors)) -plt.contourf(Z, len(colors), extent=[0,8,0,8], colors=colors) -plt.contour(Z, len(colors), extent=[0,8,0,8], colors="white", linewidths=0.125, - nchunk=10) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +colors[:, 3] = np.linspace(0.15, 0.85, len(colors)) +plt.contourf(Z, len(colors), extent=[0, 8, 0, 8], colors=colors) +plt.contour(Z, len(colors), extent=[0, 8, 0, 8], colors="white", + linewidths=0.125, nchunk=10) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) plt.savefig("../figures/basic-contour.pdf") ax.clear() - # Basic pie plot # ----------------------------------------------------------------------------- -X = 1,2,3,4 -colors = np.zeros((len(X),4)) +X = [1, 2, 3, 4] +colors = np.zeros((len(X), 4)) colors[:] = mpl.colors.to_rgba("C1") -colors[:,3] = np.linspace(0.25, 0.75, len(X)) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +colors[:, 3] = np.linspace(0.25, 0.75, len(X)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.25, color="0.75") -ax.pie(X, colors=["white",]*len(X), radius=3, center=(4,4), - wedgeprops = {"linewidth": 0.25, "edgecolor": "white"}, frame=True) -ax.pie(X, colors=colors, radius=3, center=(4,4), - wedgeprops = {"linewidth": 0.25, "edgecolor": "white"}, frame=True) +ax.pie(X, colors=["white"] * len(X), radius=3, center=(4, 4), + wedgeprops={"linewidth": 0.25, "edgecolor": "white"}, frame=True) +ax.pie(X, colors=colors, radius=3, center=(4, 4), + wedgeprops={"linewidth": 0.25, "edgecolor": "white"}, frame=True) plt.savefig("../figures/basic-pie.pdf") ax.clear() - # Basic text plot # ----------------------------------------------------------------------------- -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.25, color="0.75") ax.text(4, 4, "TEXT", color="C1", size=8, weight="bold", @@ -142,8 +139,8 @@ Y2 = 1 + 2*X/8 + np.random.uniform(0.0, 0.5, len(X)) plt.fill_between(X, Y1, Y2, color="C1", alpha=.5, linewidth=0) plt.plot(X, (Y1+Y2)/2, color="C1", linewidth=0.5) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125, color="0.75") plt.savefig("../figures/basic-fill.pdf") @@ -153,12 +150,12 @@ # ----------------------------------------------------------------------------- np.random.seed(1) T = np.linspace(0, 2*np.pi, 8) -X, Y = 4 + 1*np.cos(T), 4 + 1*np.sin(T) +X, Y = 4 + np.cos(T), 4 + np.sin(T) U, V = 1.5*np.cos(T), 1.5*np.sin(T) plt.quiver(X, Y, U, V, color="C1", angles='xy', scale_units='xy', scale=0.5, width=.05) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125, color="0.75") plt.savefig("../figures/basic-quiver.pdf") diff --git a/scripts/colorbar.py b/scripts/colorbar.py index 1a252be..495cccc 100644 --- a/scripts/colorbar.py +++ b/scripts/colorbar.py @@ -7,16 +7,16 @@ import matplotlib.pyplot as plt -fig = plt.figure(figsize=(6,.65)) -#ax = plt.subplot(111, frameon=False, aspect=.1) +fig = plt.figure(figsize=(6, .65)) +# ax = plt.subplot(111, frameon=False, aspect=.1) b = 0.025 -ax = fig.add_axes([b,10*b,1-2*b,1-10*b], frameon=False, aspect=0.05) +ax = fig.add_axes([b, 10*b, 1-2*b, 1-10*b], frameon=False, aspect=0.05) cmap = plt.get_cmap("Oranges") -norm = mpl.colors.Normalize(vmin=0,vmax=1) +norm = mpl.colors.Normalize(vmin=0, vmax=1) sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm) sm.set_array([]) -plt.colorbar(sm, cax=ax, ticks=np.linspace(0,1,11), +plt.colorbar(sm, cax=ax, ticks=np.linspace(0, 1, 11), orientation="horizontal") plt.savefig("../figures/colorbar.pdf") diff --git a/scripts/colormaps.py b/scripts/colormaps.py index 6d7ce45..a0a0f4b 100644 --- a/scripts/colormaps.py +++ b/scripts/colormaps.py @@ -4,7 +4,7 @@ figsize = 4.0, 0.25 fig = plt.figure(figsize=figsize) -ax = fig.add_axes([0,0,1,1], frameon=False, aspect=1) +ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1) ymin, ymax= 0, 1 xmin, xmax = 0, figsize[0]/figsize[1] @@ -13,15 +13,15 @@ cmaps = ('viridis', 'plasma', 'inferno', 'magma', 'cividis', 'PRGn', 'PiYG', 'RdYlGn', 'BrBG', 'RdGy', 'PuOr', 'RdBu', - 'RdYlBu', 'Spectral', 'coolwarm', 'bwr', 'seismic', + 'RdYlBu', 'Spectral', 'coolwarm', 'bwr', 'seismic', 'tab10', 'tab20', 'tab20b', 'tab20c', 'Pastel1', 'Pastel2', 'Paired', 'Set1', 'Set2', 'Set3', 'Accent', 'Dark2', - 'Greys', 'Reds','Oranges', 'YlOrBr', 'YlOrRd', 'OrRd', + 'Greys', 'Reds', 'Oranges', 'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu', 'Purples', 'YlGnBu', 'Blues', - 'PuBu', 'GnBu', 'PuBuGn', 'BuGn','Greens', 'YlGn', + 'PuBu', 'GnBu', 'PuBuGn', 'BuGn', 'Greens', 'YlGn', 'bone', 'gray', 'pink', 'afmhot', 'hot', 'gist_heat', 'copper', 'Wistia', 'autumn', 'summer', 'spring', 'cool', 'winter', @@ -29,7 +29,7 @@ 'twilight', 'twilight_shifted', 'hsv', 'terrain', 'ocean', 'gist_earth', 'cubehelix', 'rainbow' -) + ) for cmap in cmaps: n = 512 @@ -40,7 +40,7 @@ if cmap in ['Pastel2', 'Accent', 'Dark2', 'Set2']: n = 8 if cmap in ['Set3']: n = 12 if cmap in ['Greys']: n = 11 - Z = np.linspace(0,1,n).reshape(1,n) + Z = np.linspace(0, 1, n).reshape(1, n) ax.imshow(Z, extent=[xmin, xmax, ymin, ymax], cmap=plt.get_cmap(cmap)) ax.set_xlim(xmin, xmax), ax.set_xticks([]) diff --git a/scripts/colors.py b/scripts/colors.py index a55f9db..9d323e3 100644 --- a/scripts/colors.py +++ b/scripts/colors.py @@ -9,7 +9,7 @@ figsize = 4.0, 0.25 fig = plt.figure(figsize=figsize) -ax = fig.add_axes([0,0,1,1], frameon=False, aspect=1) +ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1) ymin, ymax= 0, 1 xmin, xmax = 0, figsize[0]/figsize[1] ax.set_xlim(xmin, xmax), ax.set_xticks([]) @@ -19,14 +19,14 @@ # ----------------------------------------------------------------------------- palettes = { '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)], + '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)], 'name' : ["DarkRed", "Firebrick", "Crimson", "IndianRed", "Salmon" ] } for name, colors in palettes.items(): - C = mpl.colors.to_rgba_array(colors).reshape((1,len(colors),4)) + C = mpl.colors.to_rgba_array(colors).reshape((1, len(colors), 4)) ax.imshow(C, extent=[xmin, xmax, ymin, ymax]) dx = (xmax-xmin)/len(colors) for i in range(len(colors)): @@ -34,7 +34,7 @@ if colors[i] in ['1.0', 'w']: color = "black" text = str(colors[i]).replace(' ', '') ax.text((i+0.5)*dx, (ymin+ymax)/2, text, color=color, zorder=10, - family = "Source Code Pro", size=9, ha="center", va="center") + family="Source Code Pro", size=9, ha="center", va="center") plt.savefig("../figures/colors-%s.pdf" % name) ax.clear() diff --git a/scripts/extents.py b/scripts/extents.py index 33bccd5..28a0236 100644 --- a/scripts/extents.py +++ b/scripts/extents.py @@ -8,14 +8,14 @@ import matplotlib as mpl import matplotlib.pyplot as plt -Z = np.arange(5*5).reshape(5,5) +Z = np.arange(5*5).reshape(5, 5) -fig = plt.figure(figsize=(8,5)) +fig = plt.figure(figsize=(8, 5)) -ax = fig.add_subplot(2,2,1) -ax.imshow(Z, extent=[0,10,0,5], interpolation="nearest", origin="upper") +ax = fig.add_subplot(2, 2, 1) +ax.imshow(Z, extent=[0, 10, 0, 5], interpolation="nearest", origin="upper") ax.set_xlim(-1, 11), ax.set_xticks([]) -ax.set_ylim(-1, 6), ax.set_yticks([0,5]) +ax.set_ylim(-1, 6), ax.set_yticks([0, 5]) ax.text(1, 4.5, "(0,0)", ha="center", va="center", color="white", size="large") ax.text(9, 0.5, "(4,4)", ha="center", va="center", color="black", size="large") ax.text(5.0, 5.5, 'origin="upper"', @@ -23,10 +23,10 @@ ax.text(5.0, -0.5, "extent=[0,10,0,5]", ha="center", va="center", color="black", size="large") -ax = fig.add_subplot(2,2,3) -ax.imshow(Z, extent=[0,10,0,5], interpolation="nearest", origin="lower") -ax.set_xlim(-1, 11), ax.set_xticks([0,10]) -ax.set_ylim(-1, 6), ax.set_yticks([0,5]) +ax = fig.add_subplot(2, 2, 3) +ax.imshow(Z, extent=[0, 10, 0, 5], interpolation="nearest", origin="lower") +ax.set_xlim(-1, 11), ax.set_xticks([0, 10]) +ax.set_ylim(-1, 6), ax.set_yticks([0, 5]) ax.text(1, 0.5, "(0,0)", ha="center", va="center", color="white", size="large") ax.text(9, 4.5, "(4,4)", ha="center", va="center", color="black", size="large") @@ -36,9 +36,9 @@ ha="center", va="center", color="black", size="large") -ax = fig.add_subplot(2,2,4) -ax.imshow(Z, extent=[10,0,0,5], interpolation="nearest", origin="lower") -ax.set_xlim(-1, 11), ax.set_xticks([0,10]) +ax = fig.add_subplot(2, 2, 4) +ax.imshow(Z, extent=[10, 0, 0, 5], interpolation="nearest", origin="lower") +ax.set_xlim(-1, 11), ax.set_xticks([0, 10]) ax.set_ylim(-1, 6), ax.set_yticks([]) ax.text(9, 0.5, "(0,0)", ha="center", va="center", color="white", size="large") ax.text(1, 4.5, "(4,4)", ha="center", va="center", color="black", size="large") @@ -49,8 +49,8 @@ plt.tight_layout() -ax = fig.add_subplot(2,2,2) -ax.imshow(Z, extent=[10,0,0,5], interpolation="nearest", origin="upper") +ax = fig.add_subplot(2, 2, 2) +ax.imshow(Z, extent=[10, 0, 0, 5], interpolation="nearest", origin="upper") ax.set_xlim(-1, 11), ax.set_xticks([]) ax.set_ylim(-1, 6), ax.set_yticks([]) ax.text(9, 4.5, "(0,0)", ha="center", va="center", color="white", size="large") diff --git a/scripts/fonts.py b/scripts/fonts.py index 385286f..d164ae7 100644 --- a/scripts/fonts.py +++ b/scripts/fonts.py @@ -8,8 +8,8 @@ fig = plt.figure(figsize=(4.25, 3.8)) -ax = fig.add_axes([0,0,1,1], frameon=False, xticks=[], yticks=[], - xlim=[0,40], ylim=[0,38]) +ax = fig.add_axes([0, 0, 1, 1], frameon=False, xticks=[], yticks=[], + xlim=[0, 40], ylim=[0, 38]) y = 1 @@ -20,13 +20,13 @@ } text = "The quick brown fox jumps over the lazy dog" -for i,variant in enumerate(variants.keys()): +for i, variant in enumerate(variants.keys()): ax.text(1, y, text, size=9, va="center", font=pathlib.Path(variants[variant]).resolve()) ax.text(39, y, variant, color="0.25", va="center", ha="right", - size="small", family = "Source Code Pro", weight = 400) + size="small", family="Source Code Pro", weight=400) y += 1.65 y += 1 @@ -34,13 +34,13 @@ styles = ["normal", "italic"] text = "The quick brown fox jumps over the lazy dog" -for i,style in enumerate(styles): +for i, style in enumerate(styles): ax.text(1, y, text, size=9, va="center", style=style, - family = "Source Sans Pro") + family="Source Sans Pro") ax.text(39, y, style, color="0.25", va="center", ha="right", - size="small", family = "Source Code Pro", weight = 400) + size="small", family="Source Code Pro", weight=400) y += 1.65 y += 1 @@ -53,14 +53,14 @@ "Source Code Pro" : "monospace" } text = "The quick brown fox jumps over the lazy dog" -for i,family in enumerate(families): +for i, family in enumerate(families): ax.text(1, y, text, - va="center", size=9, family = family, weight = "regular") + va="center", size=9, family=family, weight="regular") ax.text(39, y, "%s" % (families[family]), color="0.25", va="center", ha="right", - size="small", family = "Source Code Pro", weight = 400) + size="small", family="Source Code Pro", weight=400) y += 1.65 y += 1 @@ -77,13 +77,13 @@ 'black' : 900 } text = "The quick brown fox jumps over the lazy dog" -for i,weight in enumerate(["ultralight","normal","semibold","bold","black"]): +for i, weight in enumerate(["ultralight", "normal", "semibold", "bold", "black"]): ax.text(1, y, text, size=9, - va="center", family = "Source Sans Pro", weight = weight) + va="center", family="Source Sans Pro", weight=weight) ax.text(39, y, "%s (%d)" % (weight, weights[weight]), color="0.25", va="center", ha="right", - size="small", family = "Source Code Pro", weight = 400) + size="small", family="Source Code Pro", weight=400) y += 1.65 y += 1 @@ -97,13 +97,13 @@ "xx-large" : 1.728 } text = "The quick brown fox" -for i,size in enumerate(sizes.keys()): +for i, size in enumerate(sizes.keys()): ax.text(1, y, text, size=size, - ha="left", va="center", family = "Source Sans Pro", weight="light") + ha="left", va="center", family="Source Sans Pro", weight="light") ax.text(39, y, "%s (%.2f)" % (size, sizes[size]), color="0.25", va="center", ha="right", - size="small", family = "Source Code Pro", weight = 400) + size="small", family="Source Code Pro", weight=400) y += 1.65* max(sizes[size], sizes["small"]) diff --git a/scripts/interpolations.py b/scripts/interpolations.py index 8083b72..2a135ef 100644 --- a/scripts/interpolations.py +++ b/scripts/interpolations.py @@ -6,14 +6,14 @@ 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos'] np.random.seed(1) -Z = np.random.uniform(0,1,(3,3)) +Z = np.random.uniform(0, 1, (3, 3)) -fig, axs = plt.subplots(nrows=6, ncols=3, figsize=(4.5,9), +fig, axs = plt.subplots(nrows=6, ncols=3, figsize=(4.5, 9), subplot_kw={'xticks': [], 'yticks': []}) for ax, interp_method in zip(axs.flat, methods): ax.imshow(Z, interpolation=interp_method, cmap='viridis', - extent=[0,9,0,9], rasterized=True) + extent=[0, 9, 0, 9], rasterized=True) ax.text(4.5, 1, str(interp_method), weight="bold", color="white", size=12, transform=ax.transData, ha="center", va="center") diff --git a/scripts/layouts.py b/scripts/layouts.py index 25388f2..9438c5d 100644 --- a/scripts/layouts.py +++ b/scripts/layouts.py @@ -5,15 +5,16 @@ import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt +from mpl_toolkits.axes_grid1 import make_axes_locatable -fig = plt.figure(figsize=(0.4,0.4)) +fig = plt.figure(figsize=(0.4, 0.4)) margin = 0.01 fig.subplots_adjust(left=margin, right=1-margin, top=1-margin, bottom=margin) mpl.rc('axes', linewidth=.5) # Subplots # ----------------------------------------------------------------------------- -nrows, ncols = 3,3 +nrows, ncols = 3, 3 for i in range(nrows*ncols): ax = plt.subplot(ncols, nrows, i+1) ax.set_xticks([]), ax.set_yticks([]) @@ -22,7 +23,7 @@ # Subplots (colored) # ----------------------------------------------------------------------------- -nrows, ncols = 3,3 +nrows, ncols = 3, 3 for i in range(nrows*ncols): ax = plt.subplot(ncols, nrows, i+1) ax.set_xticks([]), ax.set_yticks([]) @@ -33,7 +34,7 @@ # Spines # ----------------------------------------------------------------------------- -ax = fig.add_subplot(1,1,1, xticks=[], yticks=[]) +ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[]) ax.spines["top"].set_color("None") ax.spines["right"].set_color("None") plt.savefig("../figures/layout-spines.pdf") @@ -67,7 +68,7 @@ # ----------------------------------------------------------------------------- mpl.rc('axes', linewidth=.5) margin = 0.0125 -ax1 = fig.add_axes([margin,margin,1-2*margin,1-2*margin], xticks=[], yticks=[]) +ax1 = fig.add_axes([margin, margin, 1-2*margin, 1-2*margin], xticks=[], yticks=[]) ax2 = ax1.inset_axes([0.5, 0.5, 0.4, 0.4], xticks=[], yticks=[]) plt.savefig("../figures/layout-inset.pdf") fig.clear() @@ -75,9 +76,8 @@ # Axes divider # ----------------------------------------------------------------------------- -from mpl_toolkits.axes_grid1 import make_axes_locatable margin = 0.0125 -ax = fig.add_axes([margin,margin,1-2*margin,1-2*margin], xticks=[], yticks=[]) +ax = fig.add_axes([margin, margin, 1-2*margin, 1-2*margin], xticks=[], yticks=[]) divider = make_axes_locatable(ax) cax = divider.new_horizontal(size="10%", pad=0.025) fig.add_axes(cax) diff --git a/scripts/legend.py b/scripts/legend.py index 32f01ed..5269ff9 100644 --- a/scripts/legend.py +++ b/scripts/legend.py @@ -7,44 +7,47 @@ import matplotlib.pyplot as plt -fig = plt.figure(figsize=(4,4)) -ax = fig.add_axes([0.15,0.15,.7,.7], frameon=True, aspect=1, +fig = plt.figure(figsize=(4, 4)) +ax = fig.add_axes([0.15, 0.15, .7, .7], frameon=True, aspect=1, xticks=[], yticks=[]) + def text(x, y, _text): color= "C1" - if not 0 < x < 1 or not 0 < y < 1: color = "C0" + if not 0 < x < 1 or not 0 < y < 1: color = "C0" size = 0.15 - ax.text(x, y, _text, color="white", #bbox={"color": "C1"}, + ax.text(x, y, _text, color="white", # bbox={"color": "C1"}, size="xx-large", weight="bold", ha="center", va="center") rect = plt.Rectangle((x-size/2, y-size/2), size, size, facecolor=color, zorder=-10, clip_on=False) ax.add_patch(rect) + def point(x, y): ax.scatter([x], [y], facecolor="C0", edgecolor="white", zorder=10, clip_on=False) + d = .1 e = .15/2 -text( d, d, "3"), text( 0.5, d, "8"), text(1-d, d, "4") +text( d, d, "3"), text( 0.5, d, "8"), text(1-d, d, "4") text( d, 0.5, "6"), text( 0.5, 0.5, "10"), text(1-d, 0.5, "7") text( d, 1-d, "2"), text( 0.5, 1-d, "9"), text(1-d, 1-d, "1") -text( -d, 1-d, "A"), text( -d, 0.5, "B"), text( -d, d, "C") +text( -d, 1-d, "A"), text( -d, 0.5, "B"), text( -d, d, "C") point(-d+e, 1-d+e), point(-d+e, 0.5), point(-d+e, d-e), -text( d, -d, "D"), text(0.5, -d, "E"), text( 1-d, -d, "F") +text( d, -d, "D"), text(0.5, -d, "E"), text( 1-d, -d, "F") point(d-e, -d+e), point(0.5, -d+e), point(1-d+e, -d+e), -text(1+d, d, "G"), text(1+d, 0.5, "H"), text( 1+d, 1-d, "I") +text(1+d, d, "G"), text(1+d, 0.5, "H"), text( 1+d, 1-d, "I") point(1+d-e, d-e), point(1+d-e, .5), point(1+d-e, 1-d+e), text(1-d, 1+d, "J"), text(0.5, 1+d, "K"), text( d, 1+d, "L") point(1-d+e, 1+d-e), point(0.5, 1+d-e), point(d-e, 1+d-e), -plt.xlim(0,1), plt.ylim(0,1) +plt.xlim(0, 1), plt.ylim(0, 1) plt.savefig("../figures/legend-placement.pdf") # plt.show() diff --git a/scripts/linestyles.py b/scripts/linestyles.py index 7826085..b1c619e 100644 --- a/scripts/linestyles.py +++ b/scripts/linestyles.py @@ -6,11 +6,12 @@ import matplotlib.pyplot as plt -fig = plt.figure(figsize=(4.25,2*.55)) -ax = fig.add_axes([0,0,1,1], xlim=[0.75,10.25], ylim=[0.5,2.5], frameon=False, - xticks=[], yticks=[]) +fig = plt.figure(figsize=(4.25, 2*.55)) +ax = fig.add_axes([0, 0, 1, 1], xlim=[0.75, 10.25], ylim=[0.5, 2.5], frameon=False, + xticks=[], yticks=[]) y = 2 + def split(n_segment): width = 9 segment_width = 0.75*(width/n_segment) @@ -23,17 +24,17 @@ def split(n_segment): # Line style # ---------------------------------------------------------------------------- X0, X1 = split(5) -styles = "-", ":", "--", "-.", (0,(0.01,2)) +styles = "-", ":", "--", "-.", (0, (0.01, 2)) -for x0,x1,style in zip(X0,X1,styles): - ax.plot([x0,x1],[y,y], color="C1", linestyle=style, +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(' ','') + if isinstance(style, str): text = '"%s"' % style + else: text = '%s' % str(style) + text = text.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", +ax.text(X0[0]-0.25, y+0.2, "linestyle or ls", family="Source Code Pro", size=14, ha="left", va="baseline") y -= 1 @@ -41,14 +42,14 @@ def split(n_segment): # ---------------------------------------------------------------------------- X0, X1 = split(3) styles = "butt", "round", "projecting" -for x0,x1,style in zip(X0,X1,styles): - ax.plot([x0,x1],[y,y], color="C1", dash_capstyle="projecting", +for x0, x1, style in zip(X0, X1, styles): + ax.plot([x0, x1], [y, y], color="C1", dash_capstyle="projecting", linewidth=7, linestyle="--", alpha=.25) - ax.plot([x0,x1],[y,y], color="C1", linewidth=7, + 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, '"%s"' % style, 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", +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 d4ce894..50c5e36 100644 --- a/scripts/markers.py +++ b/scripts/markers.py @@ -8,30 +8,30 @@ # Markers # ----------------------------------------------------------------------------- -fig = plt.figure(figsize=(3.5,1.5)) -ax = fig.add_axes([0,0,1,1], frameon=False, - xlim=[0.5,10.5], ylim=[0.0,4.35], xticks=[], yticks=[]) -X = np.linspace(1,10,12) -Y = np.arange(1,4) -X, Y = np.meshgrid(X,Y) -X ,Y = X.ravel(), Y.ravel() +fig = plt.figure(figsize=(3.5, 1.5)) +ax = fig.add_axes([0, 0, 1, 1], frameon=False, + xlim=[0.5, 10.5], ylim=[0.0, 4.35], xticks=[], yticks=[]) +X = np.linspace(1, 10, 12) +Y = np.arange(1, 4) +X, Y = np.meshgrid(X, Y) +X , Y = X.ravel(), Y.ravel() plt.scatter(X, 1+Y, s=256, marker="s", fc="C1", ec="none", alpha=.25) markers = [ - "$♠$", "$♣$", "$♥$","$♦$", "$→$","$←$","$↑$","$↓$", "$◐$","$◑$","$◒$","$◓$", + "$♠$", "$♣$", "$♥$", "$♦$", "$→$", "$←$", "$↑$", "$↓$", "$◐$", "$◑$", "$◒$", "$◓$", "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" +for x, y, marker in zip(X, Y, markers): + if y == 3: fc = "white" elif y == 2: fc = "None" - else: fc = "C1" + else: fc = "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 + if isinstance(marker, str): text = "'%s'" % marker + else: text = '%s' % marker plt.text(x, 1+y-0.4, text, - size="x-small", ha="center", va="top", family="Monospace") + size="x-small", ha="center", va="top", family="Monospace") # Spacing @@ -40,9 +40,9 @@ segment_width = 0.75*(width/n_segment) segment_pad = (width - n_segment*segment_width)/(n_segment-1) X0 = 1+np.arange(n_segment)*(segment_width+segment_pad) -marks = [ 10, [0,-1], (25, 5), [0,25,-1] ] +marks = [ 10, [0, -1], (25, 5), [0, 25, -1] ] y = .6 -for x0, mark in zip(X0,marks): +for x0, mark in zip(X0, marks): X = np.linspace(x0, x0+segment_width, 50) Y = y*np.ones(len(X)) ax.plot(X, Y, linewidth=1, color="black", diff --git a/scripts/performance-tips.py b/scripts/performance-tips.py index 0094a1b..adbfaa1 100644 --- a/scripts/performance-tips.py +++ b/scripts/performance-tips.py @@ -11,8 +11,8 @@ n = 10_000_000 np.random.seed(1) -X = np.random.uniform(0,1,n) -Y = np.random.uniform(0,1,n) +X = np.random.uniform(0, 1, n) +Y = np.random.uniform(0, 1, n) start = time.perf_counter() ax.plot(X, Y, marker="o", ls="") @@ -32,8 +32,8 @@ np.random.seed(1) X = [] for i in range(n): - X.append(np.random.uniform(0,1,10)) -#np.random.uniform(0,1,n) + X.append(np.random.uniform(0, 1, 10)) +# np.random.uniform(0,1,n) # Y = np.random.uniform(0,1,n) start = time.perf_counter() @@ -45,7 +45,7 @@ ax.clear() start = time.perf_counter() -ax.plot(sum([list(x)+[None] for x in X],[])) +ax.plot(sum([list(x)+[None] for x in X], [])) # X0,Y0 = X[0::2], Y[0::2] # X1,Y1 = X[1::2], Y[1::2] # S = [None]*len(X) diff --git a/scripts/plot-variations.py b/scripts/plot-variations.py index bbcb9a1..ad4cc30 100644 --- a/scripts/plot-variations.py +++ b/scripts/plot-variations.py @@ -8,7 +8,7 @@ import matplotlib as mpl import matplotlib.pyplot as plt -fig = plt.figure(figsize=(0.4,0.4)) +fig = plt.figure(figsize=(0.4, 0.4)) mpl.rcParams['axes.linewidth'] = 0.5 mpl.rcParams['xtick.major.size'] = 0.0 mpl.rcParams['ytick.major.size'] = 0.0 @@ -16,85 +16,85 @@ # Basic line plot (color) # ----------------------------------------------------------------------------- -ax = fig.add_axes([d,d,1-2*d,1-2*d]) +ax = fig.add_axes([d, d, 1-2*d, 1-2*d]) X = np.linspace(0, 10, 100) Y = 4+2*np.sin(2*X) ax.plot(X, Y, color="black", linewidth=0.75) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.grid(linewidth=0.125) plt.savefig("../figures/plot-color.pdf") fig.clear() # Basic line plot (linestyle) # ----------------------------------------------------------------------------- -ax = fig.add_axes([d,d,1-2*d,1-2*d]) +ax = fig.add_axes([d, d, 1-2*d, 1-2*d]) X = np.linspace(0, 10, 100) Y = 4+2*np.sin(2*X) ax.plot(X, Y, color="C1", linewidth=0.75, linestyle="--") -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.grid(linewidth=0.125) plt.savefig("../figures/plot-linestyle.pdf") fig.clear() # Basic line plot (linewidth) # ----------------------------------------------------------------------------- -ax = fig.add_axes([d,d,1-2*d,1-2*d]) +ax = fig.add_axes([d, d, 1-2*d, 1-2*d]) X = np.linspace(0, 10, 100) Y = 4+2*np.sin(2*X) ax.plot(X, Y, color="C1", linewidth=1.5) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.grid(linewidth=0.125) plt.savefig("../figures/plot-linewidth.pdf") fig.clear() # Basic line plot (marker) # ----------------------------------------------------------------------------- -ax = fig.add_axes([d,d,1-2*d,1-2*d]) +ax = fig.add_axes([d, d, 1-2*d, 1-2*d]) X = np.linspace(0, 10, 100) Y = 4+2*np.sin(2*X) ax.plot(X, Y, color="C1", linewidth=0.75, marker="o", markevery=5, markersize=2) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.grid(linewidth=0.125) plt.savefig("../figures/plot-marker.pdf") fig.clear() # Basic line plot (multi) # ----------------------------------------------------------------------------- -ax = fig.add_axes([d,d,1-2*d,1-2*d]) +ax = fig.add_axes([d, d, 1-2*d, 1-2*d]) X = np.linspace(0, 10, 100) Y1 = 4+2*np.sin(2*X) Y2 = 4+2*np.cos(2*X) ax.plot(X, Y1, color="C1", linewidth=0.75) ax.plot(X, Y2, color="C0", linewidth=0.75) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.grid(linewidth=0.125) plt.savefig("../figures/plot-multi.pdf") fig.clear() # Basic line plot (vsplit) # ----------------------------------------------------------------------------- -ax1 = fig.add_axes([d, d, 1-2*d,.45-d]) -ax2 = fig.add_axes([d, .55-d, 1-2*d,.45-d]) +ax1 = fig.add_axes([d, d, 1-2*d, .45-d]) +ax2 = fig.add_axes([d, .55-d, 1-2*d, .45-d]) X = np.linspace(0, 10, 100) Y1 = 2+1*np.sin(2*X) ax1.plot(X, Y1, color="C1", linewidth=0.75) -ax1.set_xlim(0, 8), ax1.set_xticks(np.arange(1,8)), ax1.set_xticklabels([]) -ax1.set_ylim(0, 4), ax1.set_yticks(np.arange(1,4)), ax1.set_yticklabels([]) +ax1.set_xlim(0, 8), ax1.set_xticks(np.arange(1, 8)), ax1.set_xticklabels([]) +ax1.set_ylim(0, 4), ax1.set_yticks(np.arange(1, 4)), ax1.set_yticklabels([]) ax1.grid(linewidth=0.125) -ax1.tick_params(axis=u'both', which=u'both',length=0) +ax1.tick_params(axis=u'both', which=u'both', length=0) Y2 = 2+1*np.cos(2*X) ax2.plot(X, Y2, color="C0", linewidth=0.75) -ax2.set_xlim(0, 8), ax2.set_xticks(np.arange(1,8)), ax2.set_xticklabels([]) -ax2.set_ylim(0, 4), ax2.set_yticks(np.arange(1,4)), ax2.set_yticklabels([]) +ax2.set_xlim(0, 8), ax2.set_xticks(np.arange(1, 8)), ax2.set_xticklabels([]) +ax2.set_ylim(0, 4), ax2.set_yticks(np.arange(1, 4)), ax2.set_yticklabels([]) ax2.grid(linewidth=0.125) -ax2.tick_params(axis=u'both', which=u'both',length=0) +ax2.tick_params(axis=u'both', which=u'both', length=0) plt.savefig("../figures/plot-vsplit.pdf") fig.clear() @@ -106,28 +106,28 @@ X = np.linspace(0, 10, 100) Y1 = 2+1*np.sin(2*X) ax1.plot(Y1, X, color="C1", linewidth=0.75) -ax1.set_xlim(0, 4), ax1.set_xticks(np.arange(1,4)), ax1.set_xticklabels([]) -ax1.set_ylim(0, 8), ax1.set_yticks(np.arange(1,8)), ax1.set_yticklabels([]) +ax1.set_xlim(0, 4), ax1.set_xticks(np.arange(1, 4)), ax1.set_xticklabels([]) +ax1.set_ylim(0, 8), ax1.set_yticks(np.arange(1, 8)), ax1.set_yticklabels([]) ax1.grid(linewidth=0.125) -ax1.tick_params(axis=u'both', which=u'both',length=0) +ax1.tick_params(axis=u'both', which=u'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.set_xticklabels([]) -ax2.set_ylim(0, 8), ax2.set_yticks(np.arange(1,8)), ax2.set_yticklabels([]) +ax2.set_xlim(0, 4), ax2.set_xticks(np.arange(1, 4)), ax2.set_xticklabels([]) +ax2.set_ylim(0, 8), ax2.set_yticks(np.arange(1, 8)), ax2.set_yticklabels([]) ax2.grid(linewidth=0.125) -ax2.tick_params(axis=u'both', which=u'both',length=0) +ax2.tick_params(axis=u'both', which=u'both', length=0) plt.savefig("../figures/plot-hsplit.pdf") fig.clear() # Basic line plot (title) # ----------------------------------------------------------------------------- -ax = fig.add_axes([d,d,1-2*d,.8-2*d]) +ax = fig.add_axes([d, d, 1-2*d, .8-2*d]) X = np.linspace(0, 10, 100) Y = 3+2*np.sin(2*X) ax.plot(X, Y, color="C1", linewidth=0.75) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)) -ax.set_ylim(0, 6), ax.set_yticks(np.arange(1,6)) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) +ax.set_ylim(0, 6), ax.set_yticks(np.arange(1, 6)) ax.grid(linewidth=0.125) ax.text(4, 6.75, "A Sine wave", transform=ax.transData, clip_on=False, weight="bold", size=4, ha="center", va="center") @@ -137,12 +137,12 @@ # Basic line plot (xlabel) # ----------------------------------------------------------------------------- -ax = fig.add_axes([d,.2-d,1-2*d,.8-2*d]) +ax = fig.add_axes([d, .2-d, 1-2*d, .8-2*d]) X = np.linspace(0, 10, 100) Y = 3+2*np.sin(2*X) ax.plot(X, Y, color="C1", linewidth=0.75) -ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8)), ax.set_xticklabels([]) -ax.set_ylim(0, 6), ax.set_yticks(np.arange(1,6)), ax.set_yticklabels([]) +ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)), ax.set_xticklabels([]) +ax.set_ylim(0, 6), ax.set_yticks(np.arange(1, 6)), ax.set_yticklabels([]) ax.grid(linewidth=0.125) ax.text(4, -1, "Time", transform=ax.transData, clip_on=False, size=3.5, ha="center", va="center") diff --git a/scripts/projections.py b/scripts/projections.py index f659ff1..a262050 100644 --- a/scripts/projections.py +++ b/scripts/projections.py @@ -15,16 +15,16 @@ # Taken from https://github.com/SciTools/cartopy/issues/1325#issuecomment-904343657 target_path_template = cartopy.io.shapereader.NEShpDownloader.default_downloader().target_path_template downloader = cartopy.io.shapereader.NEShpDownloader(url_template=CARTOPY_SOURCE_TEMPLATE, - target_path_template=target_path_template) + target_path_template=target_path_template) cartopy.config['downloaders'][('shapefiles', 'natural_earth')] = downloader # Polar plot # ----------------------------------------------------------------------------- mpl.rc('axes', linewidth=4.0) -fig = plt.figure(figsize=(4,4)) +fig = plt.figure(figsize=(4, 4)) b = 0.025 -ax = fig.add_axes([b,b,1-2*b,1-2*b], projection="polar") +ax = fig.add_axes([b, b, 1-2*b, 1-2*b], projection="polar") T = np.linspace(0, 3*2*np.pi, 500) R = np.linspace(0, 2, len(T)) ax.plot(T, R, color="C1", linewidth=6) @@ -32,7 +32,7 @@ ax.set_xticklabels([]) ax.set_yticks(np.linspace(0, 2, 8)) ax.set_yticklabels([]) -ax.set_ylim(0,2) +ax.set_ylim(0, 2) ax.grid(linewidth=1) plt.savefig("../figures/projection-polar.pdf") fig.clear() @@ -40,7 +40,7 @@ # 3D plot # ----------------------------------------------------------------------------- mpl.rc('axes', linewidth=2.0) -ax = fig.add_axes([0,.1,1,.9], projection="3d") +ax = fig.add_axes([0, .1, 1, .9], projection="3d") r = np.linspace(0, 1.25, 50) p = np.linspace(0, 2*np.pi, 50) R, P = np.meshgrid(r, p) @@ -60,7 +60,7 @@ # ----------------------------------------------------------------------------- mpl.rc('axes', linewidth=3.0) b = 0.025 -ax = fig.add_axes([b,b,1-2*b,1-2*b], frameon=False, +ax = fig.add_axes([b, b, 1-2*b, 1-2*b], frameon=False, projection=cartopy.crs.Orthographic()) ax.add_feature(cartopy.feature.LAND, zorder=0, facecolor="C1", edgecolor="0.0", linewidth=0) diff --git a/scripts/scales.py b/scripts/scales.py index 508bb4c..7520d00 100644 --- a/scripts/scales.py +++ b/scripts/scales.py @@ -1,11 +1,11 @@ import numpy as np import matplotlib.pyplot as plt -fig = plt.figure(figsize=(0.4,2/3*0.4)) -ax = fig.add_axes([0,0,1,1], frameon=False) +fig = plt.figure(figsize=(0.4, 2/3*0.4)) +ax = fig.add_axes([0, 0, 1, 1], frameon=False) ax.tick_params(axis='both', which='both', length=0) -ax.set_xlim(-2,2) -X = np.linspace(-2,+2,1001) +ax.set_xlim(-2, 2) +X = np.linspace(-2, +2, 1001) Y = np.sin(X*2.5*2*np.pi) @@ -14,11 +14,11 @@ ax.set_xlim(X.min(), X.max()) ax.set_xscale("linear") ax.plot(X, Y, color="C1", linewidth=0.75) -ax.set_ylim(-2.5,1.5) +ax.set_ylim(-2.5, 1.5) ax.text(0, 0.12, "-∞", ha="left", va="bottom", size=3, transform=ax.transAxes) -ax.text(0, 0.15, "⇤", ha="left", va="top", size=4, transform=ax.transAxes) +ax.text(0, 0.15, "⇤", ha="left", va="top", size=4, transform=ax.transAxes) ax.text(1, 0.12, "+∞", ha="right", va="bottom", size=3, transform=ax.transAxes) -ax.text(1, 0.15, "⇥", ha="right", va="top", size=4, transform=ax.transAxes) +ax.text(1, 0.15, "⇥", ha="right", va="top", size=4, transform=ax.transAxes) plt.savefig("../figures/scale-linear.pdf") ax.clear() @@ -26,11 +26,11 @@ # ----------------------------------------------------------------------------- ax.set_xscale("log", base=10) ax.plot(X, Y, color="C1", linewidth=0.75) -ax.set_ylim(-2.5,1.5) +ax.set_ylim(-2.5, 1.5) ax.text(0, 0.12, "0", ha="left", va="bottom", size=3, transform=ax.transAxes) -ax.text(0, 0.15, "⇤", ha="left", va="top", size=4, transform=ax.transAxes) +ax.text(0, 0.15, "⇤", ha="left", va="top", size=4, transform=ax.transAxes) ax.text(1, 0.12, "+∞", ha="right", va="bottom", size=3, transform=ax.transAxes) -ax.text(1, 0.15, "⇥", ha="right", va="top", size=4, transform=ax.transAxes) +ax.text(1, 0.15, "⇥", ha="right", va="top", size=4, transform=ax.transAxes) plt.savefig("../figures/scale-log.pdf") ax.clear() @@ -38,11 +38,11 @@ # ----------------------------------------------------------------------------- ax.set_xscale("symlog", base=10, linthresh=1) ax.plot(X, Y, color="C1", linewidth=0.75) -ax.set_ylim(-2.5,1.5) +ax.set_ylim(-2.5, 1.5) ax.text(0, 0.12, "-∞", ha="left", va="bottom", size=3, transform=ax.transAxes) -ax.text(0, 0.15, "⇤", ha="left", va="top", size=4, transform=ax.transAxes) +ax.text(0, 0.15, "⇤", ha="left", va="top", size=4, transform=ax.transAxes) ax.text(1, 0.12, "+∞", ha="right", va="bottom", size=3, transform=ax.transAxes) -ax.text(1, 0.15, "⇥", ha="right", va="top", size=4, transform=ax.transAxes) +ax.text(1, 0.15, "⇥", ha="right", va="top", size=4, transform=ax.transAxes) plt.savefig("../figures/scale-symlog.pdf") ax.clear() @@ -50,10 +50,10 @@ # ----------------------------------------------------------------------------- ax.set_xscale("logit") ax.plot(X, Y, color="C1", linewidth=0.75) -ax.set_ylim(-2.5,1.5) +ax.set_ylim(-2.5, 1.5) ax.text(0, 0.12, "0", ha="left", va="bottom", size=3, transform=ax.transAxes) -ax.text(0, 0.15, "⇤", ha="left", va="top", size=4, transform=ax.transAxes) +ax.text(0, 0.15, "⇤", ha="left", va="top", size=4, transform=ax.transAxes) ax.text(1, 0.12, "1", ha="right", va="bottom", size=3, transform=ax.transAxes) -ax.text(1, 0.15, "⇥", ha="right", va="top", size=4, transform=ax.transAxes) +ax.text(1, 0.15, "⇥", ha="right", va="top", size=4, transform=ax.transAxes) plt.savefig("../figures/scale-logit.pdf") ax.clear() diff --git a/scripts/sine.py b/scripts/sine.py index bf39a71..c31c49f 100644 --- a/scripts/sine.py +++ b/scripts/sine.py @@ -8,32 +8,32 @@ X = np.linspace(0.1, 10*np.pi, 10000) Y = np.sin(X) -fig = plt.figure(figsize=(8,2)) +fig = plt.figure(figsize=(8, 2)) plt.plot(X, Y, color="orange", linewidth=2) # plt.xticks([]), plt.yticks([]) plt.tight_layout() plt.savefig("../figures/sine.pdf", dpi=100) -fig = plt.figure(figsize=(7,1.5)) -plt.plot(X, Y, "C1o:", markevery=500, mec="1.0", lw=2, ms=8.5, mew=2) +fig = plt.figure(figsize=(7, 1.5)) +plt.plot(X, Y, "C1o:", markevery=500, mec="1.0", lw=2, ms=8.5, mew=2) # plt.xticks([]), plt.yticks([]) plt.ylim(-1.5, 1.5) plt.tight_layout() plt.savefig("../figures/sine-marker.pdf", dpi=100) -fig, ax = plt.subplots(figsize=(7,1.5)) +fig, ax = plt.subplots(figsize=(7, 1.5)) ax.set_xscale("log") ax.plot(X, Y, "-") -plt.plot(X, Y, "C1o-", markevery=500, mec="1.0", lw=2, ms=8.5, mew=2) -#plt.xticks([]), plt.yticks([]) +plt.plot(X, Y, "C1o-", markevery=500, mec="1.0", lw=2, ms=8.5, mew=2) +# plt.xticks([]), plt.yticks([]) plt.ylim(-1.5, 1.5) plt.tight_layout() plt.savefig("../figures/sine-logscale.pdf", dpi=100) -fig = plt.figure(figsize=(7,1.5)) +fig = plt.figure(figsize=(7, 1.5)) plt.plot(X, Y, "C1", lw=2) -plt.fill_betweenx([-1.5,1.5],[0],[2*np.pi], color=".9") +plt.fill_betweenx([-1.5, 1.5], [0], [2*np.pi], color=".9") plt.text(0, -1, r" Period $\Phi$") # plt.xticks([]), plt.yticks([]) plt.ylim(-1.5, 1.5) @@ -42,10 +42,10 @@ # plt.show() -fig = plt.figure(figsize=(7,1.5)) +fig = plt.figure(figsize=(7, 1.5)) plt.plot(X, np.sin(X), "C0", lw=2, label="Sine") plt.plot(X, np.cos(X), "C1", lw=2, label="Cosine") -plt.legend(bbox_to_anchor = (0.0, .9, 1.02, 0.1), +plt.legend(bbox_to_anchor=(0.0, .9, 1.02, 0.1), frameon=False, mode="expand", ncol=2, loc="lower left") plt.title("Sine and Cosine") plt.xticks([]), plt.yticks([]) @@ -55,18 +55,18 @@ # plt.show() -fig = plt.figure(figsize=(7,1.5)) +fig = plt.figure(figsize=(7, 1.5)) X = np.linspace(0, 10*np.pi, 1000) Y = np.sin(X) -plt.plot(X, Y, "C1o-", markevery=50, mec="1.0", lw=2, ms=8.5, mew=2) +plt.plot(X, Y, "C1o-", markevery=50, mec="1.0", lw=2, ms=8.5, mew=2) # plt.xticks([]), plt.yticks([]) plt.ylim(-1.5, 1.5) -plt.annotate(" ", (X[200],Y[200]), (X[250], -1), ha="center", va="center", - arrowprops = {"arrowstyle" : "->", "color": "C1"}) -plt.annotate("A", (X[250],Y[250]), (X[250], -1), ha="center", va="center", - arrowprops = {"arrowstyle" : "->", "color": "C1"}) -plt.annotate(" ", (X[300],Y[300]), (X[250], -1), ha="center", va="center", - arrowprops = {"arrowstyle" : "->", "color": "C1"}) +plt.annotate(" ", (X[200], Y[200]), (X[250], -1), ha="center", va="center", + arrowprops={"arrowstyle" : "->", "color": "C1"}) +plt.annotate("A", (X[250], Y[250]), (X[250], -1), ha="center", va="center", + arrowprops={"arrowstyle" : "->", "color": "C1"}) +plt.annotate(" ", (X[300], Y[300]), (X[250], -1), ha="center", va="center", + arrowprops={"arrowstyle" : "->", "color": "C1"}) plt.tight_layout() plt.savefig("../figures/sine-annotate.pdf", dpi=100) # plt.show() diff --git a/scripts/styles.py b/scripts/styles.py index bf5109a..94ff839 100644 --- a/scripts/styles.py +++ b/scripts/styles.py @@ -8,11 +8,11 @@ for style in ['default'] + plt.style.available: with plt.style.context(style): - fig = plt.figure(figsize=(5,3), dpi=100) - ax = plt.subplot(1,1,1) - X = np.linspace(0,2*np.pi, 256) + fig = plt.figure(figsize=(5, 3), dpi=100) + ax = plt.subplot(1, 1, 1) + X = np.linspace(0, 2*np.pi, 256) Y = np.cos(X) - ax.plot(X,Y) + ax.plot(X, Y) plt.title(style, family="Source Serif Pro", size=32) plt.tight_layout() plt.savefig("../figures/style-%s.pdf" % style) diff --git a/scripts/text-alignments.py b/scripts/text-alignments.py index 2470ab7..c329ae0 100644 --- a/scripts/text-alignments.py +++ b/scripts/text-alignments.py @@ -7,8 +7,8 @@ dpi = 100 fig = plt.figure(figsize=(4.25, 1.5), dpi=dpi) -ax = fig.add_axes([0,0,1,1], frameon=False, - xlim=(0,4.25), ylim=(0,1.5), xticks=[], yticks=[]) +ax = fig.add_axes([0, 0, 1, 1], frameon=False, + xlim=(0, 4.25), ylim=(0, 1.5), xticks=[], yticks=[]) fontsize = 48 renderer = fig.canvas.get_renderer() @@ -37,16 +37,16 @@ text.set_position(position) -for name,y in yoffset.items(): +for name, y in yoffset.items(): y = position[1] - y + yoffset[verticalalignment] plt.plot([0.1, 3.75], [y, y], linewidth=0.5, color=color) plt.text(3.75, y, " "+name, color=color, ha="left", va="center", size="x-small") -for name,x in xoffset.items(): +for name, x in xoffset.items(): x = position[0] - x + xoffset[horizontalalignment] - plt.plot([x,x], [0.25, 1.25], linewidth=0.5, color=color) - plt.text(x, 0.24, name, color = color, + plt.plot([x, x], [0.25, 1.25], linewidth=0.5, color=color) + plt.text(x, 0.24, name, color=color, ha="center", va="top", size="x-small") P = [] @@ -54,16 +54,16 @@ x = position[0] - x + xoffset[horizontalalignment] for y in yoffset.values(): y = position[1] - y + yoffset[verticalalignment] - P.append((x,y)) + P.append((x, y)) P = np.array(P) -ax.scatter(P[:,0], P[:,1], s=10, zorder=10, +ax.scatter(P[:, 0], P[:, 1], s=10, zorder=10, facecolor="white", edgecolor=color, linewidth=0.75) epsilon = 0.05 -plt.text(P[3,0]+epsilon, P[3,1]-epsilon, "(0,0)", +plt.text(P[3, 0]+epsilon, P[3, 1]-epsilon, "(0,0)", color=color, ha="left", va="top", size="x-small") -plt.text(P[8,0]-epsilon, P[8,1]+epsilon, "(1,1)", +plt.text(P[8, 0]-epsilon, P[8, 1]+epsilon, "(1,1)", color=color, ha="right", va="bottom", size="x-small") plt.savefig("../figures/text-alignments.pdf") diff --git a/scripts/tick-formatters.py b/scripts/tick-formatters.py index 3df9ee7..8566554 100644 --- a/scripts/tick-formatters.py +++ b/scripts/tick-formatters.py @@ -8,6 +8,8 @@ import matplotlib.ticker as ticker # Setup a plot such that only the bottom spine is shown + + def setup(ax): ax.spines['right'].set_color('none') ax.spines['left'].set_color('none') diff --git a/scripts/tick-locators.py b/scripts/tick-locators.py index 6803738..276f8a3 100644 --- a/scripts/tick-locators.py +++ b/scripts/tick-locators.py @@ -8,6 +8,8 @@ import matplotlib.ticker as ticker # Setup a plot such that only the bottom spine is shown + + def setup(ax): ax.spines['right'].set_color('none') ax.spines['left'].set_color('none') diff --git a/scripts/tick-multiple-locator.py b/scripts/tick-multiple-locator.py index 51110ff..771e2fe 100644 --- a/scripts/tick-multiple-locator.py +++ b/scripts/tick-multiple-locator.py @@ -8,6 +8,8 @@ import matplotlib.ticker as ticker # Setup a plot such that only the bottom spine is shown + + def setup(ax): ax.spines['right'].set_color('none') ax.spines['left'].set_color('none') diff --git a/scripts/tip-color-range.py b/scripts/tip-color-range.py index 01d0c7e..b8b43eb 100644 --- a/scripts/tip-color-range.py +++ b/scripts/tip-color-range.py @@ -8,16 +8,16 @@ import matplotlib as mpl import matplotlib.pyplot as plt -fig = plt.figure(figsize=(2,2)) +fig = plt.figure(figsize=(2, 2)) mpl.rcParams['axes.linewidth'] = 1.5 d = 0.01 -ax = fig.add_axes([d,d,1-2*d,1-2*d], xticks=[], yticks=[]) +ax = fig.add_axes([d, d, 1-2*d, 1-2*d], xticks=[], yticks=[]) X = np.random.seed(1) X = np.random.randn(1000, 4) cmap = plt.get_cmap("Oranges") -colors = [cmap(i) for i in [.1,.3,.5,.7]] +colors = [cmap(i) for i in [.1, .3, .5, .7]] ax.hist(X, 2, density=True, histtype='bar', color=colors) plt.savefig("../figures/tip-color-range.pdf") diff --git a/scripts/tip-colorbar.py b/scripts/tip-colorbar.py index 5e7bf50..2a46357 100644 --- a/scripts/tip-colorbar.py +++ b/scripts/tip-colorbar.py @@ -9,13 +9,13 @@ import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects -fig = plt.figure(figsize=(2.15,2)) +fig = plt.figure(figsize=(2.15, 2)) mpl.rcParams['axes.linewidth'] = 1.5 d = 0.01 -ax = fig.add_axes([d,d,1-2*d,1-2*d], xticks=[], yticks=[]) +ax = fig.add_axes([d, d, 1-2*d, 1-2*d], xticks=[], yticks=[]) np.random.seed(1) -Z = np.random.uniform(0,1,(8,8)) +Z = np.random.uniform(0, 1, (8, 8)) cmap = plt.get_cmap("Oranges") im = ax.imshow(Z, interpolation="nearest", cmap=cmap, vmin=0, vmax=2) cb = fig.colorbar(im, fraction=0.046, pad=0.04) diff --git a/scripts/tip-dotted.py b/scripts/tip-dotted.py index f5781aa..ebfae99 100644 --- a/scripts/tip-dotted.py +++ b/scripts/tip-dotted.py @@ -7,15 +7,15 @@ import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt -fig = plt.figure(figsize=(5,.25)) +fig = plt.figure(figsize=(5, .25)) -ax = fig.add_axes([0,0,1,1], frameon=False, - xticks=[], yticks=[], xlim=[0,1], ylim=[-.5,1.5]) +ax = fig.add_axes([0, 0, 1, 1], frameon=False, + xticks=[], yticks=[], xlim=[0, 1], ylim=[-.5, 1.5]) epsilon=1e-12 -plt.plot([0,1], [0,0], "black", clip_on=False, lw=8, - ls=(.5,(epsilon, 1)), dash_capstyle="round") -plt.plot([0,1], [1,1], "black", clip_on=False, lw=8, - ls=(-.5,(epsilon, 2)), dash_capstyle="round") +plt.plot([0, 1], [0, 0], "black", clip_on=False, lw=8, + ls=(.5, (epsilon, 1)), dash_capstyle="round") +plt.plot([0, 1], [1, 1], "black", clip_on=False, lw=8, + ls=(-.5, (epsilon, 2)), dash_capstyle="round") plt.savefig("../figures/tip-dotted.pdf") # plt.show() diff --git a/scripts/tip-dual-axis.py b/scripts/tip-dual-axis.py index 0d60963..74677eb 100644 --- a/scripts/tip-dual-axis.py +++ b/scripts/tip-dual-axis.py @@ -4,17 +4,17 @@ mpl.rcParams['axes.linewidth'] = 1.5 -fig = plt.figure(figsize=(2,2)) +fig = plt.figure(figsize=(2, 2)) d = 0.01 -ax1 = fig.add_axes([d,d,1-2*d,1-2*d], label="cartesian") -ax2 = fig.add_axes([d,d,1-2*d,1-2*d], projection="polar", label="polar") +ax1 = fig.add_axes([d, d, 1-2*d, 1-2*d], label="cartesian") +ax2 = fig.add_axes([d, d, 1-2*d, 1-2*d], projection="polar", label="polar") -ax1.set_xticks([]) #np.linspace(0.0, 0.4, 5)) -ax1.set_yticks([]) #np.linspace(0.0, 1.0, 11)) +ax1.set_xticks([]) # np.linspace(0.0, 0.4, 5)) +ax1.set_yticks([]) # np.linspace(0.0, 1.0, 11)) ax2.set_rorigin(0) ax2.set_thetamax(90) -ax2.set_ylim(0.5,1.0) +ax2.set_ylim(0.5, 1.0) ax2.set_xticks(np.linspace(0, np.pi/2, 10)) ax2.set_yticks(np.linspace(0.5, 1.0, 5)) diff --git a/scripts/tip-font-family.py b/scripts/tip-font-family.py index c98a7dc..8689b3b 100644 --- a/scripts/tip-font-family.py +++ b/scripts/tip-font-family.py @@ -8,6 +8,8 @@ import matplotlib.ticker as ticker # Setup a plot such that only the bottom spine is shown + + def setup(ax): ax.spines['right'].set_color('none') ax.spines['left'].set_color('none') diff --git a/scripts/tip-hatched.py b/scripts/tip-hatched.py index 9e33ae3..c8a4ec3 100644 --- a/scripts/tip-hatched.py +++ b/scripts/tip-hatched.py @@ -7,27 +7,27 @@ plt.rcParams['hatch.color'] = color1 plt.rcParams['hatch.linewidth'] = 8 -fig = plt.figure(figsize=(2,2)) +fig = plt.figure(figsize=(2, 2)) ax = plt.subplot() np.random.seed(123) -x1,y1 = 3*np.arange(2), np.random.randint(25,50,2) -x2,y2 = x1+1, np.random.randint(25,75,2) +x1, y1 = 3*np.arange(2), np.random.randint(25, 50, 2) +x2, y2 = x1+1, np.random.randint(25, 75, 2) ax.bar(x1, y1, color=color2) for i in range(len(x1)): - plt.annotate("%d%%" % y1[i], (x1[i], y1[i]), xytext=(0,1), + plt.annotate("%d%%" % y1[i], (x1[i], y1[i]), xytext=(0, 1), fontsize="x-small", color=color2, textcoords="offset points", va="bottom", ha="center") ax.bar(x2, y2, color=color2, hatch="/" ) for i in range(len(x2)): - plt.annotate("%d%%" % y2[i], (x2[i], y2[i]), xytext=(0,1), + plt.annotate("%d%%" % y2[i], (x2[i], y2[i]), xytext=(0, 1), fontsize="x-small", color=color2, textcoords="offset points", va="bottom", ha="center") ax.set_yticks([]) -ax.set_xticks(0.5+np.arange(0,6,3)) +ax.set_xticks(0.5+np.arange(0, 6, 3)) ax.set_xticklabels(["2018", "2019"]) ax.tick_params('x', length=0, labelsize="small", which='major') diff --git a/scripts/tip-multiline.py b/scripts/tip-multiline.py index 06c1dbf..1b62b76 100644 --- a/scripts/tip-multiline.py +++ b/scripts/tip-multiline.py @@ -7,12 +7,12 @@ import matplotlib.pyplot as plt mpl.rcParams['axes.linewidth'] = 1.5 -fig = plt.figure(figsize=(8,1.5)) -dx,dy = 0.0025, 0.01 +fig = plt.figure(figsize=(8, 1.5)) +dx, dy = 0.0025, 0.01 ax = fig.add_axes([dx, dy, 1-2*dx, 1-2*dy], frameon=False) -X,Y = [], [] +X, Y = [], [] for x in np.linspace(0.01, 10*np.pi-0.01, 100): - X.extend([x, x,None]) + X.extend([x, x, None]) Y.extend([0, np.sin(x), None]) print(X[:10], Y[:10]) plt.plot(X, Y, "black") diff --git a/scripts/tip-outline.py b/scripts/tip-outline.py index e34ad89..e376149 100644 --- a/scripts/tip-outline.py +++ b/scripts/tip-outline.py @@ -9,19 +9,19 @@ import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects -fig = plt.figure(figsize=(2,2)) +fig = plt.figure(figsize=(2, 2)) mpl.rcParams['axes.linewidth'] = 1.5 d = 0.01 -ax = fig.add_axes([d,d,1-2*d,1-2*d], xticks=[], yticks=[]) +ax = fig.add_axes([d, d, 1-2*d, 1-2*d], xticks=[], yticks=[]) np.random.seed(1) -Z = np.random.uniform(0,1,(8,8)) +Z = np.random.uniform(0, 1, (8, 8)) cmap = plt.get_cmap("Oranges") ax.imshow(Z, interpolation="nearest", cmap=cmap, vmin=0, vmax=2) text = ax.text(0.5, 0.1, "Label", transform=ax.transAxes, - color=cmap(0.9), size=32, weight="bold", ha="center", va="bottom") + color=cmap(0.9), size=32, weight="bold", ha="center", va="bottom") text.set_path_effects([path_effects.Stroke(linewidth=5, foreground='white'), path_effects.Normal()]) plt.savefig("../figures/tip-outline.pdf") diff --git a/scripts/tip-post-processing.py b/scripts/tip-post-processing.py index 1bf7238..4086d03 100644 --- a/scripts/tip-post-processing.py +++ b/scripts/tip-post-processing.py @@ -5,21 +5,21 @@ from scipy.ndimage import gaussian_filter # First pass for drop-shadow -fig = Figure(figsize=(6,1.5)) +fig = Figure(figsize=(6, 1.5)) canvas = FigureCanvas(fig) -ax = fig.add_axes([0,0,1,1], frameon=False, - xlim=[0,1], xticks=[], ylim=[0,1], yticks=[]) +ax = fig.add_axes([0, 0, 1, 1], frameon=False, + xlim=[0, 1], xticks=[], ylim=[0, 1], yticks=[]) ax.text(0.5, 0.5, "Matplotlib", transform=ax.transAxes, ha="center", va="center", size=64, color="black") canvas.draw() -Z = np.array(canvas.renderer.buffer_rgba())[:,:,0] +Z = np.array(canvas.renderer.buffer_rgba())[:, :, 0] Z = gaussian_filter(Z, sigma=9) # Second pass for text + drop-shadow -fig = plt.figure(figsize=(6,1.5)) -ax = fig.add_axes([0,0,1,1], frameon=False, - xlim=[0,1], xticks=[], ylim=[0,1], yticks=[]) -ax.imshow(Z, extent=[0,1,0,1], cmap=plt.cm.gray, alpha=0.65, aspect='auto') +fig = plt.figure(figsize=(6, 1.5)) +ax = fig.add_axes([0, 0, 1, 1], frameon=False, + xlim=[0, 1], xticks=[], ylim=[0, 1], yticks=[]) +ax.imshow(Z, extent=[0, 1, 0, 1], cmap=plt.cm.gray, alpha=0.65, aspect='auto') ax.text(0.5, 0.5, "Matplotlib", transform=ax.transAxes, ha="center", va="center", size=64, color="black") diff --git a/scripts/tip-transparency.py b/scripts/tip-transparency.py index 3a2c820..0172073 100644 --- a/scripts/tip-transparency.py +++ b/scripts/tip-transparency.py @@ -13,8 +13,8 @@ n = 500 X = np.random.normal(0, 0.25, n) Y = np.random.normal(0, 0.25, n) -ax.scatter(X, Y, s=50, c="k", lw=2) -ax.scatter(X, Y, s=50, c="w", lw=0) +ax.scatter(X, Y, s=50, c="k", lw=2) +ax.scatter(X, Y, s=50, c="w", lw=0) ax.scatter(X, Y, s=40, c="C1", lw=0, alpha=0.1) ax.set_xlim([-1, 1]), ax.set_xticks([]),