From aa80eeeba7cc5ca441217c50f9a2cd68d0523689 Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Wed, 17 Nov 2021 12:46:27 -0800 Subject: [PATCH 01/65] Cht add pcolormesh (#91) * CHT: change xcorr to pcolormesh * FIX * FIX * FIX --- .circleci/config.yml | 2 +- cheatsheets.tex | 16 +++++++++------- figures/legend.pdf | Bin 14117 -> 13179 bytes scripts/basic-plots.py | 13 +++++++++---- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 799c53f..06f76c7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,7 +11,7 @@ jobs: - checkout - run: command: echo "placeholder" - + workflows: main: jobs: diff --git a/cheatsheets.tex b/cheatsheets.tex index 5666a60..14fc806 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -382,6 +382,15 @@ \optional{extent}, \optional{origin} } {} + \plot{basic-pcolormesh.pdf}{\textbf{pcolormesh}([X],[Y],Z,…)} + {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pcolormesh.html} + { \optional{X}, + \optional{Y}, + \mandatory{Z}, + \optional{vmin}, + \optional{vmax}, + \optional{cmap}} + {} \plot{basic-quiver.pdf}{\textbf{quiver}([X],[Y],U,V,…)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.quiver.html} { \optional{X}, @@ -488,13 +497,6 @@ \optional{gridsize}, \optional{bins} } {} - \plot{advanced-xcorr.pdf}{\textbf{xcorr}(X,Y,…)} - {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.xcorr.html} - {\mandatory{X}, - \mandatory{Y}, - \optional{normed}, - \optional{detrend} } - {} \end{myboxed} diff --git a/figures/legend.pdf b/figures/legend.pdf index a2fd28be23e3e62014c1fab9cc3376e6df7e29f0..7cc56eef9f758c26e089a38462aca33c2d364898 100644 GIT binary patch delta 2014 zcmah~3sh7^7zPX<*GCdaCJC2fgB5n~V_9~W(3E}f5_WmTDrW8DvaIZj-3#JsY)Xb6 zO%JGmZl$gY28hz4f<_%M3wVD_jei7@GNj0(a8Q=SU*$f#seMiS1M z40Zna3n;@18Tihd2RcBgBY^})G8iZWg?W@EFvh?bL#c^V?Qh;VI19L?){um;7C!^| zU^r0v2f0|76HigFzrECdvFjEcGV!HnxW`64p~T-HzOD#`{+||{IK~cw5s?P?As`fb zB>~wFPAT?6G0yY5a3|n@*){tO$s`N@ELw?Cugp;Zs)IlXQV1!?m{637@jx*6Al#%L zNWk*gRIS$uC^mxx;W&z8ps_I)jh-y1$`g46#;=Jx9Yf>`wLzd+Oz+jVHv5$Ys~eSG|s`&3|uIou_Kr z&wjscE7)z|6}4uK9~^JKGH=(W9p;8z0n=Bm?Ae-~EG}8A&D?|5d>(Um9a(t(;>qeh z?|V8g_uQ*xE$uVzC49d%&1$WeDB{yNp=DinwhnM_MI4^V`9uZT{oJxP@p_iX-`+(- zPY+m>orPyyE0mjyX4Tyvk^PeY76Ds_UVs072r`a2p!$G5(CBa+J2q=a$GMY+v`07O zpG~H*YL3>gIx*5)AU1byzHajVl%YR1-(3FQ+12U;r4o|NkNB$oO8Df}T>Hn?=F)2w zN0xNNpRg5Wb=@~)%t|U2`nAvX4^YYac564Bv@pK(EDHCJ&{x?$tFPR9+g>$Pb!jd- zbLJM^rE_V;u^#U_=-UdLo}55VoiA0aNQfy(tY*{HqDj7MV&&~Sk~Xz>9FA&PB)xfk zZ-o0)#y#!2eKu)}L2T@FU0fdBHSox0Jk;HsUe)kuxIQ$l&%J6luOVWD`^OhKnp;0= zZ$TE5yfoKQ5Ul$C>l@93JF^oHu8S+*IV>%%`8e&Qh(NxD{HzbN8|Qe2FB;B%yxi}J zQP5xJY0BE!X?BU~y>zBObI-RD7Y|90&z=T);y32*1^d(L7>N&$Y>SPKeLON}wWG1G zy?cfum3Q>Rm+e1#f3;~+O_KMBb;ar69<{Zl)-qT-wX$_%#}7-3dw>6#TitxPyW93^ z;KACVQ-a0VpvQdQ2budj52eN_ZZdA7_~rc%GhLq4g^KMn`1>STA4LwR`H4^L6ZqTO zw=Xo6MAOSs9xPiqX|}7+!{y4#+@5Q~?83Oj!sTmO{;zcP*Bq*dn(*RM$FFyKt&H$l zQ-aLPEgMR1ieH=fK8N0+nUKEcfkAM&FMp`9dhm?q4*!&GShuFa)Ay>rl|QcH0X%dkEAu&270bY3&#zVm)pR6{6+YK&e8k~;7IBdbdVv=4@ z!Z=lmKvAHI1nhj=sEGhhkBH>)c^r;_#o>hEq6GpW8$~$_cx<64QpCpjJpMfR|5d;# zPs=6e?{W!Vha%?e+^*SeO;bOBy~cg#?IH9J=}CR@ZqJly&C`9Q7mp9E%u}D=>$23= zJwyEbD9B*xDe~D)Lx@qwPSFUJ$`1915NSTq$GXgR& OoXbWb8ciq`L4N|tCjUhM delta 3033 zcmbtWOK;mo5Ju2biK4x*lAn1XiRuT)D6i6zt z3l#hh?XCBo3iOipfAo*^7v$2JX`q4T(1p87alVS=Ap@9Vezy5OoZ~l1jmsJu(QV0r9NJ}Rp8p?JueX&n( zi?d-778(u@2_P(FH~_nQ1RU%r#NWq{>09+{_tKPuuFw>}?H*@VLdK8Dp=`FlOh=FAMz~e$G1zhn1e1jj% z#4ehJGjkyK46Kq2Im^<;e8tvkJ%cuz9ikOknB;R>H@a)!3n;RMZbn^{I?=D=NDt1A z39MZ)(0RJZBAo-db+EEa|0@JGf)p4ToQ*;H;v;;%`T4V7K34?Sfl@;7#!sAfyP<)% zZZUEG?UR=eN`mU?QUvYnZ8uZgPIMk+@w`Yg+Jy<_Rd|CjID2;9zrNldn(YjA7LWT` z+8OA{ViqoCd*MwyyMx_I3`njV14`~y>So~t{okrSuEN$44ug)A3WUHP&X}lUc2R`0 zI66uuGY!m4JIW&yekNTrCW8r}=?3VA^K%_frkEnA#{!JAJuLLibMPw-G&pYtwC7$t z(-M5+{AC(a!ZzNm(t>2o62rx-!Xzf)RaPE{xi)#f<*4!=N;tZZXVoQT0CYFw|MOG< zx#xqf5)=zSc^){v56bmGVdhHZ;L`_}aS#FdUOAq53lMRci({PS(=Hq#!I2I+OVtQU z3%5!UWM_Jv#OM@_0Y~Xol5w2=WgEr16!MDyt2F!eoBqeH!E2%j>4=soO`%*Vr@Sp^ zhG+JtUq2|Dgh9o^UGj{I+;$$lmuFYcub%Y3-#^#0*Sd(K@JcUq=aTZ-1lZ(jO|n)7 zNT^(;Se;iS-Ehp2#4(2S3VaVZcjbK?3tZ2v*-}h!X@C`qp&A1Xi}F5-37~MS#pm6= zsT8&x!!k=eGw70LTYf4x9QA&VG2iIgD zC$73$X-*GF>1DcO-5)I?oxyGt##sv3jokwVyVIhW=Z|bWIv_g9!ud3g@`E&+>{U73 z&2)$z2o8Ivy&hvuz?gfA_c3Fh#3$WY+&zX*g+(5pl9%{`Limljh|mYmsRSjCNl5rO z#+z_+BSs445q`sk=yva0j0{0JkJdm7L|~3ScDE#><1{&;v(oO#BSA|#EZ|aj%-?6? zA!B((br9&9P}6;*w1O33+ScEYj ztJ3D&z+)2o+?qlzxP$4uiMgA`;Q4UN7{s=WL9hB-`XsfrdX1-G6V=C-x7bNaMr{RfY5-nIY$ diff --git a/scripts/basic-plots.py b/scripts/basic-plots.py index e044728..4b58e58 100644 --- a/scripts/basic-plots.py +++ b/scripts/basic-plots.py @@ -79,13 +79,20 @@ plt.savefig("../figures/basic-imshow.pdf") ax.clear() - -# Basic contour plot +# Basic pcolormesh plot # ----------------------------------------------------------------------------- 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 = 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)) +plt.savefig("../figures/basic-pcolormesh.pdf") +ax.clear() + +# Basic contour plot +# ----------------------------------------------------------------------------- colors = np.zeros((5,4)) colors[:] = mpl.colors.to_rgba("C1") colors[:,3] = np.linspace(0.15, 0.85, len(colors)) @@ -94,8 +101,6 @@ 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)) -# ax.set_axisbelow(True) -# ax.grid(linewidth=0.125, color="0.75") plt.savefig("../figures/basic-contour.pdf") ax.clear() From d09834595a6958cd838620d66753569ec777c3db Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Wed, 17 Nov 2021 23:14:15 +0100 Subject: [PATCH 02/65] Apply PEP-8 compatible code formatting While not visible in the cheatsheet itself, we should still adhere to common best practices, to be a role model for potential contributors. --- scripts/advanced-plots.py | 100 +++++++++++++++++++------------------- scripts/basic-plots.py | 93 +++++++++++++++++------------------ 2 files changed, 94 insertions(+), 99 deletions(-) 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/basic-plots.py b/scripts/basic-plots.py index 4b58e58..2462b82 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 = 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)) +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)) 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") From 3be24b7a87350b33e855fe41c52c3f5a7f24bfa8 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Wed, 17 Nov 2021 23:34:29 +0100 Subject: [PATCH 03/65] Formatting: - Whitespace - Remove [explode] from `pie()` and [cmap] from `imshow()`: All other functions only list the primary data fields (with the exception of `plot(..., [fmt])`, but that function is so prominent that I'll make an exception for it. The parameters `cmap` and `explode` are still listed, so that information is not lost. --- cheatsheets.tex | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index 14fc806..3f54ce5 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -286,7 +286,7 @@ Y = np.cos(X)\\ \\ fig, ax = plt.subplots()\\ - ax.plot(X,Y,color='C1')\\ + ax.plot(X, Y, color='green')\\ \\ fig.savefig(``figure.pdf'')\\ fig.show() } @@ -303,7 +303,7 @@ \API{https://matplotlib.org/tutorials/intermediate/gridspec.html} } \plot{layout-subplot.pdf}{\textbf{subplot[s]}(rows,cols,…)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html} - {\ttfamily fig, axs = plt.subplots(3,3)} + {\ttfamily fig, axs = plt.subplots(3, 3)} {} \plot{layout-gridspec.pdf}{G = \textbf{gridspec}(rows,cols,…)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.gridspec.GridSpec.html} @@ -313,7 +313,7 @@ {}{} \plot{layout-divider.pdf}{d=\textbf{make\_axes\_locatable}(ax)} {https://matplotlib.org/mpl_toolkits/axes_grid/users/axes_divider.html} - {\ttfamily ax=d.new\_horizontal('10\%')}{} + {\ttfamily ax = d.new\_horizontal('10\%')}{} \end{myboxed} \vspace{\fill} @@ -364,7 +364,7 @@ \optional{bottom}, \optional{align}, \optional{color} }{} - \plot{basic-imshow.pdf}{\textbf{imshow}(Z,[cmap],…)} + \plot{basic-imshow.pdf}{\textbf{imshow}(Z,…)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html} { \mandatory{Z}, \optional{cmap}, @@ -372,7 +372,7 @@ \optional{extent}, \optional{origin} } {} - \plot{basic-contour.pdf}{\textbf{contour[f]}([X],[Y],Z,,…)} + \plot{basic-contour.pdf}{\textbf{contour[f]}([X],[Y],Z,…)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contour.html} { \optional{X}, \optional{Y}, @@ -401,7 +401,7 @@ \optional{units}, \optional{angles} } {} - \plot{basic-pie.pdf}{\textbf{pie}(X,[explode],…)} + \plot{basic-pie.pdf}{\textbf{pie}(X,…)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pie.html} {\mandatory{Z}, \optional{explode}, @@ -420,7 +420,7 @@ \optional{weight}, \optional{transform} } {} - \plot{basic-fill.pdf}{\textbf{fill[\_between][x]}( … )} + \plot{basic-fill.pdf}{\textbf{fill[\_between][x]}(…)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.fill.html} {\mandatory{X}, \optional{Y1}, @@ -666,13 +666,13 @@ {\ttfamily \scriptsize import matplotlib.animation as mpla\par ~\par - T = np.linspace(0,2*np.pi,100)\par + T = np.linspace(0, 2*np.pi, 100)\par S = np.sin(T)\par line, = plt.plot(T, S)\par def animate(i):\par - ~~line.set\_ydata(np.sin(T+i/50))\par + ~~~~line.set\_ydata(np.sin(T+i/50))\par anim = mpla.FuncAnimation(\par - ~~plt.gcf(), animate, interval=5)\par + ~~~~plt.gcf(), animate, interval=5)\par plt.show()\par } \end{myboxed} @@ -794,7 +794,7 @@ % \begin{myboxed}{Text alignments \hfill \API{https://matplotlib.org/tutorials/text/text_props.html} } - ax.\textbf{text}( …, ha=… , va=…, … )\\ + ax.\textbf{text}( …, ha=… , va=…, …)\\ \includegraphics[width=\columnwidth]{text-alignments.pdf} \end{myboxed} @@ -803,8 +803,8 @@ % \begin{myboxed}{Text parameters \hfill \API{https://matplotlib.org/tutorials/text/text_props.html}} - ax.\textbf{text}( …, family=… , size=…, weight = …)\\ - ax.\textbf{text}( …, fontproperties = … )\\ + ax.\textbf{text}(…, family=…, size=…, weight=…)\\ + ax.\textbf{text}(…, fontproperties=…)\\ \includegraphics[width=\columnwidth]{fonts.pdf} \end{myboxed} @@ -963,7 +963,7 @@ % \begin{myboxed}{How do I …} \textbf{… resize a figure?}\\ - \hspace*{2.5mm}~$\rightarrow$ fig.set\_size\_inches(w,h)\\ + \hspace*{2.5mm}~$\rightarrow$ fig.set\_size\_inches(w, h)\\ \textbf{… save a figure?}\\ \hspace*{2.5mm}~$\rightarrow$ fig.savefig("figure.pdf")\\ \textbf{… save a transparent figure?}\\ @@ -985,7 +985,7 @@ \textbf{… show error as shaded region?}\\ \hspace*{2.5mm}~$\rightarrow$ ax.fill\_between(X, Y+error, Y-error)\\ \textbf{… draw a rectangle?}\\ - \hspace*{2.5mm}~$\rightarrow$ ax.add\_patch(plt.Rectangle((0, 0),1,1)\\ + \hspace*{2.5mm}~$\rightarrow$ ax.add\_patch(plt.Rectangle((0, 0), 1, 1)\\ \textbf{… draw a vertical line?}\\ \hspace*{2.5mm}~$\rightarrow$ ax.axvline(x=0.5)\\ \textbf{… draw outside frame?}\\ @@ -993,7 +993,7 @@ \textbf{… use transparency?}\\ \hspace*{2.5mm}~$\rightarrow$ ax.plot(…, alpha=0.25)\\ \textbf{… convert an RGB image into a gray image? }\\ - \hspace*{2.5mm}~$\rightarrow$ gray = 0.2989*R+0.5870*G+0.1140*B\\ + \hspace*{2.5mm}~$\rightarrow$ gray = 0.2989*R + 0.5870*G + 0.1140*B\\ \textbf{… set figure background color?}\\ \hspace*{2.5mm}~$\rightarrow$ fig.patch.set\_facecolor(``grey'')\\ \textbf{… get a reversed colormap?}\\ From b0f3b176c7277bd157a1a741cf317d55b52661f7 Mon Sep 17 00:00:00 2001 From: Jamal Mustafa Date: Thu, 18 Nov 2021 12:16:44 -0800 Subject: [PATCH 04/65] add flake8 --- .flake8 | 5 +++++ .pre-commit-config.yaml | 4 ++++ requirements/requirements.in | 4 +++- requirements/requirements.txt | 27 ++++++++++++++++++++++++++- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .flake8 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/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 From 2398af613f65c8f0b61a48a0b303f1015e869f30 Mon Sep 17 00:00:00 2001 From: Jamal Mustafa Date: Thu, 18 Nov 2021 19:05:55 -0800 Subject: [PATCH 05/65] fix formatting - fix E12,E231,E241,E251,E26,E30 with autopep8 - fix the rest by hand --- docs/conf.py | 4 +- logos/mpl-logos2.py | 1 + scripts/adjustements.py | 50 ++++++++--------- scripts/anatomy.py | 5 +- scripts/animation.py | 6 ++- scripts/annotate.py | 13 +++-- scripts/annotation-arrow-styles.py | 7 ++- scripts/annotation-connection-styles.py | 2 + scripts/basic-plots.py | 8 +-- scripts/colorbar.py | 10 ++-- scripts/colormaps.py | 12 ++--- scripts/colors.py | 8 +-- scripts/extents.py | 28 +++++----- scripts/fonts.py | 32 +++++------ scripts/interpolations.py | 6 +-- scripts/layouts.py | 14 ++--- scripts/legend.py | 21 ++++---- scripts/linestyles.py | 31 +++++------ scripts/markers.py | 32 +++++------ scripts/performance-tips.py | 10 ++-- scripts/plot-variations.py | 72 ++++++++++++------------- scripts/projections.py | 12 ++--- scripts/scales.py | 32 +++++------ scripts/sine.py | 36 ++++++------- scripts/styles.py | 8 +-- scripts/text-alignments.py | 20 +++---- scripts/tick-formatters.py | 2 + scripts/tick-locators.py | 2 + scripts/tick-multiple-locator.py | 2 + scripts/tip-color-range.py | 6 +-- scripts/tip-colorbar.py | 6 +-- scripts/tip-dotted.py | 14 ++--- scripts/tip-dual-axis.py | 12 ++--- scripts/tip-font-family.py | 2 + scripts/tip-hatched.py | 12 ++--- scripts/tip-multiline.py | 8 +-- scripts/tip-outline.py | 8 +-- scripts/tip-post-processing.py | 16 +++--- scripts/tip-transparency.py | 4 +- 39 files changed, 298 insertions(+), 276 deletions(-) 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/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/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 2462b82..d7a0c35 100644 --- a/scripts/basic-plots.py +++ b/scripts/basic-plots.py @@ -68,10 +68,10 @@ # 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") +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") 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([]), From 59b75b8d873c970d6af96eb7cf8193f08ccb3397 Mon Sep 17 00:00:00 2001 From: Steffen Rehberg Date: Mon, 22 Nov 2021 12:44:07 +0100 Subject: [PATCH 06/65] Fix various typos and inconsistencies - annotation: missing x in xycoords and "text" instead of "Annotation" to correspond to function call signature above - clear a figure how-to: make code correspond to heading - remove ticks how-to: same for yaxis as is the other how-to's - explicitly set legend location in anatomy.py as mpl 3.5.0 "best" default location results in lower right corner --- cheatsheets.tex | 6 +++--- scripts/anatomy.py | 2 +- scripts/annotate.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index 3f54ce5..9d4421a 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -968,12 +968,12 @@ \hspace*{2.5mm}~$\rightarrow$ fig.savefig("figure.pdf")\\ \textbf{… save a transparent figure?}\\ \hspace*{2.5mm}~$\rightarrow$ fig.savefig("figure.pdf", transparent=True)\\ - \textbf{… clear a figure?}\\ - \hspace*{2.5mm}~$\rightarrow$ ax.clear()\\ + \textbf{… clear a figure/an axes?}\\ + \hspace*{2.5mm}~$\rightarrow$ fig.clear() $\rightarrow$ ax.clear()\\ \textbf{… close all figures?}\\ \hspace*{2.5mm}~$\rightarrow$ plt.close("all")\\ \textbf{… remove ticks?}\\ - \hspace*{2.5mm}~$\rightarrow$ ax.set\_xticks([])\\ + \hspace*{2.5mm}~$\rightarrow$ ax.set\_[xy]ticks([])\\ \textbf{… remove tick labels ?}\\ \hspace*{2.5mm}~$\rightarrow$ ax.set\_[xy]ticklabels([])\\ \textbf{… rotate tick labels ?}\\ diff --git a/scripts/anatomy.py b/scripts/anatomy.py index 35c5661..4a32544 100644 --- a/scripts/anatomy.py +++ b/scripts/anatomy.py @@ -49,7 +49,7 @@ def minor_tick(x, pos): ax.set_xlabel("X axis label") ax.set_ylabel("Y axis label") -ax.legend() +ax.legend(loc="upper right") def circle(x, y, radius=0.15): diff --git a/scripts/annotate.py b/scripts/annotate.py index f138bc1..4254941 100644 --- a/scripts/annotate.py +++ b/scripts/annotate.py @@ -17,10 +17,10 @@ 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("text", (5.5, .75), (0.75, .75), size=16, va="center", ha="center", arrowprops=dict(facecolor='black', shrink=0.05)) -plt.text( 5.5, 0.6, "xy\nycoords", size=10, va="top", ha="center", color=".5") +plt.text( 5.5, 0.6, "xy\nxycoords", size=10, va="top", ha="center", color=".5") plt.text( .75, 0.6, "xytext\ntextcoords", size=10, va="top", ha="center", color=".5") plt.savefig("../figures/annotate.pdf") From 8e20e9964be881619370306f655c029df23a11d4 Mon Sep 17 00:00:00 2001 From: Steffen Rehberg Date: Tue, 7 Dec 2021 18:06:42 +0100 Subject: [PATCH 07/65] Add missing font Pacifico which is required in font.py --- README.md | 3 ++- fonts/Makefile | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d956a69..a9d07d5 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,8 @@ Beginner handout [(download pdf)](https://matplotlib.org/cheatsheets/handout-beg or https://github.com/adobe-fonts/source-sans-pro/tree/release/OTF * `fonts/source-serif-pro/*` : See https://fonts.google.com/specimen/Source+Serif+Pro or https://github.com/adobe-fonts/source-serif-pro/tree/release/OTF -* `fonts/delicious-123/*` : See https://www.exljbris.com/delicious.html +* `fonts/eb-garamond/*` : See https://bitbucket.org/georgd/eb-garamond/src/master +* `fonts/pacifico/*` : See https://fonts.google.com/download?family=Pacifico On Linux, with `make` installed, the fonts can be set up with the following command: ```shell diff --git a/fonts/Makefile b/fonts/Makefile index baa450e..7525dcf 100644 --- a/fonts/Makefile +++ b/fonts/Makefile @@ -1,4 +1,4 @@ -FONT_DIRS := eb-garamond roboto roboto-mono roboto-slab source-code-pro source-sans-pro source-serif-pro +FONT_DIRS := eb-garamond roboto roboto-mono roboto-slab source-code-pro source-sans-pro source-serif-pro pacifico EB_GARAMOND_ZIP := https://bitbucket.org/georgd/eb-garamond/downloads/EBGaramond-0.016.zip ROBOTO_ZIP := https://github.com/googlefonts/roboto/releases/download/v2.138/roboto-unhinted.zip @@ -7,6 +7,7 @@ ROBOTO_SLAB_ZIP := https://github.com/googlefonts/robotoslab/archive/a65e6d SOURCE_CODE_PRO_ZIP := https://github.com/adobe-fonts/source-code-pro/releases/download/2.038R-ro%2F1.058R-it%2F1.018R-VAR/OTF-source-code-pro-2.038R-ro-1.058R-it.zip SOURCE_SANS_PRO_ZIP := https://github.com/adobe-fonts/source-sans/releases/download/2.045R-ro%2F1.095R-it/source-sans-pro-2.045R-ro-1.095R-it.zip SOURCE_SERIF_PRO_ZIP := https://github.com/adobe-fonts/source-serif/releases/download/3.001R/source-serif-pro-3.001R.zip +PACIFICO_ZIP := https://fonts.google.com/download?family=Pacifico UNZIP_FLAGS := -x "__MACOSX/*" @@ -24,6 +25,7 @@ all: sources cd source-code-pro && unzip -j /tmp/source-code-pro.zip "*.otf" $(UNZIP_FLAGS) cd source-sans-pro && unzip -j /tmp/source-sans-pro.zip "source-sans-pro-2.045R-ro-1.095R-it/OTF/*.otf" $(UNZIP_FLAGS) cd source-serif-pro && unzip -j /tmp/source-serif-pro.zip "source-serif-pro-3.001R/OTF/*.otf" $(UNZIP_FLAGS) + cd pacifico && unzip -j /tmp/pacifico.zip "*.ttf" $(UNZIP_FLAGS) .PHONY: sources sources: @@ -34,6 +36,7 @@ sources: wget $(SOURCE_CODE_PRO_ZIP) -O /tmp/source-code-pro.zip wget $(SOURCE_SANS_PRO_ZIP) -O /tmp/source-sans-pro.zip wget $(SOURCE_SERIF_PRO_ZIP) -O /tmp/source-serif-pro.zip + wget $(PACIFICO_ZIP) -O /tmp/pacifico.zip .PHONY: clean clean: From e07f8efe15913d1c9124d5902ba8c34dba45ad3f Mon Sep 17 00:00:00 2001 From: Jamal Mustafa Date: Fri, 10 Dec 2021 00:06:45 -0800 Subject: [PATCH 08/65] check the matplotlib version being used --- .bumpversion.cfg | 4 ++++ Makefile | 1 + check-matplotlib-version.py | 5 +++++ 3 files changed, 10 insertions(+) create mode 100755 check-matplotlib-version.py diff --git a/.bumpversion.cfg b/.bumpversion.cfg index c192f5b..3d5cc41 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,6 +1,10 @@ [bumpversion] current_version = 3.4.2 +[bumpversion:file:./check-matplotlib-version.py] +search = __version__ == '{current_version}' +replace = __version__ == '{new_version}' + [bumpversion:glob:./handout-*.tex] search = Matplotlib {current_version} replace = Matplotlib {new_version} diff --git a/Makefile b/Makefile index 114d87e..917c3b7 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ handouts: .PHONY: check check: + ./check-matplotlib-version.py ./check-num-pages.sh cheatsheets.pdf 2 ./check-num-pages.sh handout-tips.pdf 1 ./check-num-pages.sh handout-beginner.pdf 1 diff --git a/check-matplotlib-version.py b/check-matplotlib-version.py new file mode 100755 index 0000000..5311f08 --- /dev/null +++ b/check-matplotlib-version.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python +import matplotlib as mpl + + +assert mpl.__version__ == '3.4.2' From b0af64fa203dbcb2d921e7a8710ad5184f5347f1 Mon Sep 17 00:00:00 2001 From: Jamal Mustafa Date: Fri, 10 Dec 2021 00:18:21 -0800 Subject: [PATCH 09/65] bump the matplotlib version --- .bumpversion.cfg | 2 +- Makefile | 2 +- cheatsheets.tex | 2 +- check-matplotlib-version.py | 2 +- handout-beginner.tex | 2 +- handout-intermediate.tex | 2 +- handout-tips.tex | 2 +- requirements/requirements.in | 2 +- requirements/requirements.txt | 13 +++++++++++-- 9 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 3d5cc41..46fdeb8 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 3.4.2 +current_version = 3.5.0 [bumpversion:file:./check-matplotlib-version.py] search = __version__ == '{current_version}' diff --git a/Makefile b/Makefile index 917c3b7..530fc09 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ all: logos figures cheatsheets handouts docs .PHONY: logos logos: - wget https://github.com/matplotlib/matplotlib/raw/v3.4.2/doc/_static/logo2.png -O ./logos/logo2.png + wget https://github.com/matplotlib/matplotlib/raw/v3.5.0/doc/_static/logo2.png -O ./logos/logo2.png .PHONY: figures figures: diff --git a/cheatsheets.tex b/cheatsheets.tex index 9d4421a..1212c7d 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -264,7 +264,7 @@ \begin{multicols*}{5} \begin{overpic}[width=\columnwidth,tics=6,trim=12 6 18 6, clip]{logo2.png} \put (16.5,1.5) {\scriptsize\RobotoCon \textcolor[HTML]{11557c}{Cheat sheet}} - \put (80,1.5) {\tiny\Roboto \textcolor[HTML]{11557c}{Version 3.4.2}} + \put (80,1.5) {\tiny\Roboto \textcolor[HTML]{11557c}{Version 3.5.0}} \end{overpic} %\textbf{\Large \RobotoCon Matplotlib 3.2 cheat sheet}\\ %{\ttfamily https://matplotlib.org} \hfill CC-BY 4.0 diff --git a/check-matplotlib-version.py b/check-matplotlib-version.py index 5311f08..d8f88d3 100755 --- a/check-matplotlib-version.py +++ b/check-matplotlib-version.py @@ -2,4 +2,4 @@ import matplotlib as mpl -assert mpl.__version__ == '3.4.2' +assert mpl.__version__ == '3.5.0' diff --git a/handout-beginner.tex b/handout-beginner.tex index f9d7394..1b3087a 100644 --- a/handout-beginner.tex +++ b/handout-beginner.tex @@ -297,7 +297,7 @@ \subsection*{\rmfamily Save \mdseries (bitmap or vector format)} \vfill % {\scriptsize - Matplotlib 3.4.2 handout for beginners. + Matplotlib 3.5.0 handout for beginners. Copyright (c) 2021 Matplotlib Development Team. Released under a CC-BY 4.0 International License. Supported by NumFOCUS. diff --git a/handout-intermediate.tex b/handout-intermediate.tex index d04971b..38fb97e 100644 --- a/handout-intermediate.tex +++ b/handout-intermediate.tex @@ -198,7 +198,7 @@ \subsection*{\rmfamily Size \& DPI} \vfill % {\scriptsize - Matplotlib 3.4.2 handout for intermediate users. + Matplotlib 3.5.0 handout for intermediate users. Copyright (c) 2021 Matplotlib Development Team. Released under a CC-BY 4.0 International License. Supported by NumFOCUS. diff --git a/handout-tips.tex b/handout-tips.tex index 864dc56..8b1f7ca 100644 --- a/handout-tips.tex +++ b/handout-tips.tex @@ -243,7 +243,7 @@ \subsection*{\rmfamily Read the documentation} \vfill % {\scriptsize - Matplotlib 3.4.2 handout for tips \& tricks. + Matplotlib 3.5.0 handout for tips \& tricks. Copyright (c) 2021 Matplotlib Development Team. Released under a CC-BY 4.0 International License. Supported by NumFOCUS. diff --git a/requirements/requirements.in b/requirements/requirements.in index d1fcdd7..179699f 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -2,7 +2,7 @@ autopep8 bump2version cartopy==0.19.0.post1 flake8 -matplotlib==3.4.2 +matplotlib==3.5.0 mpl-sphinx-theme pdfx pip-tools diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 37074d2..8ae5a1c 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -48,6 +48,8 @@ filelock==3.0.12 # via virtualenv flake8==4.0.1 # via -r requirements.in +fonttools==4.28.3 + # via matplotlib identify==2.2.2 # via pre-commit idna==3.3 @@ -66,7 +68,7 @@ kiwisolver==1.3.1 # via matplotlib markupsafe==2.0.1 # via jinja2 -matplotlib==3.4.2 +matplotlib==3.5.0 # via -r requirements.in mccabe==0.6.1 # via flake8 @@ -80,7 +82,10 @@ numpy==1.19.5 # matplotlib # scipy packaging==21.2 - # via sphinx + # via + # matplotlib + # setuptools-scm + # sphinx pdfminer.six==20201018 # via pdfx pdfx==1.4.1 @@ -121,6 +126,8 @@ requests==2.26.0 # via sphinx scipy==1.5.4 # via -r requirements.in +setuptools-scm==6.3.2 + # via matplotlib shapely==1.7.1 # via cartopy six==1.15.0 @@ -155,6 +162,8 @@ toml==0.10.2 # autopep8 # pep517 # pre-commit +tomli==1.2.2 + # via setuptools-scm typing-extensions==4.0.0 # via importlib-metadata urllib3==1.26.7 From 9915aa9524bc34bad3c933b0582686ea2468ce3a Mon Sep 17 00:00:00 2001 From: Steffen Rehberg Date: Mon, 13 Dec 2021 08:53:15 +0100 Subject: [PATCH 10/65] Fix suptitle setting - change non-existing method ax.set_suptitle to fig.suptitle and combine patch.set_alpha(0) for fig and ax into one line to make room for new line fig.suptitle() - fix typo --- cheatsheets.tex | 6 +++--- handout-tips.tex | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index 1212c7d..f79664b 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -708,19 +708,19 @@ \begin{myboxed}{Quick reminder} {\ttfamily ax.\textbf{grid}()\\ - ax.patch.\textbf{set\_alpha}(0)\\ ax.\textbf{set\_[xy]lim}(vmin, vmax)\\ ax.\textbf{set\_[xy]label}(label)\\ ax.\textbf{set\_[xy]ticks}(list)\\ ax.\textbf{set\_[xy]ticklabels}(list)\\ - ax.\textbf{set\_[sup]title}(title)\\ + ax.\textbf{set\_title}(title)\\ ax.\textbf{tick\_params}(width=10, …)\\ ax.\textbf{set\_axis\_[on|off]}()\\ \\ + fig.\textbf{suptitle}(title)\\ fig.\textbf{tight\_layout}()\\ plt.\textbf{gcf}(), plt.\textbf{gca}()\\ mpl.\textbf{rc}('axes', linewidth=1, …)\\ - fig.patch.\textbf{set\_alpha}(0)\\ + {[fig|ax]}.patch.\textbf{set\_alpha}(0)\\ \verb|text=r'$\frac{-e^{i\pi}}{2^n}$'|} \end{myboxed} % diff --git a/handout-tips.tex b/handout-tips.tex index 8b1f7ca..40ea3f1 100644 --- a/handout-tips.tex +++ b/handout-tips.tex @@ -114,7 +114,7 @@ \subsection*{\rmfamily Offline rendering} \begin{lstlisting} from matplotlib.backends.backend_agg import FigureCanvas canvas = FigureCanvas(Figure())) - ... # draw som stuff + ... # draw some stuff canvas.draw() Z = np.array(canvas.renderer.buffer_rgba()) \end{lstlisting} From 7f52e6beb324a042e24011d6a752bb0ce9d888e8 Mon Sep 17 00:00:00 2001 From: Steffen Rehberg Date: Tue, 7 Dec 2021 17:08:47 +0100 Subject: [PATCH 11/65] Fix FixedFormatter - use FixedLocator with FixedFormatter and change labels to something more appropriate for a FixedFormatter - add docstrings to pass flake8 --- logos/logo2.png | Bin 0 -> 22279 bytes scripts/tick-formatters.py | 12 +++++------- 2 files changed, 5 insertions(+), 7 deletions(-) create mode 100644 logos/logo2.png diff --git a/logos/logo2.png b/logos/logo2.png new file mode 100644 index 0000000000000000000000000000000000000000..72843ab1febbed35a00fc5c248f308f66d38cc24 GIT binary patch literal 22279 zcmd3O1y`F*7j1BNcXxMpcPQ>IMT4h!ai_SuOL2FHQYh~3u7%=o^M32z|8N({lPsdo zo-=38*?Ui-)K%qB5D5_h004@Dy!00U0Fo4ZKNubsd_;H}Fa+PgS}4g$13v%zE9fat z{_g>xyuLg570dr!AtdRuLEwMFc_^sJ!0o_7VF>YU#oG}B0OSA#X$dXR+J&(fGADC=uR6-RkD0FF>}CoiLSRt{x&ObvlY}DrD&igAMiZKg}C-u&K{XZTJ65cry-DhK)#ru7* zB?x|#({b1Wte_I1b$TYXs1z!oEqe&(0{47>?+dNuaaayAr<;@$DPhV&T3M#flP8jx z!Az!_RbuYAiN6n|IluXh#gO*N3jYTYg#u6|i$^}y<2Qg9_nZgW&uO9B7Vpz{R`e&_ zCx5*fLxxoBDqxbs>>UTWNOM1VS z0)}6Tu|U4_85{1jLJT1ek&zpxzt{lngX2f$@u?j1HqNm%F63_@f$dr5xK4b!LLIN_fGoBF0g9ZQ!K&xNAc5VaKhre1M1HJ(d5`bl_uBY{2 zU{3N8F)ja!u|@i9zFUpMuoQUM7$6Z?Mi~_dZ=a+v&=i20xKyP7E@oh$-}3uQZI*81 zB%M;ZlSt6Gbz{KMn3Pam%h?~}Q8=QPDCEy!W5X514d4ZE1~CF~q)Y7C_&!uJp^aFe zaS7puJ$^pKNED{~cX6x;3?5BrJ>ZLPv{d zukb$regzdVvTDfH!n7PRP!e_kRAGRaL0Ay?=uZR=?}3}=fpmA{lW!zJ(-3~JJ4lo) z^1K_@z$kdW$aad70(1CCPXun=djpBKq9glR@Wcx*5nrriwV()*ySy5VI8T!2tpU)I z=bSwSIyo^n7Fp;Lg?QBdJIMSh${3MyZ~0$LGR@sHw9!+M#rMFp z(w6xt78<=KsI?5EVW1DyqbgbF2>0SWHJBkG;(B53&)%%2d*X?~m4MaX0;sh<`U&_z z-O;D4di{$6;})f^-k_4{gwR-G9E>Lzb|p)AJ5#W`GfKdhMNE*1MZm9MaSt($N}fC< z5jF#}ztI_Kt;rSpB|92W)4EH$tRE#R~S?f%kbRJB#Id}1BZ*Tu2Ep6$dDVk8M6))9% zJ@1R-Mhn{KyA2jD>oYcOG3gk|5*${70I_X6F>=hW8K6R7D9r3#=Ce6K4P8T<@nw_e z>k_$4`R`=>A^dTeAFx0{ao!*%KozXIRKE#quVwCs_BQ5pdfH0g^oj3E zEvU+O47wJ0g6zrPGn*hbkajG%6A_-A*PXkce(`~ht5IeYFlmWJpw+fhA{s(`C^jvk zU%I}F7r@-smu9+JZ9DTfy0nekwtOe=U28@n3+#hwGW8>y&krE7CE>xx%jL$jgnP7q zGC&RT1#ApV!T|CVZPH@>-99=PXNiV?fIfeUz4g_~GC>2(C>h*(MO^;P_72L3l>qtS zF%zDCLJS)rVwRI4e+X|mSXD2|L}#3QC9fC(Cm!I;U<(EJ7Z{W{-$IIWwL=dI?qhD`Nd^Qt)l_Uw7>0hp?!OJuVCehndl#*W)pczyl`}pe!yhig4gUzCmZOltBf3PZ0@MKQNttz2MQq6y`sAJ1 zw+>wTk)Co;@+i0X$Foq4KVGFY_UK4!l9!Shi4QPRJl>4BB=W`JnL2!d;hkyg#aOdoYk_yCwd0JVl}9Rjw#3w*u-#6ERmk<^Ie`%L*T zM4B$59FK0zPa(^Q_Ks0 zO|Wqp|2J94Wo$>V?d;r#ypW9XEX66f)Sz#O2eXJ)j(-kr=!y;-IxOu+&&yf<%EhDj zowoGSz>7b8$0j;9p(Yl(eLd!%AUu2IZ>6tVLFSg5sRz70ZTB3!1zqGW@_%mW0@orX z^gzD|POe%DwvEQQp6882b)_h2gz#1#=Sz`8|D=sg0Al|+O3D66Lf@!Hn{e>9 z64T9d&$7iXjcqeINmbQea)Q_(37>IDFcE8*%VHmJ{RjG-q^OpbR&$SQma@VrGB^>r zf4U*+h=HK0-XUW1KHxuYw+Oif7|`HuP`K2tPDFLFX{_DFwZqPvpB}sSD{%xBx_Lj( z(Nl){g|Yghc~S8K0NWu?2#_R~EJi?%ya2(4#9=A!JcXwJ0=AzWZ8ifk4pcIJv>Pn$ z@zuB7#ikVsMAYvJP}e^nn^Jp+%m1jyc{C9vosTD58szz6Xc&W+?~iD>3|l~Hehh!`t&exY+sfEbpv#^mq52@?6le6zju*?5^;*ZY|F5)OEmZs)8K z*UR%~;M$gv1_wVsvqnCJ*PHU@uWSO=0ln$aH7#S1H$u?s*(cPW_E{_U68%*4)A`B5 zHGeiS_2lOHF6i`(a+v=`MZpnC5eJMk81E?}458DipZUF+9Y{fs5XewLWUbc&hiGiy zr|bugAB|#qJEmOlkYR5p#XjPHp7)M64{-uFPgj3#U7h5ef*da=c%ve!%4p|bHX5YZ zivrP%p2xrB0LS)0|Be{&xhiy@$dM;4ZRmmwEv9^a)w&5u1vg*|7K?(BPohpYdy{fo zzyH{V!g<&;TV&AlmF~>bqar2bCf+!9NP<>dsgf1`aw7=fA4c6~i6ZBEgt_4e5(V7c zJ{kg7rRsLs_Tz`&V$>pj&G-@cer~qis_s^|1MO&Q#i-ggUpwaR>9^b94iC*!y<{}Z zxCyD!P;F$te&yd~aE){ncgmxzq%w3(CB1bId;^LM6M? ze2_qnzckX=JTua1Va9}oce*0lm4xs`&hW&_&hWGp3ZMryzmwU>h;Xq71Ve3}7`aAs zv1v;vtHKtUt?7&DN#pFK_)@0j-Lk;$s8vn1QI%uTsj9@M zv$N6rqxFih!T0lN(X!p?K!^g)za!F@a;jYC#^~_1N5BCg)y-z?>UlSH7!%B9NZ0?e z7G2oNujpp{gpz9>+Ep6H7@6;~O@aQ(W3S-pR{6MWvGtp5Z`Og%Y{FHJyUTgxZo1*V zBXB2vf8*qJ@WObTIjNJ5Dc%GMLb!c&IEou_=fFp0)xRyX?1dM6zOVJ|ih~+^2`X#Vy zlRZmdh^Z9ZAPP6# zZ6)Erl!&|UIx{4|(ig#K$xls4m>243Ne-_L6X{KAMV} zk`LdD78PA70LMN`dSwFB<)*jQ4(iL-EoJl`wucO+>XhCZO*Hc|smMena-?K?SbCBj zdw^LHBZ5&0Bu$Cpx)ilbRRZlbaBBcOT_+?=m?)+#n-vBqN>0M%F<+!)XyvE05E`K? z31by)-jD}j*?65U;0GvES83=Cjkiji|4>y-n>?R%O|?J&YO8i16c$oU4wmNX=mL4f-`lytI-SX)pV3 z;2@m55Ykm~WeNw&ND~RRX+nx%0WFjm){r_p@4G#^cB0~X)NL|D#j650$}^gRu#f2( z$7|Ighcy03tPwhA6g?Ir9Jwn^M)z>Hs>=?}$frp&TN&0Ux0;JW8k_APv<`ddS&Rp8 zh=8B-g+Z7OhakQ?csr^>U1LF)$;9+YrD)nZKVw^IP9dG^$w($K0WkQuCyxcMj0_nj zrilQ4G9~+#d0F6-N&ct5En4uT0?fOobh-H6tQm4$MIxL;FsU+10(zxeFs;85a%evD z8yb`c@Brrmrao9aAI5sqaM8slI(be$LC(!tT{dL#iUm!M9f}>EB{t~;bbRnOWN9c} zN_pM*%(PGX*m9=#B~=6Y43pq-G9ZX4qcSDPMZ37WbIyF^mk`XK=UF}Bu6MD4nL?S|TE6yLIp0V)oMAgbwkENns8DsE^qB8+kl zg|B9)5Jo6TekE=kAs@#iMTRU!^qk+hZK9J#FLJWPWUb#)GyZ(h_J~rplHCvZ^65eg zi=}Rxc24{ahAadW)wZG@$tKK+Dy}ZKLCrNiuLk$*4%oDO@*%;>-`W~H$ueNqvz~;p zbPGN>Wg!9De%%e8az(qSY>E(1JPKmxXyBa@LiA|U!S!kNJn;2Cnj#n)J`QJd3`XS?Rmm`<)RHmBGuB@BJmi_5iqrRnYU!hM{>PzPzv9 zt*yLOEqh^j`6F3uVna9PmcZ3gU7i@SD94hj=%ggf_RTAs2h)Fn@nw4VYvrKlCYOf2 z-gBy8J0`xj=%~M@p+#N>5{JfLD+rpqZgx9Y;Kc__0LIYxv#VRyNLz7_jrRz7jv*$j z&_F-p^moV^XqVl${JkF2f6q4*~ zyF7OL(75+zDL6<4=>y{uJpe&rTBjFFaJS0Y{%!+ORneYi%1Xf_N5U{q1DSlsRUp__ zOSge}^-?nNj3f}zlOxH2XZ){cypk6YezqGc!M}Gdo(G36mN$g#&dL<0@O?fz9;vqt zTx_3Mj|=)x((6;hx+L&e;Zf6Z&s~Vd#8jt%AZ1FyCKU%YlL1rfaYI0-5JCwQAYNC( z0US1uyH(Z53dUN{`zRimsZbysaazD6=pV_-JoD3fSb2+EKi$fu7kG&k*VaCH@R>CB z5IYKZ6Vh{uj`0BWpVZ3M7%$${%$o^(McaO_C(NUZD0-bS&Tu`(0bSfi7|Q=tN(#-% zAx=q4lMQGRnS%g$s|p}Mby@Frj+sUnxJU?I)r+>D#d72d!1ydRK8%CP>SoHA@qMjl znCADXNdPl=I}S2e>EeW3HJ#CoN1^`z*yT(H2rarZ`A-3WGq|!qfxDybRMCOt_i`#y zXdc$l-zBZ%Oy0_Q?!;z#a-pZ_+|_LmTp{^xs+oU*3&|S?Z|-qE&vfXuHQQRrFiepq zuF8MrqLXrx-387gwo(3BXsu-r{cS~@Ufk%n`*;SJ82C9pz?Xi; zXQL3&W?uI%5}#r?w`Rk5tKDSlH2;ASDVDH*PtP9oggbT+yrj8wCoC&x@}Vhxj|)|4 z887{~_V>srYck&h40nzNr?bUqcX+ZD9c5f5;-%&tTU5277NOq`&@(>be$;o(0oU;; zBPmey^h6FoSCWMd8UE=to$ajf2kpy7Oas?YboDf`5HdWTU-sifMEiA}ZJ}B`*O~!D z%t)|^@4x;-H}n1=2>$CqCfCP1f7eY@3mEOg5qcJuu<2td1qFm|6E-j#p>ALh9UYAb z4!EL{5@;M89PnyxX2Y!ig84_duY<#T;Z~m>%rJ>_iv4&*0ZX>%b%hLzI# ztz656m0;vfdS&uL;B|o%0Vp+82KRIXxouzN8}z?fS8J~jqQggzf;=4AtLcBq_Hb5% zQ}}!$O&!2eCkd_TRcx2S2cgl&MzuC{_}Hqwl==rCAwx9~RMUT=1W9(i7~m(OLU z^F*i~6T-RVP)4JqUU&Z;Z$-ewHB4(|F3{n{%WO(7VGrtD;>)_!pkZFoo)aH|D+V zAA>R04(?LGs2X6WR97e7_DwSa-&^81X2G=~#$)uRbHwy5zwA<+jqHhKkV!r(BJxR33mE3MJq zWVY`FSvDy2CtN%~+*S+#?W{)Cye#ZT2^;+QX)`anv+9p-;&>?HNp6yF-x}IyV&N3C z5uSMBUB=|vwM}Fn22yk3%T3Ca7S=HTx_f)Cv!AZqsJ}aI^1i(payW0*!75eDS>&S$ z2>eu=zPNA%XBEjLYG%+5#zs>k@gYwDbcjU8)DiEZe3uQOhC#D!pZ8oRPf=qdW|bC9 zQ)y!NiHBfGX(3nFTn7VJOMz=;&1AM(5<@L}pir7?5<3d9KVo~vZj=}{15HLxDa&Y2U3q8IkM&G39+6KaC-^U zK#x0L0uZ2iw>kE&$X-ZR#kmCgN7vfdehv<0tZfJ`^US{Z)0l6h#r>2ke}h2sgD9Eb zNDH~;b6krN#0_dp`wqMJ%`28$^xl>bjr{K5t=8AY;CWeYmT)(m`Tkw5M@&vC8;SVS zB8oBu&th)^WeYoPtcqE5f6omD?uIrs8oaMB=f4){`j}sw)JJ%2_xgkL#wBqU4Y*)f zSZvAHOEl-$tt*co4RK*k(9@15-5|1r^{mkF(yb{9+H;0)0L5G|wrP5BrBXNeVn$V_ zkpl3Yr+OXyFKf;>#3e+Z>KOu|uBVe%Bn4YcLi)EoH}+&;Vy;gcFz8EdQZ^IKlpex zWO2sCBbrh5_d%r$h;OR`6UL!yEP)Im#L&b^H3Rao#piraT1ANchSG0jAq+PIz3F5X zQM*}e0O9`#7P_7!v^|1BXaxHO?PTo-j=5PJfFKv4Az=D~T-XLyRy68LXeu5yjNYh&22oDd> z_;}>hkAnxF#O&;ttSmxe@4={*UMHrH=OF_l;Toqo&ejM52OYn73aRjgrq8s|H5S9x z{>`65b#uZc=qxc{$QtV8la6D zKt^j>WCk(AlF0PaQ;(^*Wihe!8S3v2Zhr!YL$tk0`%|@`cPRAh0t?T!^U5wVE|QT{ z$@e+{xfy$O>kw&Ia4@DUY~5{?cdjORf8xLIBV;7JOl0j1=Lpjmq`6k^4xF zb(YeEky88)yJks1>%aWd{nle{&WW+45+TzwO@!oabNI~%dU1(Ii(0`1jXVGaadegO zoNu&wUg>+)nRNqRzoqtZ(E*!0&g5H=i3_OLBg$4Srq4$>$-l>s6oV9IhGoDP#a;FH zwMMViu8XT@rRp_hyviTnvs-fqIdba#+&bPJGQQ?ImgC3Q+p8`Y%d>^Q#n;p=E$oDG ziT2GVb$EED0W`RiuQ*IzDZ5WwKfBz+y%dI$7UQIXGYhNix!V3Dm9p(l#u$2C7rXPC zkKT8TPfkjMsf!#{x=8rwB54|I@pepSa80mqts?LNuWWFG$!PxumO{*V2waaU2I!4C zShu{pjkF)q$Aq7Zd;^B&)gtyXHb@M~S-&sn+=gIvC3ScGGV2yEVP<9P?pkd5^*^yE ziIhgY2%<Wd{1)%GeM zJF*m1Sg^<#6c!eZ2I_h&%}ZdcI!r&aUX-Ee{&wOqdW|EaQ*Y{r0+oLP|43^fRLU@c zgeQ72&XfUYXx=A|{d-c3Lyu=B`v1HDTvc>(EC_S|NoA+J9J@?&pLz|GO-wRS+o@K) z?^!j=+x29#Tlt_0(Ve&&;b}sGJ2*hR{7F1xF6vGuh&55qbA)rf$?+7QkK51Ub0=Hn zMJ1dYtatwqS-g%MnTfvZ+^Y??1{FpZOdRex-S(XntEBkRmb^TSZk=N<*d}S0i`I_N zvGiFZAvxxo8i;_e^MN0|Joa8x%$Bv8bz^>51p=;qk+w znE4(@#88Ec80`DlwJz0X73tIKByq->=)lynaS)y`KffvPvfP~g*hKt&Z|(`sx^GZ3U@U_fZZiU+=chX$O4ZZ5sI_hu4LZ(iRqHscq` z@T3qQhM%~m!Fg885DReV!DJOt;P zTRkXf@4u+p7&P@W@5JA@xDre5NT35|)5^$5+zSO0~j+YvA(;5c^Tx@jJ`g8;Nm8%MsWJr=drCIa!}c55y%j8XI!6?1U_PdCMUu1C!# ziHObXys4IpzKh_>50{aV(X4HKeX_MdkGZ0vB65un+;$9@z1|X*qmo5}i*RXUa^(PJ zSP@yYShXEp9M7-Ay}4dBW#I+YVfyT4(k;}7z=54_hha!;>$gQ?WY?vF6?|0R$pc{< z&w27c^oF6-v3O*(E0P3NOQahgTV&25YE%ZL-f9)`_lGM{z>9jKOmz)Cj@DVzU}rNlD%X2s{+{qY~!Le9n2 zw25t6y@)6i#X6pumlr=VG2zw6)osdm;wk9Y)4~CLyfU=MG(=$l!Al#;!xIYK2tGVDL(G!mO#AxzlpQBzP(7PPT5AoHEy-Vw4tsXN^{(I7IlqOHL-)ODF^&{3MfOlW!Gh&z1dV{g1zba?> z{?{?M{x)hiVqI8Vlwo;V5*PLB9k%|8EJz}Yb{4frL^#b&M@(w_UWeUj(AaHkd;(NK z;b>$#b3>$4rLO1W6y7RDx>5lpSo=$6CMYkwqR9zU-|l3SbI?Aeu^J`f7amA&Aen^w z*c;A{xFXlrg{_lW5Wt~@jwTOQwO6XIq>fcSxWvep#G{9EpMIA7lXQ9H{6A2L8LOPuu`&gDGVee7arutV2!VB4m! zq~sgt7w`&u;Uxr4H-GZj34CKW>))1-q-F|W(UD=Z^@W#yei9BPprWcBXC{?iJguWIKJH_{A& zF%}{*DTkSS>vmZU?xQKLJBJD#K|5v??1r~JV<8P*dp66{>~)kF94IW2@4{LUuD!uw zeWAGBXG3a}aN!OG-iVJ|e>tqf#iPV(W@e`!`EZ(bRYOa~W7SKmk=5#MJ@E}~F&NG& z9#*+167~M9jT7tm=8b@Qx!QaGXN;^T#9*gy=P*yB^>17&Pc*jlYOyW2 zmR6#85gQ}wA6iM&;Q6$$ApOY87>&7jn3R}^p)KnVOdxiA?wM6G<2;$&bc)F(mUo*t z3aZkS;X8!p=8>NFhG8Kcgg9vabT8BSUIEtg`I#{%9rhkD2`1@ou+>8<%`Ktn^g?-=yJ2b=s-w;Ws-=X^wcoe1z1t!gBv6Uv#9(bBK#3 zfk%~2*FzHujZ34LaIHh!G-7G%Dj*phEahgb@h?nJo-M$QRKwU9MO$0r%RizER;s)XTO#M4 zZ(i9j+m5_M_6`okNzwlx&4^}x)UM=z#OUI zbc+q01#L_d}z0ilGbMqD`)1+XxVCHfB$B#Jay z)-s}_Yct1xHBr34#Na$ZRzcDCsH5PhE@PxPbvL3^m2Q%gfukxN9?HjclfX!JL56-% zSjCsD5|zSCzN?Tdq!VyPJwpDWE>`lQg?bE=ryRP_FnK1A9vIx$3s~y`Gc8EyE6fn9Bu~{qrdcZ!UvbPM-zv_E$%hqXd?cpO@nQX_(j)=vqmfc zGbOI##-;5Nmnpc>wK)WEMN91^TO4Gvut!0iu4;exY67E6x6^w9^bSx2TQKTlhE-pT za$Cl-V|h<9j4eDvk}@91PmL(EdCKivfy%ieq54_m9DfcAgqa)l*#(KCWS6+)D`*uN zwTT3*ydZ*O3WBxT4XUKKSsJjr*bGvQXLH(oa-owcx-Y=yy+j*lvA9<7sI@kqVDYD^ zbn>`aG|0D~Lh?aM;IQ?)3!A(ji?M%OE7ki@;2<8@zPW|_94S*V)VP2NxLU<>zQVB7+1?OUuAg2AS`~2qE~vjPu^}a{5iA0 ziz04?MuYb0+50l`=kh-nz-^kmW*8T5^0oc!c{R1Z5=w>|CIl=`aY@1~lv3z7P)2vlVZrLlMm2iXt z#(Ud@aTrc46`Gxq$INddOEEotu!=M;(a1OFKEQgnew2s9{ht(TfhwFr5jP7?#diBf zB<)llkoz;{6QksljRQuoST8~~3)bnWvFoqYc?}}Pke=;t^$E_(iWN^sJvM#TyxE2H zid`IZHcbRoRjseN;VEnX?j`1?XtkDkdW&MAhW9X*7Isjx(-G|KQ-=02JbBtjj<6Mz zHn*AK=wU4_i6W3bEcJywFuS0C-u?RfyI=2K&LKSQy9e2X%&Yk0o{l0dJb(f=X1l82wPia$##LZlOB7U@j}= zl{Gtl0X-tPdAsifE+L|$l51nbNJA?mQGS|gYlGbY@=4G(uv~nvtQb7i-{@it8;7(}BnLq2KK_dLFc)y;xzYcU4uI*uig2tq{Fn zfDk4Lc3^;8LZ2Se=pwN6h94&zDp@%0O<247*`cj1WtyoCjIZC4c(3U4pT_Z>{5`=qT$*<33djYCKw2Dv};v$rqG!hDGnu#L6wyjhA-cXikt~@N-{p515PBqOA(A7wZ)Rxx% zZW>TMgqD3?|1}~O?CfKV1t3?T64X0yvf;bGDVUv@&2h2z-54q7xru@y;N;|7YtaIq z6qq`dY3bKvPV?HAxc3oZ##I{Ln>7%FvBuF!F8tM(ioad$V|KOzj~5xD#2jESQ{^`r zM+^8WnLy8=aP1qV9Yg7O8-zy^yMT!noGr-S*bz6MH*<>h3t80a>;@n|wy-KC*?7+y zWWpaL!5n3nW)aC?cRs=R-kMU%ptP6P+qiJwkTn(Di>vLjl011_TkAlWFtedDQx!%n zLc+sQ(cN5rr>{Y?KQ_hlZ#T}YX)3jXy0+Q+AHkaSFA@3P z;}x~ZfM3u`StKE-B8XI@4+9UDqufow3rkCTzwq*g+6?&$Rpm}ri{Wa!EpcVziKF1i zzM)gm#Y$&Qg)1b}nqNQW@4GZPgV)K3nNp>78b=ETXgno=J#$4Z5_e2?WfjVBdus{z zsFabWR3X@+PAM%{Lxx!q9XHomRRWjJS=lo{?elyc$Q%P#ECnY;^b;6mXGhKT^kc@= z0PD}!XA!-^M>N>EMEcuEnzDkpIR3>!pv9nM3gm4)yL6PChEY``$J1&iLCXjE91E?L z!PL#-Q?Y@tJ=8`Oj^*YNVa=z^=pRY~&wy~AsqfArr~`#k;rpWuR69WK?bmJ-mrxHa z9i6>~{G4wS4B(<2?4cT1x-?|>8rAcAy>H8K-ACT&aw018 z_&G8tg|;mA-x-Wcq-WELTX0(-8} zOyg7)|15_4ZZR!J>5&&MkNIz2rKd|Y8DVh?A}LNDTzG05PleiktuZSTkT521s0m=N zntrXd5VjAa9wjt)k{(7A9#gmV_L2y~Bj%CT4N}szVHmqv!t2ZVHmw^{shay;SQzJ@ z$99U}BEv_h0rA%hGFN&wzF)0bz}VdXaV_Ys!tKoxT$x|P#Yol`N$WNZpAxcOc=8Og z3I@X?5fMKcbsXE@{~bz0M<=|d=AX8Z3N4n`VHlh( zj(GX}z@?WQGYdN;!Ij4ol;`-bUjxB#xcjXRpV8msZ1(Ba8N zL`1^9NwRnJyRw^$%)GzCym)*)=&(-Z;Xs{T7y;EQcqN+UMPg%SLrnr>!tSCTLZpF6 zvQw#Lc2fe9+_7r21iVEdi3Txn6;j5?P8WG328;rk!%|W67k1m|ok0?Gbn?7g<~N+h zd18zok463sCMV;+`y|I3vC;9Og=Q=m2%mY8k~R<8l;|SjLkfIILik3P-&Rlw*JCDT zgvP#`tUe@d`~GI{Hhtvn3w(L193OAqkL`;Mnp*0ln6__e%^oz+(h40>6N@tKraAdG zrA0hfj1-%8y5t$I_3uA@71wD<$MS)gV7YJIQ$+8lPD*Mj4;31q-eH-QIp9bE+a10`S9!4i zO5mpU9YQ9?ROUmaZD(d6#IVPCF-!YIpwpJWMSBcvxdOw$U*cjKo9~8@_X0$yB}$AR z(2rfO>w|2Y{8yk`w>3T)Yx1wCstQrHoQqK)YAd01ys>m>N&4OMJa6S6Izw13t~P%Q z4}}WKz`gNqOFu(9FSUPs7u}yf+TuOn&Q$FLx};Oy=r~%)*fSLZy_!O@^FUs=%ZYWD zoVvI}@Q9axV?YxiC=D$48#OEv)6eiYI6Ngs*G#H+4m0a)Rb*g8Pp4U^#m1JUt~id& zR$5rB%(!09a*T)SvfVx2USs1jZ(A?c@uw-$VS(nG&O#V^NS<{WP^tHr9;kga5g)bP z-hUoRu(&CZpl4!oNQHi@zlFOeB=E`>dgZTowJg3pPT?ArT7GBu>tqVeI}L?X`#tLZ zI6c&7`fj_xj12(OavJCLVCG1ghC}SL6%DGBhfcZgBF+gO=Kcj701C?l1B)b8l>^i| znQ8RTwYV~Lxpdv4Kbi@1gBCCnZfvNv9#l1wnmDY!b#;>41ONd@4L)) z+bv@-@eRI!o86yDfWUFI5Ct@aq#s=ENC9grImz3?`>KAux)Iy`okC{X;HQYh@EvmB$(1*fAiyi?o^v#5{5s~u*Y${7nBJy_F^?_Ucu#>9=uL$6yeVFAdO$uZnb z7^Y5Zt5-Z=y4S?TLn?LF&QU_t#P3Z(m_LxBMu#bb0PNHOJ5NrwdW68%3k}Wrjrw+* zOF|EkB8TBSvxZC!ZOz3ATFLf{m(%vo-}Yb!23UHJy>bpa<|n%9e21+uZfRV7wAPPj z*e@+BE0bZo`2g?hx&DCzQ~bh5%ly-*Ph?3KT^w;B$?m-*L_sq|=Dax;ShAj{pksQj z*Q?|~W^2~bcC&@(0r^E%c$kk0de5DsdA*5bqT6s=>4#fW@q~R~L+fpu!Z%rMoSe|8 z5$+!a-*CizszyaLXEMjBI8OBct0ys?B8rlaA`MIc^(BngBRt!wPrTVU57{NENx%*B zh@GKpUO5`<2CHBzE30N;8#lo7b(B9Q=0aZZ>qhN?Fm;pxDP{}kWMq`qO_TR( z1i^d1tU%GFqx@TE^hc0`;=m_FJL7lW8fJgX*{!D+?%rc(AHjT&$z71;gPO*9?1@Kb z1uHz@Kc(^O*RM!(yAM9*O{)f4zC4-ACv&Apk?^noE{F2`eG8^%{#)|#k--iVsvv;Z z^;X>8o&`FFo4Y$z17Ufb7}B^1Hko5(@GmPwylN`)&rnB?+uE^MqPl^r&8~HAp*ZyR z7fCmbC7teu7dmA@8@q!h5$jYAxHQO_^5ZGDaz|A7F@6Mld->ePWoqu}%vEr|UIE9k*(CerTM}oE*ogxYvVj49XG$VhxO&m-}zR=22yY9ApPLSjyoN|^^3@@OW+NveSBoDyau zR+dVc7ONBGD!j+{ky1#A$j1Hm+~0ZIKcjMeN>3w1LEudX=p}z)ZTIdV5I=bT;ySLk z^4PD(#KaUY1wXsZvtoa%2L8zyqRf9k{{6(6k5WRES|u5VhQa~%iiey00H<%({yL(aQ00$T9)=!Uz&n(S{3p#G)s*C^SB4Ik!Sod zOh8O#sAv8-j(5rV9UX05y%eTv7D8%E;z@5}cq?^Z+-b61##G8MH#Y~i0fWtI;OeM2 zDIWIiX+Ht@;Lht9YGwlt2-K-jHKMg?-oEqRh@1X1w*_dNj42ziVDLS2cC2jZze%$C zdbIb`T4}w-t6A3m-`HHL*v`T(RMx3CvvC9K7KE1s;$tf6;sSbIFl(BO<@#P51wsTb z;49<4@mR`RlVz_(j@)%d&LbxV_G>C^>W}-7i~cvkz%L`7p2FuWjFS_G0WGR>VNf zQ=$#)4Ze@g|Fy`AQ+EATY`TSy873aj+lRB4Ocdvp?Tu%-S?7v}pL;Z( zO~Mm1!SVH4t0)P-8=f*Tl=t59aL!m;al zEYn}K^PpT~q#9p3u!Gc@p+i)`=E(RvMA9_vnjhHyQ3HUc8rUWUx;UHBO!!@8aUQ|B z%SX_6{RT{DMO8^Hs2p;ikwjha*3M&jZLxIikKB9OrOJUT>eEs7r!N4@WMEyVx_qBr z@?bmreM0S{H&GPW@QCCU5bT&Cmo8x z_i&28Bv`tAa53+0`((CFR5iqV0)rPslS=ZGV}Bvv+mdH+nCmQ8@m*UdB|{tm;qO=}AJ~?#JBW4Hj710Y-)RPnDV`7mVvaQWv&P9@Ts- z`IM?e8Na(xry`AOJd+b)S-H2h(3Q23?hoSH^54iN^jOtCQ1x-fZ*%cdD$QZ^UQKJp zO0KZP7RQoO{Ft*9y*)bIZM;DJ&MeQ6UBB|d@JyF3f#AB1^|C$ahXy64O&q!s=lwP; zRyG94g)+fKY#@^Y%*b4`yHJ{jWpS$an>XbAqjl!|>`0RM_;_0azw0}nx4OD)Y;0K1 zcRU;x&vkP$`TXP=If1V1>h4~dNXf0~QB?R*m_oU%Kh+SV3sk+Mcu>r>VodCAAvMah zynF4jo>M+EIY`g5^_*GJY+faW9z;LHWk7X{fkCm03%F_1m%qOynbRoGVPP^(XFs8c z^r<6krB#V+CDw$1FgF9SL(P0SrL&6uLR$F~C55$SrBT4dQZljMo9F>s61x-Mr3NawS*fS5E+=hcu{Sec+A&FeJ^GT2fPN-Z(x$X2ma%6Sdkv=mCpo1-#?De{q;R_ zn7Be-_~r#!xV<)+${5qfsjMeK8Qqkx<%7qfUr}k3Z^-#E;4$DweNGfm)>7ln-Y?z3 z*vIj!4D?!0`#X?z^w=q2b{dG?-^vex3J3%bzz(o}HTP9j2CziCflJfTf(Z6O8*w&TqJU&_ zd~8!;TH((jphVKQj*DW6=8LnlI(C+_4}$+NqA4XJtD8U7&8oaBdr2&;JuXn$Bw(6q zED%FkZ@r_0k*$%j1(}~be@+s|!4=;vulAN#rHoo>1#qSJvS0_O6fON6{1K~FI%$tA z4$=9%Zk#E6d@fhB%(2u5%oAjBS2XVA{Gl5aj3AqW?0E6w`$%>h^-d&&eCAQo{P8?s zUG38ZhiNtN-h5cG5$`gqH0_H70eymqWw|KXcYw$R%qf7_*!f9#<6!o^kq=MPq< z>DDRVpRJ*Xu9U>tjT}7Lj)lbb?!#5L9KaC(!~@V=0_gEUQ8WpoB>v`TMwn8&O}G$X z@cLO+hD)vxpo<6BKSm+ulfceWynKAAcfEM4cAb{L>(=l2QsBl3SXZgT9(16!MIE!! zG;cD5)%R&RXkqwe=w6dX+Gd^8g=Dg-j-t@_?5`zm+OJJHJjP&7IPK@-tP<@G_cGevhC0SR*GC^jdv|%Hw7) zH>pRDrGuW6eHss5KK4Km{sJT&{E@S5-s`6w^+t##x$!51mJ&3Lk9@dqzDta9C7c*; z6YQX1p?uT#5=c2U+1k=kS$}Cb8^7PT#@xDLtv?aKl9bhqH7!~agWeqTYrO%M<;O}Iv7TT4~cPmxt?gB~h-$Hz;mjWEqb zP>k1>DjR3NH$dUw;OZGUA{r^>K2Y(}bTI$)qim#omT1)PI@;_z%+Ai@KRkd<>6^JT za7xDc+4ApL9aEsmEZ0A8V5Q11 zT_auQOMAMdwYmlm#IY!igY;*z{^{a3MKW%wQ2P!O1|q3|4%2j;)tH!=e@&uNBx6V2 z!PmHVuDZ&n3?oFFT=3Io(y*T~I;6V;0|Pb?MvKEkg8Vx-i}d}Xv0L=%z`FOg^o#sa zKkYRZ^1}I!PIzNx$|oHkLf6Lr{CuA}IGAyhee^%+`b9?>6FR+JJ|~a6ZufMCX3hpu z{*gO(;n+}XR1=$*05V(dq2}_6-YOc^CD4mty4C8;zX{=6URQ~4*lVfV^u8aN$E7&a z^fLPTxMsGJTyIxa%V(It#j~2#klTnuPZ}EHO_^rQpd&;XRXIvUGsdr zsRLrP*=%T>njkmq^{UW@xRH|56ftcr^74w7n7OfnuPiL&`+FJ^eF@01^(UZ8%NK#+aTMTxc( z!JuL9Q)3t?Q{mgR)O7=ANIxRbyV!Nd6`OJvQN|l^?X}w?)Dp2{Cu*Rf5VKGHL`2`CXR{}>& zg)Lc$dE_Xgh;_=B=dc*CdMQkius4vw64$AgkCS^bmz6np6ZRHNdinssIFXgg@Wd@@fpF=hURb=}csD5S)+w|#kp zSa(`K8YRS9%^;(nxZM`eFM#R`E$-4|+Wl=n-^bAA;M6BvSK@r-x3>#p6a5XN&_t1u zMOmZw`mAnvqZSX5EYSlk;`((&BsT>zY5jP}gmE*hlV?@=B;sZd*lfD=4R3!ST&yi& zd|V5eU+}vG<;1bO&kd>z^kzv^l{6cd#W@LoL9=KkY=17lF(in?XRP^9z)>Yt!QQ8d znaU3c1$`LqDZAoEl#96bcecU~FNwfJ+Xv&52z$;mz3_oHrqpl5PC}zG;XxwX#D*m= zKKPD)i#Ylnhey05G$A?!(zJf?H^)8U?|yo`(*h+FBesl8UIIUHj8LLQRu{T~{o|SH z?eDVdml~1W+DeoD{Dd4KT6!D)kfaEIM@7M< zSxWJ;bfpT32Q!enm|OJtRmM`gdcxxn5t7!*a7djAmZ^49<6qn&!y`>n2q>xTX`wcV zxwSAt?_ECC)UZ#zArqHinIu)C$+B&At`~lPbSU>LC*(s%@_+HwDo?_lggK`^97t>EvTG&o+ zO@(^*>l9{#9PTn>{VJv!LV4ii?%JL}1huGb4GucN^;*j-*_e7+>fxOYWZkbM1`DuSW8Pbyj=JN-W}G9ZO+AluW1%awr^3hI{#!Niv8HH5 z&Yqm)Tsj?%-#gl?Iy#B~u)9YqOj{>a{BZ$~b?5Z`Vv47rzK?!mUROuODrlSso}Q90!em?>{x12%D73-vS_(qOEN3Ena@AP(LRN! zO=H~ZpnnMQusyan%`QJSO7|*+_;AX2cN@A09*WUjUN1EAR-E3onH6M4yG03&IO+PJ z^_+5O%R)+-R>a-XmHb}$Q{Y~(#&GqP*sBi&ciq$Fd3WJM3%i#-DrqK1A{NY?&ILQS z9{C<}3v}QHMirvUi+xRMKHzD#RR!=sn$k0)91_&fb+$m$!KxkmwZtuWav`9D8DRD! zd^98(^MPqqRG)nD`_j>-6{va9C7;*+f%JWs)a^U`C0^FWGaD@$f_iFy?Z?fkb?#4w z7-GlILj}26W6Z<%@c%NJ?vG$8+fRkz!Hk9zxd^Uj8ouaj z{^}#Bv0&grmDGT`iJMS=y+$Ydv|aJ`pYS|%uF2BO_`D!mVq-npUDu_dS4F-o#Fj}1 z!$Rj~QJcdZ{^ZdrD2ncrr$qZR5yWE<=p_ka=^26=DRKBInd`axkaX(Z*zHs2(_H-; z+xX$$Rq6MTT}j0nFNHu7SGh@Q(!3{q^I^kvbsnN37}u>LoER+x9*eaX&+I$(w#()R zr+f_tI?oq9?)}$|R$4dF;>TBiKRp^7{*pT4MRGDUQU7Q6nB~0LO7@WtGb`R%NHJkN zz|p#9V3EG=^XMk`=4X~tsIj0!-?n=Z8^XK;M)zzRKTq;k?Ub`Z(vn1Rx3;z(U#FQm z^1QGwSq~0U#2?gUB&yEu%MWEO!U9I9KQSv-9qI>#nz5%>kdp`=cA=+t`SyiAtivy3nRfEh?8bOH8D_jNRjlf@ zP+PXBGpjXtwlV1>3pPOA=ivMTNsVsH;LTsme~`ALk$_FaM$6wgqHDi=N?$TH)gc@OKAq~Ne^HeQ11-%~;W|e<4!W836cir_a>W%mo$kcg-X8-nt zk7VoH&#*ZcWn1~?*#Y3tsx{BTu(4Rbst$7VmS#1Sq-}Pv8YL)Pk`x*()MBAce8?p( ze*astLo+?7{3#|3(;{r!_RXr3RQmfu>U*E zsE5P&d1J1%1#8<4#Sa~Gnvf6@`u9*QAo#{;r(kL4Mpj6rAv|VsQ>uzVTJuM`kLr7U z+T=@T$?%H&?oeJR&oz5ir`M{+Jiy&z^(LWmf#JaFniHEvyh7&U^cDXnH5^Y0V?azC z58l=ORaoh(O9rB(H-5!*;y)HzXR}WeO(3A3Cwi>)U)nR0W&@Y3bu=sOV=O~+2(&Q4 zM{9~zikFB;5wXO7_Q@wGr_p=QF uzQ^tNM)>2D^H83=IPL$>ho<5I@Ab+|0z*Y85Ab9yhKhp5>#|p-0sjN5vy}$` literal 0 HcmV?d00001 diff --git a/scripts/tick-formatters.py b/scripts/tick-formatters.py index 8566554..fe5bb40 100644 --- a/scripts/tick-formatters.py +++ b/scripts/tick-formatters.py @@ -3,7 +3,6 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- -import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as ticker @@ -11,6 +10,7 @@ def setup(ax): + """Set up Axes with just an x-Axis.""" ax.spines['right'].set_color('none') ax.spines['left'].set_color('none') ax.yaxis.set_major_locator(ticker.NullLocator()) @@ -43,20 +43,18 @@ def setup(ax): # Fixed formatter ax = fig.add_subplot(n, 1, 2) setup(ax) -ax.xaxis.set_major_locator(ticker.MultipleLocator(1.0)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) -majors = ["", "0", "1", "2", "3", "4", "5"] +ax.xaxis.set_major_locator(ticker.FixedLocator(range(6))) +majors = ["zero", "one", "two", "three", "four", "five"] ax.xaxis.set_major_formatter(ticker.FixedFormatter(majors)) -minors = [""] + ["%.2f" % (x-int(x)) if (x-int(x)) - else "" for x in np.arange(0, 5, 0.25)] -ax.xaxis.set_minor_formatter(ticker.FixedFormatter(minors)) -ax.text(0.0, 0.1, "ticker.FixedFormatter(['', '0', '1', ...])", +ax.text(0.0, 0.1, "ticker.FixedFormatter(['zero', 'one', 'two', …])", family=family, fontsize=fontsize, transform=ax.transAxes) # FuncFormatter can be used as a decorator @ticker.FuncFormatter def major_formatter(x, pos): + """Return formatted value with 2 decimal places.""" return "[%.2f]" % x From d72ab92635df378381345bc39df55ba44582dbfe Mon Sep 17 00:00:00 2001 From: Steffen Rehberg Date: Mon, 13 Dec 2021 08:32:33 +0100 Subject: [PATCH 12/65] Update to mpl 3.5.0 - make room for two additional annotation arrow styles - add possibility to set tick labels together with tick positions --- cheatsheets.tex | 4 ++-- scripts/annotation-arrow-styles.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index f79664b..d1b46f4 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -710,8 +710,8 @@ ax.\textbf{grid}()\\ ax.\textbf{set\_[xy]lim}(vmin, vmax)\\ ax.\textbf{set\_[xy]label}(label)\\ - ax.\textbf{set\_[xy]ticks}(list)\\ - ax.\textbf{set\_[xy]ticklabels}(list)\\ + ax.\textbf{set\_[xy]ticks}(ticks, [labels])\\ + ax.\textbf{set\_[xy]ticklabels}(labels)\\ ax.\textbf{set\_title}(title)\\ ax.\textbf{tick\_params}(width=10, …)\\ ax.\textbf{set\_axis\_[on|off]}()\\ diff --git a/scripts/annotation-arrow-styles.py b/scripts/annotation-arrow-styles.py index 6bff923..648a4c4 100644 --- a/scripts/annotation-arrow-styles.py +++ b/scripts/annotation-arrow-styles.py @@ -10,7 +10,7 @@ def demo_con_style(ax, connectionstyle): transform=ax.transAxes, ha="left", va="top", size="x-small") -(fig, axes) = plt.subplots(5, 3, figsize=(4, 2.5), frameon=False) +(fig, axes) = plt.subplots(4, 4, 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())): From 4007098638e3359052754e48eeced1afef0c5128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volker=20Wei=C3=9Fmann?= Date: Wed, 15 Dec 2021 16:07:42 +0100 Subject: [PATCH 13/65] fix --- handout-intermediate.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handout-intermediate.tex b/handout-intermediate.tex index 38fb97e..7af7e8c 100644 --- a/handout-intermediate.tex +++ b/handout-intermediate.tex @@ -83,7 +83,7 @@ \subsection*{\rmfamily Figure, axes \& spines} % ----------------------------------------------------------------------------- \begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}} \begin{lstlisting}[belowskip=-\baselineskip] - fig, axs = plt.subplots((3,3)) + fig, axs = plt.subplots(3,3) axs[0,0].set_facecolor("#ddddff") axs[2,2].set_facecolor("#ffffdd") \end{lstlisting} From aec0df4f91adced09f977bfc35b5635c37531233 Mon Sep 17 00:00:00 2001 From: Jamal Mustafa Date: Sat, 23 Oct 2021 13:29:56 -0700 Subject: [PATCH 14/65] make cheatsheets column width exactly 57 mm Notes: The A4 long dimension is 297 mm. With 2.5 mm left and right margins and 7/4 mm spacing between the 5 columns (4 gaps), this gives (297 - 2.5*2 - 4*7/4) / 5 = 57 mm wide columns. --- cheatsheets.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index d1b46f4..c75b7d8 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -104,7 +104,7 @@ \setlength\parindent{0pt} \setlength{\tabcolsep}{2pt} \baselineskip=0pt -\setlength\columnsep{0.5em} +\setlength\columnsep{1.75mm} % --- Macros ------------------------------------------------------------------ From b20eb400d417933da0f381c1a7816923ef9bc017 Mon Sep 17 00:00:00 2001 From: Jamal Mustafa Date: Sun, 14 Nov 2021 10:54:51 -0800 Subject: [PATCH 15/65] start refactoring using style sheets --- scripts/advanced-plots.py | 14 ++++++++------ scripts/basic-plots.py | 30 ++++++++++++++++-------------- styles/plotlet.mplstyle | 15 +++++++++++++++ 3 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 styles/plotlet.mplstyle diff --git a/scripts/advanced-plots.py b/scripts/advanced-plots.py index 025378a..73f3527 100644 --- a/scripts/advanced-plots.py +++ b/scripts/advanced-plots.py @@ -3,15 +3,17 @@ # Released under the BSD License # ----------------------------------------------------------------------------- -# Scripts to generate all the basic plots +# Script to generate all the advanced plots +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt -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 + +mpl.style.use(pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle') + +fig = plt.figure() d = 0.01 ax = fig.add_axes([d, d, 1-2*d, 1-2*d]) @@ -19,7 +21,7 @@ # ----------------------------------------------------------------------------- X = np.linspace(0, 10, 16) Y = 4 + 2*np.sin(2*X) -ax.step(X, Y, color="C1", linewidth=0.75) +ax.step(X, Y, color="C1") 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) diff --git a/scripts/basic-plots.py b/scripts/basic-plots.py index d7a0c35..1fbe48f 100644 --- a/scripts/basic-plots.py +++ b/scripts/basic-plots.py @@ -3,15 +3,17 @@ # Released under the BSD License # ----------------------------------------------------------------------------- -# Scripts to generate all the basic plots +# Script to generate all the basic plots +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt -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 + +mpl.style.use(pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle') + +fig = plt.figure() d = 0.01 ax = fig.add_axes([d, d, 1 - 2 * d, 1 - 2 * d]) @@ -19,10 +21,10 @@ # ----------------------------------------------------------------------------- X = np.linspace(0, 10, 100) Y = 4 + 2*np.sin(2*X) -ax.plot(X, Y, color="C1", linewidth=0.75) +ax.plot(X, Y, color="C1") 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) +ax.grid() plt.savefig("../figures/basic-plot.pdf") ax.clear() @@ -30,11 +32,11 @@ # ----------------------------------------------------------------------------- X = np.linspace(0, 10, 100) -Y = 4 + 2 * np.sin(2 * X) -ax.plot(X, Y, color="black", linewidth=0.75) +Y = 4 + 2*np.sin(2*X) +ax.plot(X, Y, color="black") 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) +ax.grid() plt.savefig("../figures/basic-plot-color.pdf") ax.clear() @@ -47,7 +49,7 @@ 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.grid(linewidth=0.125) +ax.grid() plt.savefig("../figures/basic-scatter.pdf") ax.clear() @@ -61,7 +63,7 @@ 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) +ax.grid() plt.savefig("../figures/basic-bar.pdf") ax.clear() @@ -142,7 +144,7 @@ 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") +ax.grid(color="0.75") plt.savefig("../figures/basic-fill.pdf") ax.clear() @@ -157,6 +159,6 @@ 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") +ax.grid(color="0.75") plt.savefig("../figures/basic-quiver.pdf") ax.clear() diff --git a/styles/plotlet.mplstyle b/styles/plotlet.mplstyle new file mode 100644 index 0000000..b86d240 --- /dev/null +++ b/styles/plotlet.mplstyle @@ -0,0 +1,15 @@ +figure.figsize: 0.4, 0.4 + +figure.constrained_layout.h_pad: 0.01 +figure.constrained_layout.w_pad: 0.01 +figure.constrained_layout.hspace: 0.01 +figure.constrained_layout.wspace: 0.01 + +axes.linewidth: 0.5 + +grid.linewidth: 0.2 + +lines.linewidth: 0.75 + +xtick.major.size: 0.0 +ytick.major.size: 0.0 From 5ea8b48b8d8fdd0ce2bb63f9d788566166b14b98 Mon Sep 17 00:00:00 2001 From: Jamal Mustafa Date: Sat, 23 Oct 2021 14:15:56 -0700 Subject: [PATCH 16/65] continue refactoring using style sheets - add base style with constrained_layout enabled - add style for the ticks examples - add style for a grid of figures - resize figures to a maximum width of 57 mm - small tweaks to arrow connections to accommodate change in figure size --- scripts/advanced-plots.py | 6 ++- scripts/annotation-arrow-styles.py | 19 ++++----- scripts/annotation-connection-styles.py | 21 ++++++---- scripts/basic-plots.py | 6 ++- scripts/interpolations.py | 20 +++++++--- scripts/projections.py | 27 +++++++------ scripts/tick-formatters.py | 49 ++++++++++------------- scripts/tick-locators.py | 53 ++++++++++--------------- styles/base.mplstyle | 5 +++ styles/plotlet-grid.mplstyle | 10 +++++ styles/ticks.mplstyle | 17 ++++++++ 11 files changed, 136 insertions(+), 97 deletions(-) create mode 100644 styles/base.mplstyle create mode 100644 styles/plotlet-grid.mplstyle create mode 100644 styles/ticks.mplstyle diff --git a/scripts/advanced-plots.py b/scripts/advanced-plots.py index 73f3527..3ad36c0 100644 --- a/scripts/advanced-plots.py +++ b/scripts/advanced-plots.py @@ -11,7 +11,11 @@ import matplotlib.pyplot as plt -mpl.style.use(pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle') +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', + pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle', +]) + fig = plt.figure() d = 0.01 diff --git a/scripts/annotation-arrow-styles.py b/scripts/annotation-arrow-styles.py index 648a4c4..046c3e1 100644 --- a/scripts/annotation-arrow-styles.py +++ b/scripts/annotation-arrow-styles.py @@ -1,16 +1,17 @@ +import pathlib + +import matplotlib as mpl import matplotlib.pyplot as plt 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") +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', + pathlib.Path(__file__).parent/'../styles/plotlet-grid.mplstyle', +]) -(fig, axes) = plt.subplots(4, 4, figsize=(4, 2.5), frameon=False) +(fig, axes) = plt.subplots(4, 4, figsize=(5.7/2.54, 1.5), frameon=True) for ax in axes.flatten(): ax.axis("off") for i, (ax, style) in enumerate(zip(axes.flatten(), mpatches.ArrowStyle.get_styles())): @@ -21,13 +22,13 @@ def demo_con_style(ax, connectionstyle): xy=(x0, y0), xycoords='data', xytext=(x1, y1), textcoords='data', arrowprops=dict(arrowstyle=style, + mutation_scale=10, color="black", shrinkA=5, shrinkB=5, patchA=None, patchB=None, connectionstyle="arc3,rad=0")) ax.text( (x1+x0)/2, y0-0.2, style, transform=ax.transAxes, - family="Source Code Pro", ha="center", va="top") + ha="center", va="top", fontsize=8) plt.savefig("../figures/annotation-arrow-styles.pdf") -# plt.show() diff --git a/scripts/annotation-connection-styles.py b/scripts/annotation-connection-styles.py index 64fa300..4382cbb 100644 --- a/scripts/annotation-connection-styles.py +++ b/scripts/annotation-connection-styles.py @@ -1,6 +1,15 @@ +import pathlib + +import matplotlib as mpl import matplotlib.pyplot as plt +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', + pathlib.Path(__file__).parent/'../styles/plotlet-grid.mplstyle', +]) + + def demo_con_style(ax, connectionstyle): x1, y1 = 0.3, 0.2 x2, y2 = 0.8, 0.6 @@ -9,29 +18,27 @@ def demo_con_style(ax, connectionstyle): xy=(x1, y1), xycoords='data', xytext=(x2, y2), textcoords='data', arrowprops=dict(arrowstyle="->", color="0.5", - shrinkA=5, shrinkB=5, + shrinkA=2, shrinkB=2, patchA=None, patchB=None, connectionstyle=connectionstyle), ) ax.text(.05, .95, connectionstyle.replace(",", ",\n"), - family="Source Code Pro", - transform=ax.transAxes, ha="left", va="top", size="x-small") + transform=ax.transAxes, ha="left", va="top", size=4) -fig, axs = plt.subplots(3, 3, figsize=(5, 5)) +fig, axs = plt.subplots(3, 3, figsize=(5.7/2.54, 5.7/2.54)) demo_con_style(axs[0, 0], "arc3,rad=0") demo_con_style(axs[0, 1], "arc3,rad=0.3") demo_con_style(axs[0, 2], "angle3,angleA=0,angleB=90") demo_con_style(axs[1, 0], "angle,angleA=-90,angleB=180,rad=0") -demo_con_style(axs[1, 1], "angle,angleA=-90,angleB=180,rad=25") -demo_con_style(axs[1, 2], "arc,angleA=-90,angleB=0,armA=0,armB=40,rad=0") +demo_con_style(axs[1, 1], "angle,angleA=-90,angleB=180,rad=10") +demo_con_style(axs[1, 2], "arc,angleA=-90,angleB=0,armA=0,armB=20,rad=0") demo_con_style(axs[2, 0], "bar,fraction=0.3") demo_con_style(axs[2, 1], "bar,fraction=-0.3") demo_con_style(axs[2, 2], "bar,angle=180,fraction=-0.2") for ax in axs.flat: ax.set(xlim=(0, 1), ylim=(0, 1), xticks=[], yticks=[], aspect=1) -fig.tight_layout(pad=0.2) plt.savefig("../figures/annotation-connection-styles.pdf") # plt.show() diff --git a/scripts/basic-plots.py b/scripts/basic-plots.py index 1fbe48f..64e07fc 100644 --- a/scripts/basic-plots.py +++ b/scripts/basic-plots.py @@ -11,7 +11,11 @@ import matplotlib.pyplot as plt -mpl.style.use(pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle') +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', + pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle', +]) + fig = plt.figure() d = 0.01 diff --git a/scripts/interpolations.py b/scripts/interpolations.py index 2a135ef..783d26c 100644 --- a/scripts/interpolations.py +++ b/scripts/interpolations.py @@ -1,6 +1,16 @@ +import pathlib + +import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np + +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', + pathlib.Path(__file__).parent/'../styles/plotlet-grid.mplstyle', +]) + + methods = [None, 'none', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos'] @@ -9,14 +19,14 @@ 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=(5.7/2.54, 5.7/2.54*2), + # 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) - ax.text(4.5, 1, str(interp_method), weight="bold", color="white", size=12, - transform=ax.transData, ha="center", va="center") + extent=[0, 1, 0, 1], rasterized=True) + ax.text(0.5, 0.1, str(interp_method), weight="bold", color="white", size=6, + ha="center", va="center") -plt.tight_layout() plt.savefig("../figures/interpolations.pdf", dpi=600) # plt.show() diff --git a/scripts/projections.py b/scripts/projections.py index a262050..fde46cb 100644 --- a/scripts/projections.py +++ b/scripts/projections.py @@ -2,12 +2,20 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import cartopy import matplotlib as mpl import matplotlib.pyplot as plt +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', + pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle', +]) + + CARTOPY_SOURCE_TEMPLATE = 'https://naturalearth.s3.amazonaws.com/%7Bresolution%7D_%7Bcategory%7D/ne_%7Bresolution%7D_%7Bname%7D.zip' @@ -21,26 +29,22 @@ # Polar plot # ----------------------------------------------------------------------------- -mpl.rc('axes', linewidth=4.0) -fig = plt.figure(figsize=(4, 4)) -b = 0.025 -ax = fig.add_axes([b, b, 1-2*b, 1-2*b], projection="polar") +(fig, ax) = plt.subplots(subplot_kw={'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) +ax.plot(T, R, color="C1") ax.set_xticks(np.linspace(0, 2*np.pi, 2*8)) ax.set_xticklabels([]) ax.set_yticks(np.linspace(0, 2, 8)) ax.set_yticklabels([]) ax.set_ylim(0, 2) -ax.grid(linewidth=1) +ax.grid(linewidth=0.2) plt.savefig("../figures/projection-polar.pdf") fig.clear() # 3D plot # ----------------------------------------------------------------------------- -mpl.rc('axes', linewidth=2.0) -ax = fig.add_axes([0, .1, 1, .9], projection="3d") +(fig, ax) = plt.subplots(subplot_kw={'projection': '3d'}) r = np.linspace(0, 1.25, 50) p = np.linspace(0, 2*np.pi, 50) R, P = np.meshgrid(r, p) @@ -58,10 +62,9 @@ # Cartopy plot # ----------------------------------------------------------------------------- -mpl.rc('axes', linewidth=3.0) -b = 0.025 -ax = fig.add_axes([b, b, 1-2*b, 1-2*b], frameon=False, - projection=cartopy.crs.Orthographic()) +fig = plt.figure() +ax = fig.add_subplot(frameon=False, + projection=cartopy.crs.Orthographic()) ax.add_feature(cartopy.feature.LAND, zorder=0, facecolor="C1", edgecolor="0.0", linewidth=0) plt.savefig("../figures/projection-cartopy.pdf") diff --git a/scripts/tick-formatters.py b/scripts/tick-formatters.py index fe5bb40..c652846 100644 --- a/scripts/tick-formatters.py +++ b/scripts/tick-formatters.py @@ -3,33 +3,35 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import pathlib + +import numpy as np +import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.ticker as ticker + +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', + pathlib.Path(__file__).parent/'../styles/ticks.mplstyle', +]) + + # Setup a plot such that only the bottom spine is shown def setup(ax): """Set up Axes with just an x-Axis.""" - ax.spines['right'].set_color('none') - ax.spines['left'].set_color('none') ax.yaxis.set_major_locator(ticker.NullLocator()) - ax.spines['top'].set_color('none') - ax.xaxis.set_ticks_position('bottom') - ax.tick_params(which='major', width=1.00, length=5) - ax.tick_params(which='minor', width=0.75, length=2.5, labelsize=10) ax.set_xlim(0, 5) ax.set_ylim(0, 1) ax.patch.set_alpha(0.0) -fig = plt.figure(figsize=(8, 5)) +fig = plt.figure(figsize=(5.7/2.54, 3.8/2.54)) fig.patch.set_alpha(0.0) n = 7 -fontsize = 18 -family = "Source Code Pro" - # Null formatter ax = fig.add_subplot(n, 1, 1) setup(ax) @@ -37,8 +39,7 @@ def setup(ax): ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.xaxis.set_minor_formatter(ticker.NullFormatter()) -ax.text(0.0, 0.1, "ticker.NullFormatter()", family=family, - fontsize=fontsize, transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.NullFormatter()", transform=ax.transAxes) # Fixed formatter ax = fig.add_subplot(n, 1, 2) @@ -47,8 +48,7 @@ def setup(ax): ax.xaxis.set_major_locator(ticker.FixedLocator(range(6))) majors = ["zero", "one", "two", "three", "four", "five"] ax.xaxis.set_major_formatter(ticker.FixedFormatter(majors)) -ax.text(0.0, 0.1, "ticker.FixedFormatter(['zero', 'one', 'two', …])", - family=family, fontsize=fontsize, transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.FixedFormatter(['zero', 'one', 'two', …])", transform=ax.transAxes) # FuncFormatter can be used as a decorator @@ -63,8 +63,7 @@ def major_formatter(x, pos): ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(major_formatter) -ax.text(0.0, 0.1, 'ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)', - family=family, fontsize=fontsize, transform=ax.transAxes) +ax.text(0.0, 0.1, 'ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)', transform=ax.transAxes) # FormatStr formatter @@ -73,8 +72,7 @@ def major_formatter(x, pos): ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.FormatStrFormatter(">%d<")) -ax.text(0.0, 0.1, "ticker.FormatStrFormatter('>%d<')", - family=family, fontsize=fontsize, transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.FormatStrFormatter('>%d<')", transform=ax.transAxes) # Scalar formatter ax = fig.add_subplot(n, 1, 5) @@ -82,8 +80,7 @@ def major_formatter(x, pos): ax.xaxis.set_major_locator(ticker.AutoLocator()) ax.xaxis.set_minor_locator(ticker.AutoMinorLocator()) ax.xaxis.set_major_formatter(ticker.ScalarFormatter(useMathText=True)) -ax.text(0.0, 0.1, "ticker.ScalarFormatter()", - family=family, fontsize=fontsize, transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.ScalarFormatter()", transform=ax.transAxes) # StrMethod formatter ax = fig.add_subplot(n, 1, 6) @@ -91,8 +88,7 @@ def major_formatter(x, pos): ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.StrMethodFormatter("{x}")) -ax.text(0.0, 0.1, "ticker.StrMethodFormatter('{x}')", - family=family, fontsize=fontsize, transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.StrMethodFormatter('{x}')", transform=ax.transAxes) # Percent formatter ax = fig.add_subplot(n, 1, 7) @@ -100,12 +96,7 @@ def major_formatter(x, pos): ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.PercentFormatter(xmax=5)) -ax.text(0.0, 0.1, "ticker.PercentFormatter(xmax=5)", - family=family, fontsize=fontsize, transform=ax.transAxes) - -# Push the top of the top axes outside the figure because we only show the -# bottom spine. -fig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=1.05) +ax.text(0.0, 0.1, "ticker.PercentFormatter(xmax=5)", transform=ax.transAxes) -plt.savefig("../figures/tick-formatters.pdf", transparent=True) +plt.savefig("../figures/tick-formatters.pdf") # plt.show() diff --git a/scripts/tick-locators.py b/scripts/tick-locators.py index 276f8a3..c6521c0 100644 --- a/scripts/tick-locators.py +++ b/scripts/tick-locators.py @@ -3,50 +3,47 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import pathlib + import numpy as np +import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.ticker as ticker + +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', + pathlib.Path(__file__).parent/'../styles/ticks.mplstyle', +]) + + # 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') ax.yaxis.set_major_locator(ticker.NullLocator()) - ax.spines['top'].set_color('none') - ax.xaxis.set_ticks_position('bottom') - ax.tick_params(which='major', width=1.00) - ax.tick_params(which='major', length=5) - ax.tick_params(which='minor', width=0.75) - ax.tick_params(which='minor', length=2.5) ax.set_xlim(0, 5) ax.set_ylim(0, 1) ax.patch.set_alpha(0.0) -fig = plt.figure(figsize=(8, 5)) +fig = plt.figure(figsize=(5.7/2.54, 3.8/2.54)) fig.patch.set_alpha(0.0) n = 8 -fontsize = 18 -family = "Source Code Pro" - # Null Locator ax = plt.subplot(n, 1, 1) setup(ax) ax.xaxis.set_major_locator(ticker.NullLocator()) ax.xaxis.set_minor_locator(ticker.NullLocator()) -ax.text(0.0, 0.1, "ticker.NullLocator()", - family=family, fontsize=fontsize, transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.NullLocator()", transform=ax.transAxes) # Multiple Locator ax = plt.subplot(n, 1, 2) setup(ax) ax.xaxis.set_major_locator(ticker.MultipleLocator(0.5)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.1)) -ax.text(0.0, 0.1, "ticker.MultipleLocator(0.5)", - family=family, fontsize=fontsize, transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.MultipleLocator(0.5)", transform=ax.transAxes) # Fixed Locator ax = plt.subplot(n, 1, 3) @@ -55,40 +52,35 @@ def setup(ax): ax.xaxis.set_major_locator(ticker.FixedLocator(majors)) minors = np.linspace(0, 1, 11)[1:-1] ax.xaxis.set_minor_locator(ticker.FixedLocator(minors)) -ax.text(0.0, 0.1, "ticker.FixedLocator([0, 1, 5])", - family=family, fontsize=fontsize, transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.FixedLocator([0, 1, 5])", transform=ax.transAxes) # Linear Locator ax = plt.subplot(n, 1, 4) setup(ax) ax.xaxis.set_major_locator(ticker.LinearLocator(3)) ax.xaxis.set_minor_locator(ticker.LinearLocator(31)) -ax.text(0.0, 0.1, "ticker.LinearLocator(numticks=3)", - family=family, fontsize=fontsize, transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.LinearLocator(numticks=3)", transform=ax.transAxes) # Index Locator ax = plt.subplot(n, 1, 5) setup(ax) ax.plot(range(0, 5), [0]*5, color='white') ax.xaxis.set_major_locator(ticker.IndexLocator(base=.5, offset=.25)) -ax.text(0.0, 0.1, "ticker.IndexLocator(base=0.5, offset=0.25)", - family=family, fontsize=fontsize, transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.IndexLocator(base=0.5, offset=0.25)", transform=ax.transAxes) # Auto Locator ax = plt.subplot(n, 1, 6) setup(ax) ax.xaxis.set_major_locator(ticker.AutoLocator()) ax.xaxis.set_minor_locator(ticker.AutoMinorLocator()) -ax.text(0.0, 0.1, "ticker.AutoLocator()", - family=family, fontsize=fontsize, transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.AutoLocator()", transform=ax.transAxes) # MaxN Locator ax = plt.subplot(n, 1, 7) setup(ax) ax.xaxis.set_major_locator(ticker.MaxNLocator(4)) ax.xaxis.set_minor_locator(ticker.MaxNLocator(40)) -ax.text(0.0, 0.1, "ticker.MaxNLocator(n=4)", - family=family, fontsize=fontsize, transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.MaxNLocator(n=4)", transform=ax.transAxes) # Log Locator ax = plt.subplot(n, 1, 8) @@ -96,12 +88,7 @@ def setup(ax): ax.set_xlim(10**3, 10**10) ax.set_xscale('log') ax.xaxis.set_major_locator(ticker.LogLocator(base=10.0, numticks=15)) -ax.text(0.0, 0.1, "ticker.LogLocator(base=10, numticks=15)", - family=family, fontsize=fontsize, transform=ax.transAxes) - -# Push the top of the top axes outside the figure because we only show the -# bottom spine. -plt.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=1.05) +ax.text(0.0, 0.1, "ticker.LogLocator(base=10, numticks=15)", transform=ax.transAxes) -plt.savefig("../figures/tick-locators.pdf", transparent=True) +plt.savefig("../figures/tick-locators.pdf") # plt.show() diff --git a/styles/base.mplstyle b/styles/base.mplstyle new file mode 100644 index 0000000..77cbdce --- /dev/null +++ b/styles/base.mplstyle @@ -0,0 +1,5 @@ +figure.constrained_layout.use: True +figure.constrained_layout.h_pad: 0 +figure.constrained_layout.w_pad: 0 +figure.constrained_layout.hspace: 0 +figure.constrained_layout.wspace: 0 diff --git a/styles/plotlet-grid.mplstyle b/styles/plotlet-grid.mplstyle new file mode 100644 index 0000000..c4133c3 --- /dev/null +++ b/styles/plotlet-grid.mplstyle @@ -0,0 +1,10 @@ +figure.constrained_layout.h_pad: 0.04 +figure.constrained_layout.w_pad: 0.04 +figure.constrained_layout.hspace: 0.04 +figure.constrained_layout.wspace: 0.04 + +font.family: Source Code Pro +font.size: 5 + +xtick.major.size: 0.0 +ytick.major.size: 0.0 diff --git a/styles/ticks.mplstyle b/styles/ticks.mplstyle new file mode 100644 index 0000000..a2fb14f --- /dev/null +++ b/styles/ticks.mplstyle @@ -0,0 +1,17 @@ +savefig.transparent: True + +font.family: Source Code Pro +font.size: 5 + +axes.linewidth: 0.5 +axes.spines.right: False +axes.spines.top: False +axes.spines.left: False +axes.spines.bottom: True + +xtick.labelsize: 3 +xtick.major.pad: 1 +xtick.major.width: 0.2 +xtick.major.size: 2 +xtick.minor.width: 0.1 +xtick.minor.size: 1 From aeeeb3b11457bd6bee82a056f56565451f38fa36 Mon Sep 17 00:00:00 2001 From: Jamal Mustafa Date: Tue, 23 Nov 2021 21:19:21 -0800 Subject: [PATCH 17/65] finish (for now) refactoring using style sheets - diminish scope of pdfcrop use - migrate more scripts to use the base mplstyle - continue migration to subplots usage - refactor to use common subplot_kw where possible - add style sheet for the sine plots - make more DRY --- Makefile | 14 ++-- scripts/adjustements.py | 71 ++++++++++++------- scripts/advanced-plots.py | 76 ++++++++------------ scripts/anatomy.py | 12 +++- scripts/basic-plots.py | 74 +++++++------------ scripts/colornames.py | 24 +++---- scripts/extents.py | 24 ++++--- scripts/legend.py | 27 +++++-- scripts/plot-variations.py | 118 +++++++++++++------------------ scripts/sine.py | 97 ++++++++++++------------- scripts/tick-formatters.py | 74 ++++++++----------- scripts/tick-locators.py | 67 ++++++++---------- scripts/tick-multiple-locator.py | 46 ++++-------- styles/base.mplstyle | 8 +-- styles/plotlet-grid.mplstyle | 7 +- styles/plotlet.mplstyle | 6 ++ styles/sine-plot.mplstyle | 24 +++++++ styles/ticks.mplstyle | 11 +-- 18 files changed, 378 insertions(+), 402 deletions(-) create mode 100644 styles/sine-plot.mplstyle diff --git a/Makefile b/Makefile index 530fc09..f193644 100644 --- a/Makefile +++ b/Makefile @@ -14,10 +14,16 @@ logos: figures: # generate the figures cd scripts && for script in *.py; do echo $$script; MPLBACKEND="agg" python $$script; done - # crop the figures - cd figures && for figure in *.pdf; do echo $$figure; pdfcrop $$figure $$figure; done - # regenerate some figures that should not be cropped - cd scripts && MPLBACKEND="agg" python styles.py + # crop some of the figures + cd figures && pdfcrop adjustments.pdf adjustments.pdf + cd figures && pdfcrop annotate.pdf annotate.pdf + cd figures && pdfcrop anatomy.pdf anatomy.pdf + cd figures && pdfcrop colornames.pdf colornames.pdf + cd figures && pdfcrop fonts.pdf fonts.pdf + cd figures && pdfcrop markers.pdf markers.pdf + cd figures && pdfcrop text-alignments.pdf text-alignments.pdf + cd figures && pdfcrop tip-font-family.pdf tip-font-family.pdf + cd figures && pdfcrop tip-hatched.pdf tip-hatched.pdf .PHONY: cheatsheets cheatsheets: diff --git a/scripts/adjustements.py b/scripts/adjustements.py index 807474f..f433a69 100644 --- a/scripts/adjustements.py +++ b/scripts/adjustements.py @@ -2,62 +2,82 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib import numpy as np +import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.patches as mpatches from matplotlib.collections import PatchCollection -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=[]) +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', +]) +mpl.rc('font', size=4) +mpl.rc('lines', linewidth=0.5) +mpl.rc('patch', linewidth=0.5) + + +subplots_kw = dict( + figsize=(5.7/2.54, 5.7/2.54 * 95/115), + subplot_kw=dict( + frameon=False, + aspect=1, + xlim=(0-5, 100+10), + ylim=(-10, 80+5), + xticks=[], + yticks=[], + ), +) + +(fig, ax) = plt.subplots(**subplots_kw) box = mpatches.FancyBboxPatch( (0, 0), 100, 83, mpatches.BoxStyle("Round", pad=0, rounding_size=2), - linewidth=1., facecolor="0.9", edgecolor="black") + facecolor="0.9", edgecolor="black") ax.add_artist(box) box = mpatches.FancyBboxPatch( (0, 0), 100, 75, mpatches.BoxStyle("Round", pad=0, rounding_size=0), - linewidth=1., facecolor="white", edgecolor="black") + facecolor="white", edgecolor="black") ax.add_artist(box) box = mpatches.Rectangle( (5, 5), 45, 30, zorder=10, - linewidth=1.0, facecolor="white", edgecolor="black") + facecolor="white", edgecolor="black") ax.add_artist(box) box = mpatches.Rectangle( (5, 40), 45, 30, zorder=10, - linewidth=1.0, facecolor="white", edgecolor="black") + facecolor="white", edgecolor="black") ax.add_artist(box) box = mpatches.Rectangle( (55, 5), 40, 65, zorder=10, - linewidth=1.0, facecolor="white", edgecolor="black") + 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, - edgecolor="black", facecolor="white", linewidth=1) +plt.scatter(X, Y, s=20, zorder=10, + edgecolor="black", facecolor="white") # Window size extension X, Y = [0, 0], [0, -8] -plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False) +plt.plot(X, Y, color="black", linestyle=":", clip_on=False) X, Y = [100, 100], [0, -8] -plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False) +plt.plot(X, Y, color="black", linestyle=":", clip_on=False) X, Y = [100, 108], [0, 0] -plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False) +plt.plot(X, Y, color="black", linestyle=":", clip_on=False) X, Y = [100, 108], [75, 75] -plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False) +plt.plot(X, Y, color="black", linestyle=":", clip_on=False) def ext_arrow(p0, p1, p2, p3): @@ -69,7 +89,7 @@ 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=.5, color="black") def int_arrow(p0, p1): @@ -85,45 +105,44 @@ def int_arrow(p0, p1): x = 0 y = 10 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) +ax.text(x+9.5, y, "left", ha="left", va="center", zorder=20) x += 50 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) +ax.text(x-4.5, y, "wspace", ha="right", va="center", zorder=20) x += 45 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) +ax.text(x-4.5, y, "right", ha="right", va="center", zorder=20) y = 0 x = 25 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) +ax.text(x, y+9.5, "bottom", ha="center", va="bottom", zorder=20) y += 35 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) +ax.text(x, y-4.5, "hspace", ha="center", va="top", zorder=20) y += 35 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) +ax.text(x, y-4.5, "top", ha="center", va="top", zorder=20) int_arrow((0, -5), (100, -5)) ax.text(50, -5, "figure width", backgroundcolor="white", zorder=30, - ha="center", va="center", size="x-small") + ha="center", va="center") 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") 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") + ha="center", va="center") 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") plt.savefig("../figures/adjustments.pdf") -# plt.show() diff --git a/scripts/advanced-plots.py b/scripts/advanced-plots.py index 3ad36c0..4d86ba0 100644 --- a/scripts/advanced-plots.py +++ b/scripts/advanced-plots.py @@ -17,23 +17,23 @@ ]) -fig = plt.figure() -d = 0.01 -ax = fig.add_axes([d, d, 1-2*d, 1-2*d]) +subplot_kw = dict( + xlim=(0, 8), xticks=np.arange(1, 8), + ylim=(0, 8), yticks=np.arange(1, 8), +) # Step plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) X = np.linspace(0, 10, 16) Y = 4 + 2*np.sin(2*X) ax.step(X, Y, color="C1") -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() +ax.grid() +fig.savefig("../figures/advanced-step.pdf") # Violin plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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, @@ -41,15 +41,13 @@ 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_axisbelow(True) -ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-violin.pdf") -ax.clear() +ax.grid() +fig.savefig("../figures/advanced-violin.pdf") # Boxplot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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, @@ -63,85 +61,74 @@ "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") -ax.clear() +ax.grid() +fig.savefig("../figures/advanced-boxplot.pdf") # Barbs plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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)) ax.set_axisbelow(True) -ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-barbs.pdf") -ax.clear() +ax.grid() +fig.savefig("../figures/advanced-barbs.pdf") # Event plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) np.random.seed(1) 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.set_axisbelow(True) -ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-event.pdf") -ax.clear() +ax.grid() +fig.savefig("../figures/advanced-event.pdf") # Errorbar plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) np.random.seed(1) 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_axisbelow(True) -ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-errorbar.pdf") -ax.clear() +ax.grid() +fig.savefig("../figures/advanced-errorbar.pdf") # Hexbin plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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) 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_axisbelow(True) -ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-hexbin.pdf") -ax.clear() +ax.grid() +fig.savefig("../figures/advanced-hexbin.pdf") # Hist plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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)) ax.set_axisbelow(True) -ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-hist.pdf") -ax.clear() +ax.grid() +fig.savefig("../figures/advanced-hist.pdf") # Xcorr plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) np.random.seed(3) Y = np.random.uniform(-4, 4, 250) X = np.random.uniform(-4, 4, 250) @@ -150,6 +137,5 @@ 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") -ax.clear() +ax.grid() +fig.savefig("../figures/advanced-xcorr.pdf") diff --git a/scripts/anatomy.py b/scripts/anatomy.py index 4a32544..a79037e 100644 --- a/scripts/anatomy.py +++ b/scripts/anatomy.py @@ -3,10 +3,19 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import pathlib + import numpy as np +import matplotlib as mpl import matplotlib.pyplot as plt from matplotlib.ticker import AutoMinorLocator, MultipleLocator, FuncFormatter + +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', +]) + + np.random.seed(123) X = np.linspace(0.5, 3.5, 100) @@ -14,8 +23,7 @@ Y2 = 1+np.cos(1+X/0.75)/2 Y3 = np.random.uniform(Y1, Y2, len(X)) -fig = plt.figure(figsize=(8, 8)) -ax = fig.add_subplot(1, 1, 1, aspect=1) +(fig, ax) = plt.subplots(figsize=(8, 8), subplot_kw=dict(aspect=1)) def minor_tick(x, pos): diff --git a/scripts/basic-plots.py b/scripts/basic-plots.py index 64e07fc..5dd8598 100644 --- a/scripts/basic-plots.py +++ b/scripts/basic-plots.py @@ -17,75 +17,66 @@ ]) -fig = plt.figure() -d = 0.01 -ax = fig.add_axes([d, d, 1 - 2 * d, 1 - 2 * d]) +subplot_kw = dict( + xlim=(0, 8), xticks=np.arange(1, 8), + ylim=(0, 8), yticks=np.arange(1, 8), +) # Basic line plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) X = np.linspace(0, 10, 100) Y = 4 + 2*np.sin(2*X) ax.plot(X, Y, color="C1") -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() -plt.savefig("../figures/basic-plot.pdf") -ax.clear() - -# Basic line plot (color)blaPwd +fig.savefig("../figures/basic-plot.pdf") +# Basic line plot (color) # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) X = np.linspace(0, 10, 100) Y = 4 + 2*np.sin(2*X) ax.plot(X, Y, color="black") -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() -plt.savefig("../figures/basic-plot-color.pdf") -ax.clear() +fig.savefig("../figures/basic-plot-color.pdf") # Basic scatter plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) np.random.seed(3) 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.grid() -plt.savefig("../figures/basic-scatter.pdf") -ax.clear() +fig.savefig("../figures/basic-scatter.pdf") # Basic bar plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) np.random.seed(3) X = 0.5 + np.arange(8) 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_axisbelow(True) ax.grid() -plt.savefig("../figures/basic-bar.pdf") -ax.clear() +fig.savefig("../figures/basic-bar.pdf") # Basic imshow plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) np.random.seed(3) 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() +fig.savefig("../figures/basic-imshow.pdf") # Basic pcolormesh plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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) @@ -93,76 +84,65 @@ 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)) -plt.savefig("../figures/basic-pcolormesh.pdf") -ax.clear() +fig.savefig("../figures/basic-pcolormesh.pdf") # Basic contour plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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)) -plt.savefig("../figures/basic-contour.pdf") -ax.clear() +fig.savefig("../figures/basic-contour.pdf") # Basic pie plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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)) 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) -plt.savefig("../figures/basic-pie.pdf") -ax.clear() +fig.savefig("../figures/basic-pie.pdf") # 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)) +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) ax.set_axisbelow(True) ax.grid(linewidth=0.25, color="0.75") ax.text(4, 4, "TEXT", color="C1", size=8, weight="bold", ha="center", va="center", rotation=25) -plt.savefig("../figures/basic-text.pdf") -ax.clear() +fig.savefig("../figures/basic-text.pdf") # Basic fill plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) np.random.seed(1) X = np.linspace(0, 8, 16) Y1 = 3 + 4*X/8 + np.random.uniform(0.0, 0.5, len(X)) 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_axisbelow(True) ax.grid(color="0.75") -plt.savefig("../figures/basic-fill.pdf") -ax.clear() +fig.savefig("../figures/basic-fill.pdf") # Basic quiver plot # ----------------------------------------------------------------------------- +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) np.random.seed(1) T = np.linspace(0, 2*np.pi, 8) 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_axisbelow(True) ax.grid(color="0.75") -plt.savefig("../figures/basic-quiver.pdf") -ax.clear() +fig.savefig("../figures/basic-quiver.pdf") diff --git a/scripts/colornames.py b/scripts/colornames.py index 0f0260e..d88d381 100644 --- a/scripts/colornames.py +++ b/scripts/colornames.py @@ -5,22 +5,27 @@ Simple plot example with the named colors and its visual representation. """ -from __future__ import division +import pathlib +import matplotlib as mpl import matplotlib.pyplot as plt -from matplotlib import colors as mcolors -colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS) +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', +]) +mpl.rc('figure.constrained_layout', h_pad=0, w_pad=0, hspace=0, wspace=0) + +colors = dict(mpl.colors.BASE_COLORS, **mpl.colors.CSS4_COLORS) # Sort colors by hue, saturation, value and name. -by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name) +by_hsv = sorted((tuple(mpl.colors.rgb_to_hsv(mpl.colors.to_rgba(color)[:3])), name) for name, color in colors.items()) sorted_names = [name for hsv, name in by_hsv] n = len(sorted_names) ncols = 3 -nrows = n // ncols +1 +nrows = n // ncols fig, ax = plt.subplots(figsize=(4.5, 6)) @@ -30,8 +35,8 @@ w = X / ncols for i, name in enumerate(sorted_names): - col = i // (nrows-1) - row = i % (nrows-1) + col = i // nrows + row = i % nrows y = Y - (row * h) - h xi_line = w * (col + 0.05) @@ -49,9 +54,4 @@ ax.set_ylim(0, Y) ax.set_axis_off() -fig.subplots_adjust(left=0, right=1, - top=1, bottom=0, - hspace=0, wspace=0) - plt.savefig("../figures/colornames.pdf") -# plt.show() diff --git a/scripts/extents.py b/scripts/extents.py index 28a0236..ba424d2 100644 --- a/scripts/extents.py +++ b/scripts/extents.py @@ -2,17 +2,25 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib -# Scripts to generate all the basic plots import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', +]) +mpl.rc('figure.constrained_layout', wspace=0.05) + + Z = np.arange(5*5).reshape(5, 5) fig = plt.figure(figsize=(8, 5)) +gs = fig.add_gridspec(2, 2) -ax = fig.add_subplot(2, 2, 1) +ax = fig.add_subplot(gs[0, 0]) 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]) @@ -23,7 +31,7 @@ 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 = fig.add_subplot(gs[1, 0]) 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]) @@ -35,8 +43,7 @@ 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, 4) +ax = fig.add_subplot(gs[1, 1]) 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([]) @@ -46,10 +53,8 @@ ha="center", va="center", color="black", size="large") ax.text(5.0, -0.5, "extent=[10,0,0,5]", ha="center", va="center", color="black", size="large") -plt.tight_layout() - -ax = fig.add_subplot(2, 2, 2) +ax = fig.add_subplot(gs[0, 1]) 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([]) @@ -59,8 +64,5 @@ ha="center", va="center", color="black", size="large") ax.text(5.0, -0.5, "extent=[10,0,0,5]", ha="center", va="center", color="black", size="large") -plt.tight_layout() - plt.savefig("../figures/extents.pdf", dpi=600) -# plt.show() diff --git a/scripts/legend.py b/scripts/legend.py index 5269ff9..f75f147 100644 --- a/scripts/legend.py +++ b/scripts/legend.py @@ -2,14 +2,30 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib as mpl 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, - xticks=[], yticks=[]) +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', +]) +mpl.rc('font', size=6) +mpl.rc('lines', markersize=4) + + +subplots_kw = dict( + figsize=(5.7/2.54, 5.7/2.54), + subplot_kw=dict( + aspect=1, frameon=True, + xlim=(0, 1), ylim=(0, 1), + xticks=[], yticks=[], + ), +) + +(fig, ax) = plt.subplots(**subplots_kw) def text(x, y, _text): @@ -47,7 +63,4 @@ def point(x, y): 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.savefig("../figures/legend-placement.pdf") -# plt.show() +fig.savefig("../figures/legend-placement.pdf") diff --git a/scripts/plot-variations.py b/scripts/plot-variations.py index ad4cc30..60f9463 100644 --- a/scripts/plot-variations.py +++ b/scripts/plot-variations.py @@ -2,150 +2,128 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib # Scripts to generate all the basic plots import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt -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 + +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', + pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle', +]) +mpl.rc('axes', titlepad=1) + + +subplot_kw = dict( + xlim=(0, 8), xticks=np.arange(1, 8), + ylim=(0, 8), yticks=np.arange(1, 8), +) # Basic line plot (color) # ----------------------------------------------------------------------------- -ax = fig.add_axes([d, d, 1-2*d, 1-2*d]) +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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.grid(linewidth=0.125) -plt.savefig("../figures/plot-color.pdf") -fig.clear() +ax.grid() +fig.savefig("../figures/plot-color.pdf") # Basic line plot (linestyle) # ----------------------------------------------------------------------------- -ax = fig.add_axes([d, d, 1-2*d, 1-2*d]) +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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.grid(linewidth=0.125) -plt.savefig("../figures/plot-linestyle.pdf") -fig.clear() +ax.grid() +fig.savefig("../figures/plot-linestyle.pdf") # Basic line plot (linewidth) # ----------------------------------------------------------------------------- -ax = fig.add_axes([d, d, 1-2*d, 1-2*d]) +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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.grid(linewidth=0.125) -plt.savefig("../figures/plot-linewidth.pdf") -fig.clear() +ax.grid() +fig.savefig("../figures/plot-linewidth.pdf") # Basic line plot (marker) # ----------------------------------------------------------------------------- -ax = fig.add_axes([d, d, 1-2*d, 1-2*d]) +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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.grid(linewidth=0.125) -plt.savefig("../figures/plot-marker.pdf") -fig.clear() +ax.grid() +fig.savefig("../figures/plot-marker.pdf") # Basic line plot (multi) # ----------------------------------------------------------------------------- -ax = fig.add_axes([d, d, 1-2*d, 1-2*d]) +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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.grid(linewidth=0.125) -plt.savefig("../figures/plot-multi.pdf") -fig.clear() +ax.grid() +fig.savefig("../figures/plot-multi.pdf") # 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]) +(fig, [ax2, ax1]) = plt.subplots(nrows=2, gridspec_kw=dict(hspace=0.2), subplot_kw=subplot_kw) 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.grid(linewidth=0.125) +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) 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.grid(linewidth=0.125) +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) -plt.savefig("../figures/plot-vsplit.pdf") -fig.clear() +fig.savefig("../figures/plot-vsplit.pdf") # Basic line plot (hsplit) # ----------------------------------------------------------------------------- -ax1 = fig.add_axes([d, d, .45-d, 1-2*d]) -ax2 = fig.add_axes([.55-d, d, .45-d, 1-2*d]) +(fig, [ax1, ax2]) = plt.subplots(ncols=2, gridspec_kw=dict(wspace=0.2), subplot_kw=subplot_kw) 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.grid(linewidth=0.125) +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) 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.grid(linewidth=0.125) +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) -plt.savefig("../figures/plot-hsplit.pdf") -fig.clear() +fig.savefig("../figures/plot-hsplit.pdf") # Basic line plot (title) # ----------------------------------------------------------------------------- -ax = fig.add_axes([d, d, 1-2*d, .8-2*d]) +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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.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") -plt.savefig("../figures/plot-title.pdf") -fig.clear() - +ax.grid() +ax.set_title("A Sine wave", size=4, weight="bold") +fig.savefig("../figures/plot-title.pdf") # Basic line plot (xlabel) # ----------------------------------------------------------------------------- -ax = fig.add_axes([d, .2-d, 1-2*d, .8-2*d]) +(fig, ax) = plt.subplots(subplot_kw=subplot_kw) 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.plot(X, Y, color="C1", linewidth=0.75), ax.set_xticklabels([]) ax.set_ylim(0, 6), ax.set_yticks(np.arange(1, 6)), ax.set_yticklabels([]) -ax.grid(linewidth=0.125) +ax.grid() ax.text(4, -1, "Time", transform=ax.transData, clip_on=False, size=3.5, ha="center", va="center") -# plt.show() -plt.savefig("../figures/plot-xlabel.pdf") -fig.clear() +fig.savefig("../figures/plot-xlabel.pdf") diff --git a/scripts/sine.py b/scripts/sine.py index c31c49f..6b30775 100644 --- a/scripts/sine.py +++ b/scripts/sine.py @@ -2,71 +2,68 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import pathlib + import numpy as np +import matplotlib as mpl import matplotlib.pyplot as plt + +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', + pathlib.Path(__file__).parent/'../styles/sine-plot.mplstyle', +]) + + X = np.linspace(0.1, 10*np.pi, 10000) Y = np.sin(X) -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, ax) = plt.subplots(figsize=(5.7/2.54, 1.2/2.54)) +ax.set_yticks(np.linspace(-1, 1, 5)) +ax.plot(X, Y, color="orange") +plt.savefig("../figures/sine.pdf") -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=(5.7/2.54, 1.0/2.54)) +ax.plot(X, Y, "C1o:", markevery=500, mec="1.0") +ax.set_ylim(-1.5, 1.5) +fig.savefig("../figures/sine-marker.pdf") -fig, ax = plt.subplots(figsize=(7, 1.5)) +fig, ax = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) 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.ylim(-1.5, 1.5) -plt.tight_layout() -plt.savefig("../figures/sine-logscale.pdf", dpi=100) +ax.plot(X, Y, "C1o-", markevery=500, mec="1.0") +ax.set_ylim(-1.5, 1.5) +fig.savefig("../figures/sine-logscale.pdf") -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.text(0, -1, r" Period $\Phi$") -# plt.xticks([]), plt.yticks([]) -plt.ylim(-1.5, 1.5) -plt.tight_layout() -plt.savefig("../figures/sine-period.pdf", dpi=100) -# plt.show() +(fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) +ax.plot(X, Y, "C1") +ax.fill_betweenx([-1.5, 1.5], [0], [2*np.pi], color=".9") +ax.text(0, -1, r" Period $\Phi$", va="top") +ax.set_ylim(-1.5, 1.5) +fig.savefig("../figures/sine-period.pdf") -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), - frameon=False, mode="expand", ncol=2, loc="lower left") -plt.title("Sine and Cosine") -plt.xticks([]), plt.yticks([]) -plt.ylim(-1.25, 1.25) -plt.tight_layout() -plt.savefig("../figures/sine-legend.pdf", dpi=100) -# plt.show() +(fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) +ax.plot(X, np.sin(X), "C0", label="Sine") +ax.plot(X, np.cos(X), "C1", label="Cosine") +ax.legend(bbox_to_anchor=(0.0, .9, 1.02, 0.1), + frameon=False, mode="expand", ncol=2, loc="lower left") +ax.set_title("Sine and Cosine") +ax.set_xticks([]), ax.set_yticks([]) +ax.set_ylim(-1.25, 1.25) +fig.savefig("../figures/sine-legend.pdf") -fig = plt.figure(figsize=(7, 1.5)) +(fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) 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.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.tight_layout() -plt.savefig("../figures/sine-annotate.pdf", dpi=100) -# plt.show() +ax.plot(X, Y, "C1o-", markevery=50, mec="1.0") +ax.set_ylim(-1.5, 1.5) +ax.annotate(" ", (X[200], Y[200]), (X[250], -1), ha="center", va="center", + arrowprops=dict(arrowstyle="->", color="C1", linewidth=0.5, patchA=None, shrinkA=4, shrinkB=0.5)) +ax.annotate("A", (X[250], Y[250]), (X[250], -1), ha="center", va="center", + arrowprops=dict(arrowstyle="->", color="C1", linewidth=0.5, patchA=None, shrinkA=4, shrinkB=0.5)) +ax.annotate(" ", (X[300], Y[300]), (X[250], -1), ha="center", va="center", + arrowprops=dict(arrowstyle="->", color="C1", linewidth=0.5, patchA=None, shrinkA=4, shrinkB=0.5)) +fig.savefig("../figures/sine-annotate.pdf") diff --git a/scripts/tick-formatters.py b/scripts/tick-formatters.py index c652846..07ecfe3 100644 --- a/scripts/tick-formatters.py +++ b/scripts/tick-formatters.py @@ -17,86 +17,70 @@ ]) -# Setup a plot such that only the bottom spine is shown +subplots_kw = dict( + figsize=(5.7/2.54, 3.5/2.54), + nrows=7, + subplot_kw=dict(xlim=(0, 5), ylim=(0, 1)) +) - -def setup(ax): - """Set up Axes with just an x-Axis.""" - ax.yaxis.set_major_locator(ticker.NullLocator()) - ax.set_xlim(0, 5) - ax.set_ylim(0, 1) - ax.patch.set_alpha(0.0) - - -fig = plt.figure(figsize=(5.7/2.54, 3.8/2.54)) -fig.patch.set_alpha(0.0) -n = 7 +(fig, axs) = plt.subplots(**subplots_kw) # Null formatter -ax = fig.add_subplot(n, 1, 1) -setup(ax) +ax = axs[0] ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.xaxis.set_minor_formatter(ticker.NullFormatter()) -ax.text(0.0, 0.1, "ticker.NullFormatter()", transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.NullFormatter()", + fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) # Fixed formatter -ax = fig.add_subplot(n, 1, 2) -setup(ax) +ax = axs[1] ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_locator(ticker.FixedLocator(range(6))) majors = ["zero", "one", "two", "three", "four", "five"] ax.xaxis.set_major_formatter(ticker.FixedFormatter(majors)) -ax.text(0.0, 0.1, "ticker.FixedFormatter(['zero', 'one', 'two', …])", transform=ax.transAxes) - +ax.text(0.0, 0.1, "ticker.FixedFormatter(['zero', 'one', 'two', …])", + fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) -# FuncFormatter can be used as a decorator -@ticker.FuncFormatter -def major_formatter(x, pos): - """Return formatted value with 2 decimal places.""" - return "[%.2f]" % x - - -ax = fig.add_subplot(n, 1, 3) -setup(ax) +# FuncFormatter formatter +ax = axs[2] ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) -ax.xaxis.set_major_formatter(major_formatter) -ax.text(0.0, 0.1, 'ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)', transform=ax.transAxes) - +ax.xaxis.set_major_formatter(ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)) +ax.text(0.0, 0.1, 'ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)', + fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) # FormatStr formatter -ax = fig.add_subplot(n, 1, 4) -setup(ax) +ax = axs[3] ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.FormatStrFormatter(">%d<")) -ax.text(0.0, 0.1, "ticker.FormatStrFormatter('>%d<')", transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.FormatStrFormatter('>%d<')", + fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) # Scalar formatter -ax = fig.add_subplot(n, 1, 5) -setup(ax) +ax = axs[4] ax.xaxis.set_major_locator(ticker.AutoLocator()) ax.xaxis.set_minor_locator(ticker.AutoMinorLocator()) ax.xaxis.set_major_formatter(ticker.ScalarFormatter(useMathText=True)) -ax.text(0.0, 0.1, "ticker.ScalarFormatter()", transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.ScalarFormatter()", + fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) # StrMethod formatter -ax = fig.add_subplot(n, 1, 6) -setup(ax) +ax = axs[5] ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.StrMethodFormatter("{x}")) -ax.text(0.0, 0.1, "ticker.StrMethodFormatter('{x}')", transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.StrMethodFormatter('{x}')", + fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) # Percent formatter -ax = fig.add_subplot(n, 1, 7) -setup(ax) +ax = axs[6] ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.PercentFormatter(xmax=5)) -ax.text(0.0, 0.1, "ticker.PercentFormatter(xmax=5)", transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.PercentFormatter(xmax=5)", + fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) plt.savefig("../figures/tick-formatters.pdf") -# plt.show() diff --git a/scripts/tick-locators.py b/scripts/tick-locators.py index c6521c0..1891b30 100644 --- a/scripts/tick-locators.py +++ b/scripts/tick-locators.py @@ -17,78 +17,71 @@ ]) -# Setup a plot such that only the bottom spine is shown +subplots_kw = dict( + figsize=(5.7/2.54, 4/2.54), + nrows=8, + subplot_kw=dict(xlim=(0, 5), ylim=(0, 1)), +) - -def setup(ax): - ax.yaxis.set_major_locator(ticker.NullLocator()) - ax.set_xlim(0, 5) - ax.set_ylim(0, 1) - ax.patch.set_alpha(0.0) - - -fig = plt.figure(figsize=(5.7/2.54, 3.8/2.54)) -fig.patch.set_alpha(0.0) -n = 8 +(fig, axs) = plt.subplots(**subplots_kw) # Null Locator -ax = plt.subplot(n, 1, 1) -setup(ax) +ax = axs[0] ax.xaxis.set_major_locator(ticker.NullLocator()) ax.xaxis.set_minor_locator(ticker.NullLocator()) -ax.text(0.0, 0.1, "ticker.NullLocator()", transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.NullLocator()", + fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) # Multiple Locator -ax = plt.subplot(n, 1, 2) -setup(ax) +ax = axs[1] ax.xaxis.set_major_locator(ticker.MultipleLocator(0.5)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.1)) -ax.text(0.0, 0.1, "ticker.MultipleLocator(0.5)", transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.MultipleLocator(0.5)", + fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) # Fixed Locator -ax = plt.subplot(n, 1, 3) -setup(ax) +ax = axs[2] majors = [0, 1, 5] ax.xaxis.set_major_locator(ticker.FixedLocator(majors)) minors = np.linspace(0, 1, 11)[1:-1] ax.xaxis.set_minor_locator(ticker.FixedLocator(minors)) -ax.text(0.0, 0.1, "ticker.FixedLocator([0, 1, 5])", transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.FixedLocator([0, 1, 5])", + fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) # Linear Locator -ax = plt.subplot(n, 1, 4) -setup(ax) +ax = axs[3] ax.xaxis.set_major_locator(ticker.LinearLocator(3)) ax.xaxis.set_minor_locator(ticker.LinearLocator(31)) -ax.text(0.0, 0.1, "ticker.LinearLocator(numticks=3)", transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.LinearLocator(numticks=3)", + fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) # Index Locator -ax = plt.subplot(n, 1, 5) -setup(ax) +ax = axs[4] ax.plot(range(0, 5), [0]*5, color='white') ax.xaxis.set_major_locator(ticker.IndexLocator(base=.5, offset=.25)) -ax.text(0.0, 0.1, "ticker.IndexLocator(base=0.5, offset=0.25)", transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.IndexLocator(base=0.5, offset=0.25)", + fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) # Auto Locator -ax = plt.subplot(n, 1, 6) -setup(ax) +ax = axs[5] ax.xaxis.set_major_locator(ticker.AutoLocator()) ax.xaxis.set_minor_locator(ticker.AutoMinorLocator()) -ax.text(0.0, 0.1, "ticker.AutoLocator()", transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.AutoLocator()", + fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) # MaxN Locator -ax = plt.subplot(n, 1, 7) -setup(ax) +ax = axs[6] ax.xaxis.set_major_locator(ticker.MaxNLocator(4)) ax.xaxis.set_minor_locator(ticker.MaxNLocator(40)) -ax.text(0.0, 0.1, "ticker.MaxNLocator(n=4)", transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.MaxNLocator(n=4)", + fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) # Log Locator -ax = plt.subplot(n, 1, 8) -setup(ax) +ax = axs[7] ax.set_xlim(10**3, 10**10) ax.set_xscale('log') ax.xaxis.set_major_locator(ticker.LogLocator(base=10.0, numticks=15)) -ax.text(0.0, 0.1, "ticker.LogLocator(base=10, numticks=15)", transform=ax.transAxes) +ax.text(0.0, 0.1, "ticker.LogLocator(base=10, numticks=15)", + fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) plt.savefig("../figures/tick-locators.pdf") -# plt.show() diff --git a/scripts/tick-multiple-locator.py b/scripts/tick-multiple-locator.py index 771e2fe..c8a799e 100644 --- a/scripts/tick-multiple-locator.py +++ b/scripts/tick-multiple-locator.py @@ -3,51 +3,31 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import pathlib + import numpy as np +import matplotlib as mpl import matplotlib.pyplot as plt 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') - ax.yaxis.set_major_locator(ticker.NullLocator()) - ax.spines['top'].set_color('none') - - ax.spines['bottom'].set_position("center") - - ax.xaxis.set_ticks_position('bottom') - ax.tick_params(which='major', width=1.00) - ax.tick_params(which='major', length=5) - ax.tick_params(which='minor', width=0.75) - ax.tick_params(which='minor', length=2.5) - ax.set_xlim(0, 5) - ax.set_ylim(0, 1) - ax.patch.set_alpha(0.0) - -fig = plt.figure(figsize=(5, .5)) -fig.patch.set_alpha(0.0) -n = 1 +mpl.style.use([ + pathlib.Path(__file__).parent/'../styles/base.mplstyle', + pathlib.Path(__file__).parent/'../styles/ticks.mplstyle', +]) -fontsize = 18 -family = "Source Code Pro" -# Null Locator -ax = plt.subplot(n, 1, 1) -# ax.tick_params(axis='both', which='major', -# labelsize=10, family="Roboto Condensed") -ax.tick_params(axis='both', which='minor', labelsize=6) +subplots_kw = dict( + figsize=(5.7/2.54, 0.4/2.54), + subplot_kw=dict(xlim=(0, 5), ylim=(0, 1)), +) -setup(ax) +(fig, ax) = plt.subplots(**subplots_kw) ax.xaxis.set_major_locator(ticker.MultipleLocator(1.0)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.2)) ax.xaxis.set_major_formatter(ticker.ScalarFormatter()) ax.xaxis.set_minor_formatter(ticker.ScalarFormatter()) +ax.tick_params(axis='both', which='major', labelsize=5) ax.tick_params(axis='x', which='minor', rotation=90) -plt.tight_layout() plt.savefig("../figures/tick-multiple-locator.pdf", transparent=True) -# plt.show() diff --git a/styles/base.mplstyle b/styles/base.mplstyle index 77cbdce..ea0c81e 100644 --- a/styles/base.mplstyle +++ b/styles/base.mplstyle @@ -1,5 +1,5 @@ figure.constrained_layout.use: True -figure.constrained_layout.h_pad: 0 -figure.constrained_layout.w_pad: 0 -figure.constrained_layout.hspace: 0 -figure.constrained_layout.wspace: 0 +figure.constrained_layout.h_pad: 0.01 +figure.constrained_layout.w_pad: 0.01 +figure.constrained_layout.hspace: 0.1 +figure.constrained_layout.wspace: 0.1 diff --git a/styles/plotlet-grid.mplstyle b/styles/plotlet-grid.mplstyle index c4133c3..e637a9c 100644 --- a/styles/plotlet-grid.mplstyle +++ b/styles/plotlet-grid.mplstyle @@ -1,10 +1,7 @@ -figure.constrained_layout.h_pad: 0.04 -figure.constrained_layout.w_pad: 0.04 -figure.constrained_layout.hspace: 0.04 -figure.constrained_layout.wspace: 0.04 - font.family: Source Code Pro font.size: 5 +axes.linewidth: 0.5 + xtick.major.size: 0.0 ytick.major.size: 0.0 diff --git a/styles/plotlet.mplstyle b/styles/plotlet.mplstyle index b86d240..ff46026 100644 --- a/styles/plotlet.mplstyle +++ b/styles/plotlet.mplstyle @@ -13,3 +13,9 @@ lines.linewidth: 0.75 xtick.major.size: 0.0 ytick.major.size: 0.0 + +xtick.labeltop: False +xtick.labelbottom: False + +ytick.labelleft: False +ytick.labelright: False diff --git a/styles/sine-plot.mplstyle b/styles/sine-plot.mplstyle new file mode 100644 index 0000000..9829f21 --- /dev/null +++ b/styles/sine-plot.mplstyle @@ -0,0 +1,24 @@ +font.size: 4 + +axes.titlesize: 4 +axes.titlepad: 2 +axes.linewidth: 0.2 + +lines.linewidth: 0.5 +lines.markersize: 3 + +xtick.labelsize: 3 +xtick.major.pad: 1 +xtick.major.width: 0.2 +xtick.major.size: 1 +xtick.minor.width: 0.1 +xtick.minor.size: 0.5 + +ytick.labelsize: 3 +ytick.major.pad: 1 +ytick.major.width: 0.2 +ytick.major.size: 1 +ytick.minor.width: 0.1 +ytick.minor.size: 0.5 + +legend.fontsize: 3 diff --git a/styles/ticks.mplstyle b/styles/ticks.mplstyle index a2fb14f..ba56aa8 100644 --- a/styles/ticks.mplstyle +++ b/styles/ticks.mplstyle @@ -1,6 +1,5 @@ savefig.transparent: True -font.family: Source Code Pro font.size: 5 axes.linewidth: 0.5 @@ -10,8 +9,12 @@ axes.spines.left: False axes.spines.bottom: True xtick.labelsize: 3 -xtick.major.pad: 1 -xtick.major.width: 0.2 xtick.major.size: 2 -xtick.minor.width: 0.1 +xtick.major.width: 0.2 +xtick.major.pad: 2 xtick.minor.size: 1 +xtick.minor.width: 0.2 +xtick.minor.pad: 2 + +ytick.left: False +ytick.labelleft: False From e4c6b67c9520d67442d616a220b5092741586e56 Mon Sep 17 00:00:00 2001 From: Jamal Mustafa Date: Mon, 3 Jan 2022 13:04:26 -0800 Subject: [PATCH 18/65] small tweaks to size and spacing identified during review --- scripts/annotation-connection-styles.py | 6 +++--- scripts/tick-formatters.py | 16 ++++++++-------- scripts/tick-locators.py | 18 +++++++++--------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/annotation-connection-styles.py b/scripts/annotation-connection-styles.py index 4382cbb..81908d7 100644 --- a/scripts/annotation-connection-styles.py +++ b/scripts/annotation-connection-styles.py @@ -8,6 +8,7 @@ pathlib.Path(__file__).parent/'../styles/base.mplstyle', pathlib.Path(__file__).parent/'../styles/plotlet-grid.mplstyle', ]) +mpl.rc('lines', markersize=3) def demo_con_style(ax, connectionstyle): @@ -17,8 +18,8 @@ def demo_con_style(ax, connectionstyle): ax.annotate("", xy=(x1, y1), xycoords='data', xytext=(x2, y2), textcoords='data', - arrowprops=dict(arrowstyle="->", color="0.5", - shrinkA=2, shrinkB=2, + arrowprops=dict(arrowstyle="->", lw=0.5, color="0.5", + shrinkA=3, shrinkB=3, patchA=None, patchB=None, connectionstyle=connectionstyle), ) @@ -41,4 +42,3 @@ def demo_con_style(ax, connectionstyle): ax.set(xlim=(0, 1), ylim=(0, 1), xticks=[], yticks=[], aspect=1) plt.savefig("../figures/annotation-connection-styles.pdf") -# plt.show() diff --git a/scripts/tick-formatters.py b/scripts/tick-formatters.py index 07ecfe3..5439630 100644 --- a/scripts/tick-formatters.py +++ b/scripts/tick-formatters.py @@ -31,7 +31,7 @@ ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.xaxis.set_minor_formatter(ticker.NullFormatter()) -ax.text(0.0, 0.1, "ticker.NullFormatter()", +ax.text(0.0, 0.2, "ticker.NullFormatter()", fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) # Fixed formatter @@ -40,7 +40,7 @@ ax.xaxis.set_major_locator(ticker.FixedLocator(range(6))) majors = ["zero", "one", "two", "three", "four", "five"] ax.xaxis.set_major_formatter(ticker.FixedFormatter(majors)) -ax.text(0.0, 0.1, "ticker.FixedFormatter(['zero', 'one', 'two', …])", +ax.text(0.0, 0.2, "ticker.FixedFormatter(['zero', 'one', 'two', …])", fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) # FuncFormatter formatter @@ -48,7 +48,7 @@ ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)) -ax.text(0.0, 0.1, 'ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)', +ax.text(0.0, 0.2, 'ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)', fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) # FormatStr formatter @@ -56,7 +56,7 @@ ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.FormatStrFormatter(">%d<")) -ax.text(0.0, 0.1, "ticker.FormatStrFormatter('>%d<')", +ax.text(0.0, 0.2, "ticker.FormatStrFormatter('>%d<')", fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) # Scalar formatter @@ -64,7 +64,7 @@ ax.xaxis.set_major_locator(ticker.AutoLocator()) ax.xaxis.set_minor_locator(ticker.AutoMinorLocator()) ax.xaxis.set_major_formatter(ticker.ScalarFormatter(useMathText=True)) -ax.text(0.0, 0.1, "ticker.ScalarFormatter()", +ax.text(0.0, 0.2, "ticker.ScalarFormatter()", fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) # StrMethod formatter @@ -72,7 +72,7 @@ ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.StrMethodFormatter("{x}")) -ax.text(0.0, 0.1, "ticker.StrMethodFormatter('{x}')", +ax.text(0.0, 0.2, "ticker.StrMethodFormatter('{x}')", fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) # Percent formatter @@ -80,7 +80,7 @@ ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.PercentFormatter(xmax=5)) -ax.text(0.0, 0.1, "ticker.PercentFormatter(xmax=5)", +ax.text(0.0, 0.2, "ticker.PercentFormatter(xmax=5)", fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) -plt.savefig("../figures/tick-formatters.pdf") +fig.savefig("../figures/tick-formatters.pdf") diff --git a/scripts/tick-locators.py b/scripts/tick-locators.py index 1891b30..9964f8a 100644 --- a/scripts/tick-locators.py +++ b/scripts/tick-locators.py @@ -29,14 +29,14 @@ ax = axs[0] ax.xaxis.set_major_locator(ticker.NullLocator()) ax.xaxis.set_minor_locator(ticker.NullLocator()) -ax.text(0.0, 0.1, "ticker.NullLocator()", +ax.text(0.0, 0.2, "ticker.NullLocator()", fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) # Multiple Locator ax = axs[1] ax.xaxis.set_major_locator(ticker.MultipleLocator(0.5)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.1)) -ax.text(0.0, 0.1, "ticker.MultipleLocator(0.5)", +ax.text(0.0, 0.2, "ticker.MultipleLocator(0.5)", fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) # Fixed Locator @@ -45,35 +45,35 @@ ax.xaxis.set_major_locator(ticker.FixedLocator(majors)) minors = np.linspace(0, 1, 11)[1:-1] ax.xaxis.set_minor_locator(ticker.FixedLocator(minors)) -ax.text(0.0, 0.1, "ticker.FixedLocator([0, 1, 5])", +ax.text(0.0, 0.2, "ticker.FixedLocator([0, 1, 5])", fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) # Linear Locator ax = axs[3] ax.xaxis.set_major_locator(ticker.LinearLocator(3)) ax.xaxis.set_minor_locator(ticker.LinearLocator(31)) -ax.text(0.0, 0.1, "ticker.LinearLocator(numticks=3)", +ax.text(0.0, 0.2, "ticker.LinearLocator(numticks=3)", fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) # Index Locator ax = axs[4] ax.plot(range(0, 5), [0]*5, color='white') ax.xaxis.set_major_locator(ticker.IndexLocator(base=.5, offset=.25)) -ax.text(0.0, 0.1, "ticker.IndexLocator(base=0.5, offset=0.25)", +ax.text(0.0, 0.2, "ticker.IndexLocator(base=0.5, offset=0.25)", fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) # Auto Locator ax = axs[5] ax.xaxis.set_major_locator(ticker.AutoLocator()) ax.xaxis.set_minor_locator(ticker.AutoMinorLocator()) -ax.text(0.0, 0.1, "ticker.AutoLocator()", +ax.text(0.0, 0.2, "ticker.AutoLocator()", fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) # MaxN Locator ax = axs[6] ax.xaxis.set_major_locator(ticker.MaxNLocator(4)) ax.xaxis.set_minor_locator(ticker.MaxNLocator(40)) -ax.text(0.0, 0.1, "ticker.MaxNLocator(n=4)", +ax.text(0.0, 0.2, "ticker.MaxNLocator(n=4)", fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) # Log Locator @@ -81,7 +81,7 @@ ax.set_xlim(10**3, 10**10) ax.set_xscale('log') ax.xaxis.set_major_locator(ticker.LogLocator(base=10.0, numticks=15)) -ax.text(0.0, 0.1, "ticker.LogLocator(base=10, numticks=15)", +ax.text(0.0, 0.2, "ticker.LogLocator(base=10, numticks=15)", fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) -plt.savefig("../figures/tick-locators.pdf") +fig.savefig("../figures/tick-locators.pdf") From 37cc5416e4023a75b097b4195f7eaa63ec52f987 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 23 Feb 2022 15:51:54 -0500 Subject: [PATCH 19/65] BLD: update pins The main goal here is to update pillow, pulled everything else with it --- requirements/requirements.in | 1 + requirements/requirements.txt | 118 ++++++++++++++++------------------ 2 files changed, 56 insertions(+), 63 deletions(-) diff --git a/requirements/requirements.in b/requirements/requirements.in index 179699f..b3c566a 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -4,6 +4,7 @@ cartopy==0.19.0.post1 flake8 matplotlib==3.5.0 mpl-sphinx-theme +pillow>=9 pdfx pip-tools pre-commit diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 8ae5a1c..0a9c84e 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile +# This file is autogenerated by pip-compile with python 3.10 # To update, run: # # pip-compile requirements.in @@ -8,13 +8,11 @@ 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 +beautifulsoup4==4.10.0 # via pydata-sphinx-theme bump2version==1.0.1 # via -r requirements.in @@ -24,124 +22,121 @@ certifi==2021.10.8 # via requests cffi==1.15.0 # via cryptography -cfgv==3.2.0 +cfgv==3.3.1 # via pre-commit chardet==4.0.0 # via - # pdfminer.six + # pdfminer-six # pdfx -charset-normalizer==2.0.7 +charset-normalizer==2.0.12 # via requests -click==8.0.0 +click==8.0.4 # via pip-tools -cryptography==35.0.0 - # via pdfminer.six -cycler==0.10.0 +cryptography==36.0.1 + # via pdfminer-six +cycler==0.11.0 # via matplotlib -distlib==0.3.1 +distlib==0.3.4 # via virtualenv docutils==0.17.1 # via # pydata-sphinx-theme # sphinx -filelock==3.0.12 +filelock==3.6.0 # via virtualenv flake8==4.0.1 # via -r requirements.in -fonttools==4.28.3 +fonttools==4.29.1 # via matplotlib -identify==2.2.2 +identify==2.4.11 # via pre-commit idna==3.3 # via requests -imagesize==1.2.0 +imagesize==1.3.0 # via sphinx -importlib-metadata==4.2.0 - # via - # flake8 - # pep517 - # pre-commit - # virtualenv -jinja2==3.0.2 +jinja2==3.0.3 # via sphinx -kiwisolver==1.3.1 +kiwisolver==1.3.2 # via matplotlib -markupsafe==2.0.1 +markupsafe==2.1.0 # via jinja2 matplotlib==3.5.0 # via -r requirements.in mccabe==0.6.1 # via flake8 -mpl-sphinx-theme==0.0.6 +mpl-sphinx-theme==3.5.0 # via -r requirements.in -nodeenv==1.5.0 +nodeenv==1.6.0 # via pre-commit -numpy==1.19.5 +numpy==1.22.2 # via # cartopy # matplotlib # scipy -packaging==21.2 +packaging==21.3 # via # matplotlib # setuptools-scm # sphinx -pdfminer.six==20201018 +pdfminer-six==20201018 # via pdfx pdfx==1.4.1 # via -r requirements.in -pep517==0.10.0 +pep517==0.12.0 # via pip-tools -pillow==8.1.2 - # via matplotlib -pip-tools==6.1.0 +pillow==9.0.1 + # via + # -r requirements.in + # matplotlib +pip-tools==6.5.1 # via -r requirements.in -pre-commit==2.11.1 +platformdirs==2.5.1 + # via virtualenv +pre-commit==2.17.0 # via -r requirements.in pycodestyle==2.8.0 # via # autopep8 # flake8 -pycparser==2.20 +pycparser==2.21 # via cffi -pydata-sphinx-theme==0.7.1 +pydata-sphinx-theme==0.8.0 # via mpl-sphinx-theme pyflakes==2.4.0 # via flake8 -pygments==2.10.0 +pygments==2.11.2 # via sphinx -pyparsing==2.4.7 +pyparsing==3.0.7 # via # matplotlib # packaging -pyshp==2.1.3 +pyshp==2.2.0 # via cartopy -python-dateutil==2.8.1 +python-dateutil==2.8.2 # via matplotlib pytz==2021.3 # via babel -pyyaml==5.4.1 +pyyaml==6.0 # via pre-commit -requests==2.26.0 +requests==2.27.1 # via sphinx -scipy==1.5.4 +scipy==1.8.0 # via -r requirements.in -setuptools-scm==6.3.2 +setuptools-scm==6.4.2 # via matplotlib -shapely==1.7.1 +shapely==1.8.1.post1 # via cartopy -six==1.15.0 +six==1.16.0 # via - # cycler # python-dateutil # virtualenv -snowballstemmer==2.1.0 +snowballstemmer==2.2.0 # via sphinx sortedcontainers==2.4.0 - # via pdfminer.six -soupsieve==2.3 + # via pdfminer-six +soupsieve==2.3.1 # via beautifulsoup4 -sphinx==4.2.0 +sphinx==4.4.0 # via # -r requirements.in # pydata-sphinx-theme @@ -160,20 +155,17 @@ sphinxcontrib-serializinghtml==1.1.5 toml==0.10.2 # via # autopep8 - # pep517 # pre-commit -tomli==1.2.2 - # via setuptools-scm -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 +tomli==2.0.1 # via - # importlib-metadata # pep517 + # setuptools-scm +urllib3==1.26.8 + # via requests +virtualenv==20.13.1 + # via pre-commit +wheel==0.37.1 + # via pip-tools # The following packages are considered to be unsafe in a requirements file: # pip From 07f9bf40fde9b65a8600d8f512af4329778ec437 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 23 Feb 2022 16:13:34 -0500 Subject: [PATCH 20/65] GHA: update workflow to use python3.10 --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 447fbc6..f11e883 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.10 - name: Install dependencies run: | sudo apt update From 1609898e0d9630206aabad6ddb2218381d15e0c3 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Wed, 23 Feb 2022 16:14:56 -0500 Subject: [PATCH 21/65] CI: do not trust yaml, use strings --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index f11e883..efeebc7 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: 3.10 + python-version: "3.10" - name: Install dependencies run: | sudo apt update From 9c26d793fe9f01b4c53030d384d37ce4227f3e2d Mon Sep 17 00:00:00 2001 From: Steffen Rehberg Date: Mon, 12 Sep 2022 15:59:59 +0200 Subject: [PATCH 22/65] Make png background opaque white Make the background of the png preview images of the pdf files opaque white instead of transparent. --- Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 530fc09..6ef4869 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ SRC := $(wildcard *.tex) +CONVERTFLAGS = -density 150 -alpha remove -depth 8 .PHONY: default default: all @@ -22,16 +23,16 @@ figures: .PHONY: cheatsheets cheatsheets: xelatex cheatsheets.tex - convert -density 150 cheatsheets.pdf -scene 1 cheatsheets.png + convert $(CONVERTFLAGS) cheatsheets.pdf -scene 1 cheatsheets.png .PHONY: handouts handouts: xelatex handout-beginner.tex xelatex handout-intermediate.tex xelatex handout-tips.tex - convert -density 150 handout-tips.pdf handout-tips.png - convert -density 150 handout-beginner.pdf handout-beginner.png - convert -density 150 handout-intermediate.pdf handout-intermediate.png + convert $(CONVERTFLAGS) handout-tips.pdf handout-tips.png + convert $(CONVERTFLAGS) handout-beginner.pdf handout-beginner.png + convert $(CONVERTFLAGS) handout-intermediate.pdf handout-intermediate.png .PHONY: check check: From c4616090bab7a68fe0a031cf8a4e4dbbd4c4ab85 Mon Sep 17 00:00:00 2001 From: Steffen Rehberg Date: Mon, 12 Sep 2022 17:02:27 +0200 Subject: [PATCH 23/65] Improve tick label rotation method Using ax.set_xticks(rotation=90) without passing labels is discouraged by the documentation. It recommends ax.tick_params(axis='x', rotation=90) instead. --- cheatsheets.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index d1b46f4..d74754a 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -977,7 +977,7 @@ \textbf{… remove tick labels ?}\\ \hspace*{2.5mm}~$\rightarrow$ ax.set\_[xy]ticklabels([])\\ \textbf{… rotate tick labels ?}\\ - \hspace*{2.5mm}~$\rightarrow$ ax.set\_[xy]ticks(rotation=90)\\ + \hspace*{2.5mm}~$\rightarrow$ ax.tick\_params(axis="x", rotation=90)\\ \textbf{… hide top spine?}\\ \hspace*{2.5mm}~$\rightarrow$ ax.spines['top'].set\_visible(False)\\ \textbf{… hide legend border?}\\ From c1f972504e99dc99ceb9de233cc5a91c22355329 Mon Sep 17 00:00:00 2001 From: sanderwang <25528016+radarFudan@users.noreply.github.com> Date: Mon, 10 Oct 2022 23:26:31 +0800 Subject: [PATCH 24/65] Update the beginner tex file for the issue #117 --- handout-beginner.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/handout-beginner.tex b/handout-beginner.tex index 1b3087a..690a844 100644 --- a/handout-beginner.tex +++ b/handout-beginner.tex @@ -240,7 +240,7 @@ \subsection*{\rmfamily Organize} % ----------------------------------------------------------------------------- \begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}} \begin{lstlisting}[belowskip=-\baselineskip] - fig, (ax1, ax2) = plt.subplots((2,1)) + fig, (ax1, ax2) = plt.subplots(2,1) ax1.plot(X, Y1, color="C1") ax2.plot(X, Y2, color="C0") \end{lstlisting} @@ -249,7 +249,7 @@ \subsection*{\rmfamily Organize} % ----------------------------------------------------------------------------- \begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}} \begin{lstlisting}[belowskip=-\baselineskip] - fig, (ax1, ax2) = plt.subplots((1,2)) + fig, (ax1, ax2) = plt.subplots(1,2) ax1.plot(Y1, X, color="C1") ax2.plot(Y2, X, color="C0") \end{lstlisting} From 49950f457b12a0f4cb29f4e52a1bad9c67f9db85 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 31 Dec 2022 14:49:54 +0100 Subject: [PATCH 25/65] Change casing of sentences --- cheatsheets.tex | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index d74754a..eb1d3e0 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -760,16 +760,16 @@ % \begin{myboxed}{Ten simple rules \hfill \READ{https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1003833}} - 1. Know Your Audience\\ - 2. Identify Your Message\\ - 3. Adapt the Figure\\ - 4. Captions Are Not Optional\\ - 5. Do Not Trust the Defaults\\ - 6. Use Color Effectively\\ - 7. Do Not Mislead the Reader\\ - 8. Avoid “Chartjunk”\\ - 9. Message Trumps Beauty\\ - 10. Get the Right Tool + 1. Know your audience\\ + 2. Identify your message\\ + 3. Adapt the figure\\ + 4. Captions are not optional\\ + 5. Do not trust the defaults\\ + 6. Use color effectively\\ + 7. Do not mislead the reader\\ + 8. Avoid “chartjunk”\\ + 9. Message trumps beauty\\ + 10. Get the right tool \end{myboxed} \end{multicols*} @@ -1028,12 +1028,12 @@ % \begin{myboxed}{Beyond Matplotlib} \smallskip - \href{https://seaborn.pydata.org/}{\textbf{Seaborn}}: Statistical Data Visualization\\ - \href{https://scitools.org.uk/cartopy/docs/latest/}{\textbf{Cartopy}}: Geospatial Data Processing\\ - \href{https://yt-project.org/doc/index.html}{\textbf{yt}}: Volumetric data Visualization\\ + \href{https://seaborn.pydata.org/}{\textbf{Seaborn}}: Statistical data visualization\\ + \href{https://scitools.org.uk/cartopy/docs/latest/}{\textbf{Cartopy}}: Geospatial data processing\\ + \href{https://yt-project.org/doc/index.html}{\textbf{yt}}: Volumetric data visualization\\ \href{https://mpld3.github.io}{\textbf{mpld3}}: Bringing Matplotlib to the browser\\ \href{https://datashader.org/}{\textbf{Datashader}}: Large data processing pipeline\\ - \href{https://plotnine.readthedocs.io/en/latest/}{\textbf{plotnine}}: A Grammar of Graphics for Python + \href{https://plotnine.readthedocs.io/en/latest/}{\textbf{plotnine}}: A grammar of graphics for Python \end{myboxed} % \begin{center} From d3722d9ac1c52a46d4073da96d134607c7626865 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 31 Dec 2022 14:56:57 +0100 Subject: [PATCH 26/65] Update docker and action versions --- .circleci/config.yml | 2 +- .github/workflows/main.yaml | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 06f76c7..a8d9e77 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,7 @@ orbs: jobs: build_docs: docker: - - image: circleci/python:3.9 + - image: cimg/python:3.9 steps: - checkout - run: diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index efeebc7..821c6ef 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -6,14 +6,14 @@ jobs: pre-commit: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 - uses: pre-commit/action@v2.0.0 build: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 with: python-version: "3.10" - name: Install dependencies @@ -54,7 +54,7 @@ jobs: - name: Run checks run: | make check - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 if: ${{ always() }} with: name: build From 9396613792c40b82c668a2edd4a8f08d10aa02e3 Mon Sep 17 00:00:00 2001 From: Steffen Rehberg Date: Tue, 7 Mar 2023 17:43:17 +0100 Subject: [PATCH 27/65] Fix non-existent cartopy projection - the correct name of the projection is Orthographic instead of Cartographic. - use standard import convention to make the line a bit shorter, see https://scitools.org.uk/cartopy/docs/latest/matplotlib/intro.html. - fix wrong API link for cartopy - add missing (lost) API link for 3d --- cheatsheets.tex | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index eb1d3e0..a8a2bc8 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -519,17 +519,11 @@ {\ttfamily \textbf{subplot}(…,projection=p)} \smallskip \scale{projection-polar.pdf}{p='polar'}{} - \scale{projection-3d.pdf}{p='3d'}{} -% {https://matplotlib.org/stable/api/projections_api.html} -% {} -% {} - %% \plot{projection-3d.pdf}{p='3d'} - %% {https://matplotlib.org/stable/api/toolkits/mplot3d.html} - %% {} - %% {} - \plot{projection-cartopy.pdf}{p=Orthographic()} - {https://matplotlib.org/stable/api/toolkits/mplot3d.html} - {from cartopy.crs import Cartographic} + \scale{projection-3d.pdf} + {p='3d'\hfill\api{https://matplotlib.org/stable/api/toolkits/mplot3d.html}}{} + \plot{projection-cartopy.pdf}{p=ccrs.Orthographic()} + {https://scitools.org.uk/cartopy/docs/latest/reference/projections.html} + {import cartopy.crs as ccrs} {} \end{myboxed} % From 7d41bab953439348ccd58102f2d88b116c56a7c2 Mon Sep 17 00:00:00 2001 From: Steffen Rehberg Date: Thu, 9 Mar 2023 13:48:05 +0100 Subject: [PATCH 28/65] Fix gitter url The https scheme is needed as check-links.py checks for 200. Pdfx prepends http:// to links without a scheme which results in a permanent redired (308) to 'https://gitter.im/matplotlib/matplotlib' and hence causes check-links.py to fail. --- cheatsheets.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index a8a2bc8..cae6f19 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -328,7 +328,7 @@ \href{https://stackoverflow.com/questions/tagged/matplotlib} {\faIcon{stack-overflow}\,stackoverflow.com/questions/tagged/matplotlib}\\ \href{https://gitter.im/matplotlib/matplotlib} - {\faIcon{gitter}\,gitter.im/matplotlib}\\ + {\faIcon{gitter}\,{https://gitter.im/matplotlib/matplotlib}}\\ \href{https://twitter.com/matplotlib} {\faIcon{twitter}\,twitter.com/matplotlib}\\ \href{https://mail.python.org/mailman/listinfo/matplotlib-users} From 4b6dbaecd6c3d29860293ce5d75c8e0ab8116da6 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 28 Mar 2023 18:03:39 -0400 Subject: [PATCH 29/65] Add a randomness seed to transparency script --- scripts/tip-transparency.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/tip-transparency.py b/scripts/tip-transparency.py index 0172073..2d9abc6 100644 --- a/scripts/tip-transparency.py +++ b/scripts/tip-transparency.py @@ -7,6 +7,8 @@ import matplotlib.pyplot as plt mpl.rc('axes', linewidth=1.5) +np.random.seed(123) + fig = plt.figure(figsize=(2, 2), dpi=100) margin = 0.01 ax = fig.add_axes([margin, margin, 1-2*margin, 1-2*margin]) From a5a46ca6feb311db64f0eca54dd0f59fc352318f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 28 Mar 2023 19:23:27 -0400 Subject: [PATCH 30/65] Simplify some iterations in scripts --- scripts/fonts.py | 16 +++++++--------- scripts/tip-hatched.py | 8 ++++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/scripts/fonts.py b/scripts/fonts.py index d164ae7..9766453 100644 --- a/scripts/fonts.py +++ b/scripts/fonts.py @@ -20,9 +20,8 @@ } text = "The quick brown fox jumps over the lazy dog" -for i, variant in enumerate(variants.keys()): - ax.text(1, y, text, size=9, va="center", - font=pathlib.Path(variants[variant]).resolve()) +for i, (variant, file) in enumerate(variants.items()): + ax.text(1, y, text, size=9, va="center", font=pathlib.Path(file).resolve()) ax.text(39, y, variant, color="0.25", va="center", ha="right", @@ -53,12 +52,11 @@ "Source Code Pro" : "monospace" } text = "The quick brown fox jumps over the lazy dog" -for i, family in enumerate(families): +for i, (family, label) in enumerate(families.items()): ax.text(1, y, text, va="center", size=9, family=family, weight="regular") - ax.text(39, y, - "%s" % (families[family]), + ax.text(39, y, label, color="0.25", va="center", ha="right", size="small", family="Source Code Pro", weight=400) y += 1.65 @@ -81,7 +79,7 @@ ax.text(1, y, text, size=9, va="center", family="Source Sans Pro", weight=weight) - ax.text(39, y, "%s (%d)" % (weight, weights[weight]), + ax.text(39, y, f"{weight} ({weights[weight]:d})", color="0.25", va="center", ha="right", size="small", family="Source Code Pro", weight=400) y += 1.65 @@ -97,11 +95,11 @@ "xx-large" : 1.728 } text = "The quick brown fox" -for i, size in enumerate(sizes.keys()): +for i, (size, scaling) in enumerate(sizes.items()): ax.text(1, y, text, size=size, ha="left", va="center", family="Source Sans Pro", weight="light") - ax.text(39, y, "%s (%.2f)" % (size, sizes[size]), + ax.text(39, y, f"{size} ({scaling:.2f})", color="0.25", va="center", ha="right", size="small", family="Source Code Pro", weight=400) y += 1.65* max(sizes[size], sizes["small"]) diff --git a/scripts/tip-hatched.py b/scripts/tip-hatched.py index c8a4ec3..56ac515 100644 --- a/scripts/tip-hatched.py +++ b/scripts/tip-hatched.py @@ -15,14 +15,14 @@ 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), +for x, y in zip(x1, y1): + plt.annotate(f"{y:d}%", (x, y), 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), +for x, y in zip(x2, y2): + plt.annotate(f"{y:d}%", (x, y), xytext=(0, 1), fontsize="x-small", color=color2, textcoords="offset points", va="bottom", ha="center") From c44d32b93ff91de6f6335f4ae91acab7cd1ebc9f Mon Sep 17 00:00:00 2001 From: Jamal Mustafa Date: Thu, 30 Mar 2023 01:14:05 -0700 Subject: [PATCH 31/65] revert some changes --- Makefile | 3 + scripts/annotation-arrow-styles.py | 19 +++--- scripts/tick-formatters.py | 101 ++++++++++++++++++----------- scripts/tick-locators.py | 96 ++++++++++++++++----------- 4 files changed, 133 insertions(+), 86 deletions(-) diff --git a/Makefile b/Makefile index f193644..4a7642a 100644 --- a/Makefile +++ b/Makefile @@ -17,11 +17,14 @@ figures: # crop some of the figures cd figures && pdfcrop adjustments.pdf adjustments.pdf cd figures && pdfcrop annotate.pdf annotate.pdf + cd figures && pdfcrop annotation-arrow-styles.pdf annotation-arrow-styles.pdf cd figures && pdfcrop anatomy.pdf anatomy.pdf cd figures && pdfcrop colornames.pdf colornames.pdf cd figures && pdfcrop fonts.pdf fonts.pdf cd figures && pdfcrop markers.pdf markers.pdf cd figures && pdfcrop text-alignments.pdf text-alignments.pdf + cd figures && pdfcrop tick-formatters.pdf tick-formatters.pdf + cd figures && pdfcrop tick-locators.pdf tick-locators.pdf cd figures && pdfcrop tip-font-family.pdf tip-font-family.pdf cd figures && pdfcrop tip-hatched.pdf tip-hatched.pdf diff --git a/scripts/annotation-arrow-styles.py b/scripts/annotation-arrow-styles.py index 046c3e1..648a4c4 100644 --- a/scripts/annotation-arrow-styles.py +++ b/scripts/annotation-arrow-styles.py @@ -1,17 +1,16 @@ -import pathlib - -import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.patches as mpatches +styles = mpatches.ArrowStyle.get_styles() + -mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/plotlet-grid.mplstyle', -]) +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(4, 4, figsize=(5.7/2.54, 1.5), frameon=True) +(fig, axes) = plt.subplots(4, 4, 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())): @@ -22,13 +21,13 @@ xy=(x0, y0), xycoords='data', xytext=(x1, y1), textcoords='data', arrowprops=dict(arrowstyle=style, - mutation_scale=10, color="black", shrinkA=5, shrinkB=5, patchA=None, patchB=None, connectionstyle="arc3,rad=0")) ax.text( (x1+x0)/2, y0-0.2, style, transform=ax.transAxes, - ha="center", va="top", fontsize=8) + family="Source Code Pro", ha="center", va="top") plt.savefig("../figures/annotation-arrow-styles.pdf") +# plt.show() diff --git a/scripts/tick-formatters.py b/scripts/tick-formatters.py index 5439630..fe5bb40 100644 --- a/scripts/tick-formatters.py +++ b/scripts/tick-formatters.py @@ -3,84 +3,109 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- -import pathlib - -import numpy as np -import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.ticker as ticker +# Setup a plot such that only the bottom spine is shown + -mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/ticks.mplstyle', -]) +def setup(ax): + """Set up Axes with just an x-Axis.""" + ax.spines['right'].set_color('none') + ax.spines['left'].set_color('none') + ax.yaxis.set_major_locator(ticker.NullLocator()) + ax.spines['top'].set_color('none') + ax.xaxis.set_ticks_position('bottom') + ax.tick_params(which='major', width=1.00, length=5) + ax.tick_params(which='minor', width=0.75, length=2.5, labelsize=10) + ax.set_xlim(0, 5) + ax.set_ylim(0, 1) + ax.patch.set_alpha(0.0) -subplots_kw = dict( - figsize=(5.7/2.54, 3.5/2.54), - nrows=7, - subplot_kw=dict(xlim=(0, 5), ylim=(0, 1)) -) +fig = plt.figure(figsize=(8, 5)) +fig.patch.set_alpha(0.0) +n = 7 -(fig, axs) = plt.subplots(**subplots_kw) +fontsize = 18 +family = "Source Code Pro" # Null formatter -ax = axs[0] +ax = fig.add_subplot(n, 1, 1) +setup(ax) ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.NullFormatter()) ax.xaxis.set_minor_formatter(ticker.NullFormatter()) -ax.text(0.0, 0.2, "ticker.NullFormatter()", - fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) +ax.text(0.0, 0.1, "ticker.NullFormatter()", family=family, + fontsize=fontsize, transform=ax.transAxes) # Fixed formatter -ax = axs[1] +ax = fig.add_subplot(n, 1, 2) +setup(ax) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_locator(ticker.FixedLocator(range(6))) majors = ["zero", "one", "two", "three", "four", "five"] ax.xaxis.set_major_formatter(ticker.FixedFormatter(majors)) -ax.text(0.0, 0.2, "ticker.FixedFormatter(['zero', 'one', 'two', …])", - fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) +ax.text(0.0, 0.1, "ticker.FixedFormatter(['zero', 'one', 'two', …])", + family=family, fontsize=fontsize, transform=ax.transAxes) + + +# FuncFormatter can be used as a decorator +@ticker.FuncFormatter +def major_formatter(x, pos): + """Return formatted value with 2 decimal places.""" + return "[%.2f]" % x -# FuncFormatter formatter -ax = axs[2] + +ax = fig.add_subplot(n, 1, 3) +setup(ax) ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) -ax.xaxis.set_major_formatter(ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)) -ax.text(0.0, 0.2, 'ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)', - fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) +ax.xaxis.set_major_formatter(major_formatter) +ax.text(0.0, 0.1, 'ticker.FuncFormatter(lambda x, pos: "[%.2f]" % x)', + family=family, fontsize=fontsize, transform=ax.transAxes) + # FormatStr formatter -ax = axs[3] +ax = fig.add_subplot(n, 1, 4) +setup(ax) ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.FormatStrFormatter(">%d<")) -ax.text(0.0, 0.2, "ticker.FormatStrFormatter('>%d<')", - fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) +ax.text(0.0, 0.1, "ticker.FormatStrFormatter('>%d<')", + family=family, fontsize=fontsize, transform=ax.transAxes) # Scalar formatter -ax = axs[4] +ax = fig.add_subplot(n, 1, 5) +setup(ax) ax.xaxis.set_major_locator(ticker.AutoLocator()) ax.xaxis.set_minor_locator(ticker.AutoMinorLocator()) ax.xaxis.set_major_formatter(ticker.ScalarFormatter(useMathText=True)) -ax.text(0.0, 0.2, "ticker.ScalarFormatter()", - fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) +ax.text(0.0, 0.1, "ticker.ScalarFormatter()", + family=family, fontsize=fontsize, transform=ax.transAxes) # StrMethod formatter -ax = axs[5] +ax = fig.add_subplot(n, 1, 6) +setup(ax) ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.StrMethodFormatter("{x}")) -ax.text(0.0, 0.2, "ticker.StrMethodFormatter('{x}')", - fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) +ax.text(0.0, 0.1, "ticker.StrMethodFormatter('{x}')", + family=family, fontsize=fontsize, transform=ax.transAxes) # Percent formatter -ax = axs[6] +ax = fig.add_subplot(n, 1, 7) +setup(ax) ax.xaxis.set_major_locator(ticker.MultipleLocator(1.00)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.25)) ax.xaxis.set_major_formatter(ticker.PercentFormatter(xmax=5)) -ax.text(0.0, 0.2, "ticker.PercentFormatter(xmax=5)", - fontfamily="Source Code Pro", transform=ax.transAxes, in_layout=False) +ax.text(0.0, 0.1, "ticker.PercentFormatter(xmax=5)", + family=family, fontsize=fontsize, transform=ax.transAxes) + +# Push the top of the top axes outside the figure because we only show the +# bottom spine. +fig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=1.05) -fig.savefig("../figures/tick-formatters.pdf") +plt.savefig("../figures/tick-formatters.pdf", transparent=True) +# plt.show() diff --git a/scripts/tick-locators.py b/scripts/tick-locators.py index 9964f8a..276f8a3 100644 --- a/scripts/tick-locators.py +++ b/scripts/tick-locators.py @@ -3,85 +3,105 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- -import pathlib - import numpy as np -import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.ticker as ticker +# Setup a plot such that only the bottom spine is shown + -mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/ticks.mplstyle', -]) +def setup(ax): + ax.spines['right'].set_color('none') + ax.spines['left'].set_color('none') + ax.yaxis.set_major_locator(ticker.NullLocator()) + ax.spines['top'].set_color('none') + ax.xaxis.set_ticks_position('bottom') + ax.tick_params(which='major', width=1.00) + ax.tick_params(which='major', length=5) + ax.tick_params(which='minor', width=0.75) + ax.tick_params(which='minor', length=2.5) + ax.set_xlim(0, 5) + ax.set_ylim(0, 1) + ax.patch.set_alpha(0.0) -subplots_kw = dict( - figsize=(5.7/2.54, 4/2.54), - nrows=8, - subplot_kw=dict(xlim=(0, 5), ylim=(0, 1)), -) +fig = plt.figure(figsize=(8, 5)) +fig.patch.set_alpha(0.0) +n = 8 -(fig, axs) = plt.subplots(**subplots_kw) +fontsize = 18 +family = "Source Code Pro" # Null Locator -ax = axs[0] +ax = plt.subplot(n, 1, 1) +setup(ax) ax.xaxis.set_major_locator(ticker.NullLocator()) ax.xaxis.set_minor_locator(ticker.NullLocator()) -ax.text(0.0, 0.2, "ticker.NullLocator()", - fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) +ax.text(0.0, 0.1, "ticker.NullLocator()", + family=family, fontsize=fontsize, transform=ax.transAxes) # Multiple Locator -ax = axs[1] +ax = plt.subplot(n, 1, 2) +setup(ax) ax.xaxis.set_major_locator(ticker.MultipleLocator(0.5)) ax.xaxis.set_minor_locator(ticker.MultipleLocator(0.1)) -ax.text(0.0, 0.2, "ticker.MultipleLocator(0.5)", - fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) +ax.text(0.0, 0.1, "ticker.MultipleLocator(0.5)", + family=family, fontsize=fontsize, transform=ax.transAxes) # Fixed Locator -ax = axs[2] +ax = plt.subplot(n, 1, 3) +setup(ax) majors = [0, 1, 5] ax.xaxis.set_major_locator(ticker.FixedLocator(majors)) minors = np.linspace(0, 1, 11)[1:-1] ax.xaxis.set_minor_locator(ticker.FixedLocator(minors)) -ax.text(0.0, 0.2, "ticker.FixedLocator([0, 1, 5])", - fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) +ax.text(0.0, 0.1, "ticker.FixedLocator([0, 1, 5])", + family=family, fontsize=fontsize, transform=ax.transAxes) # Linear Locator -ax = axs[3] +ax = plt.subplot(n, 1, 4) +setup(ax) ax.xaxis.set_major_locator(ticker.LinearLocator(3)) ax.xaxis.set_minor_locator(ticker.LinearLocator(31)) -ax.text(0.0, 0.2, "ticker.LinearLocator(numticks=3)", - fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) +ax.text(0.0, 0.1, "ticker.LinearLocator(numticks=3)", + family=family, fontsize=fontsize, transform=ax.transAxes) # Index Locator -ax = axs[4] +ax = plt.subplot(n, 1, 5) +setup(ax) ax.plot(range(0, 5), [0]*5, color='white') ax.xaxis.set_major_locator(ticker.IndexLocator(base=.5, offset=.25)) -ax.text(0.0, 0.2, "ticker.IndexLocator(base=0.5, offset=0.25)", - fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) +ax.text(0.0, 0.1, "ticker.IndexLocator(base=0.5, offset=0.25)", + family=family, fontsize=fontsize, transform=ax.transAxes) # Auto Locator -ax = axs[5] +ax = plt.subplot(n, 1, 6) +setup(ax) ax.xaxis.set_major_locator(ticker.AutoLocator()) ax.xaxis.set_minor_locator(ticker.AutoMinorLocator()) -ax.text(0.0, 0.2, "ticker.AutoLocator()", - fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) +ax.text(0.0, 0.1, "ticker.AutoLocator()", + family=family, fontsize=fontsize, transform=ax.transAxes) # MaxN Locator -ax = axs[6] +ax = plt.subplot(n, 1, 7) +setup(ax) ax.xaxis.set_major_locator(ticker.MaxNLocator(4)) ax.xaxis.set_minor_locator(ticker.MaxNLocator(40)) -ax.text(0.0, 0.2, "ticker.MaxNLocator(n=4)", - fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) +ax.text(0.0, 0.1, "ticker.MaxNLocator(n=4)", + family=family, fontsize=fontsize, transform=ax.transAxes) # Log Locator -ax = axs[7] +ax = plt.subplot(n, 1, 8) +setup(ax) ax.set_xlim(10**3, 10**10) ax.set_xscale('log') ax.xaxis.set_major_locator(ticker.LogLocator(base=10.0, numticks=15)) -ax.text(0.0, 0.2, "ticker.LogLocator(base=10, numticks=15)", - fontfamily='Source Code Pro', transform=ax.transAxes, in_layout=False) +ax.text(0.0, 0.1, "ticker.LogLocator(base=10, numticks=15)", + family=family, fontsize=fontsize, transform=ax.transAxes) + +# Push the top of the top axes outside the figure because we only show the +# bottom spine. +plt.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=1.05) -fig.savefig("../figures/tick-locators.pdf") +plt.savefig("../figures/tick-locators.pdf", transparent=True) +# plt.show() From cfa709d50feb0e5dfb4988ebd82ce560c27e4ca6 Mon Sep 17 00:00:00 2001 From: Jamal Mustafa Date: Thu, 30 Mar 2023 17:47:06 -0700 Subject: [PATCH 32/65] replace `add_gridspec` with `plt.subplots` --- scripts/extents.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/extents.py b/scripts/extents.py index ba424d2..c3bec1d 100644 --- a/scripts/extents.py +++ b/scripts/extents.py @@ -17,10 +17,9 @@ Z = np.arange(5*5).reshape(5, 5) -fig = plt.figure(figsize=(8, 5)) -gs = fig.add_gridspec(2, 2) +(fig, axs) = plt.subplots(figsize=(8, 5), nrows=2, ncols=2) -ax = fig.add_subplot(gs[0, 0]) +ax = axs[0, 0] 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]) @@ -31,7 +30,7 @@ ax.text(5.0, -0.5, "extent=[0,10,0,5]", ha="center", va="center", color="black", size="large") -ax = fig.add_subplot(gs[1, 0]) +ax = axs[1, 0] 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]) @@ -43,7 +42,7 @@ ax.text(5.0, -0.5, "extent=[0,10,0,5]", ha="center", va="center", color="black", size="large") -ax = fig.add_subplot(gs[1, 1]) +ax = axs[1, 1] 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([]) @@ -54,7 +53,7 @@ ax.text(5.0, -0.5, "extent=[10,0,0,5]", ha="center", va="center", color="black", size="large") -ax = fig.add_subplot(gs[0, 1]) +ax = axs[0, 1] 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([]) From e98828aafac4f0ed3b6b901431a961620638cd9f Mon Sep 17 00:00:00 2001 From: Cameron Riddell Date: Mon, 5 Jun 2023 09:04:40 -0700 Subject: [PATCH 33/65] Replace calls to fig.show() with plt.show() Some examples call `fig.show()` with the expectation that a matpltolib figure will be displayed on-screen. However, since `fig.show` does not manage the backed GUI mainloop this will seemingly fail. In most cases, it will be more convenient for end-users to rely on `plt.show` to display figures. --- cheatsheets.tex | 2 +- handout-beginner.tex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index 09c86a1..3f34564 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -289,7 +289,7 @@ ax.plot(X, Y, color='green')\\ \\ fig.savefig(``figure.pdf'')\\ - fig.show() } + plt.show() } \end{myboxed} \vspace{\fill} diff --git a/handout-beginner.tex b/handout-beginner.tex index 690a844..1c9d32c 100644 --- a/handout-beginner.tex +++ b/handout-beginner.tex @@ -91,7 +91,7 @@ \section*{\LARGE \rmfamily \begin{lstlisting} fig, ax = plt.subplots() ax.plot(X, Y) - fig.show() + plt.show() \end{lstlisting} % \fbox{4} \textbf{Observe} \medskip\\ From 3720ef47e167939ece900d8bbf8b2dfb50a0ee33 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 23 Jan 2024 10:13:40 +0000 Subject: [PATCH 34/65] Bump pre-commit action version --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 821c6ef..1270699 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -8,7 +8,7 @@ jobs: steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 - - uses: pre-commit/action@v2.0.0 + - uses: pre-commit/action@v3.0.0 build: runs-on: ubuntu-20.04 steps: From 9d84c66c84bb41697b222d485283e8b259c4ba03 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 24 Jan 2024 11:37:37 +0000 Subject: [PATCH 35/65] Bump version of wheel in requirements.txt --- requirements/requirements.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 0a9c84e..a24e784 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,6 +1,6 @@ # -# This file is autogenerated by pip-compile with python 3.10 -# To update, run: +# This file is autogenerated by pip-compile with Python 3.10 +# by the following command: # # pip-compile requirements.in # @@ -164,7 +164,7 @@ urllib3==1.26.8 # via requests virtualenv==20.13.1 # via pre-commit -wheel==0.37.1 +wheel==0.42.0 # via pip-tools # The following packages are considered to be unsafe in a requirements file: From 85af93e64fea9a40d71bb0c45aa4472aaf928fc0 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 29 Mar 2023 04:11:06 -0400 Subject: [PATCH 36/65] Add image diffs against previous build to CI results --- .github/workflows/main.yaml | 12 +++++++++ Makefile | 1 + check-diffs.py | 51 +++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100755 check-diffs.py diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 1270699..8c50ad0 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -62,6 +62,18 @@ jobs: cheatsheets.pdf handout-*.pdf ./docs/_build/html/ + - uses: actions/upload-artifact@v4 + id: diffs-artifact-upload + if: ${{ always() }} + with: + name: diffs + path: | + diffs/ + - name: Output artifacts URL + run: | + echo 'Artifact URL:' \ + '${{ steps.diffs-artifact-upload.outputs.artifact-url }}' \ + >> $GITHUB_STEP_SUMMARY - name: Publish cheatsheets and handouts if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} uses: peaceiris/actions-gh-pages@v3 diff --git a/Makefile b/Makefile index 555ef60..4e0ef4c 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,7 @@ check: ./check-num-pages.sh handout-beginner.pdf 1 ./check-num-pages.sh handout-intermediate.pdf 1 ./check-links.py cheatsheets.pdf + ./check-diffs.py .PHONY: docs docs: diff --git a/check-diffs.py b/check-diffs.py new file mode 100755 index 0000000..e68c0d6 --- /dev/null +++ b/check-diffs.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +import os +import subprocess +import sys +from pathlib import Path + + +ROOT_DIR = Path(__file__).parent + +if os.environ.get('GITHUB_ACTIONS', '') == '': + print('Not running when not in GitHub Actions.') + sys.exit() +summary_file = os.environ.get('GITHUB_STEP_SUMMARY') +if summary_file is None: + sys.exit('$GITHUB_STEP_SUMMARY is not set') + +gh_pages = ROOT_DIR.parent / 'pages' +subprocess.run(['git', 'fetch', 'https://github.com/matplotlib/cheatsheets.git', + 'gh-pages:upstream-gh-pages'], check=True) +subprocess.run(['git', 'worktree', 'add', gh_pages, 'upstream-gh-pages'], + check=True) + +diff_dir = ROOT_DIR / 'diffs' +diff_dir.mkdir(exist_ok=True) + +hashes = {} +for original in gh_pages.glob('*.png'): + result = subprocess.run( + ['compare', '-metric', 'PHASH', + original, + ROOT_DIR / 'docs/_build/html' / original.name, + diff_dir / f'{original.stem}-diff.png'], + text=True, stderr=subprocess.PIPE) + if result.returncode == 2: # Some kind of IO or similar error. + hashes[original] = (float('nan'), result.stderr) + elif result.stderr: # Images were different. + hashes[original] = (float(result.stderr), '') + else: # No differences. + hashes[original] = (0.0, '') + +with open(summary_file, 'w+') as summary: + print('# Cheatsheet image comparison', file=summary) + print('| Filename | Perceptual Hash Difference | Error message |', file=summary) + print('| -------- | -------------------------- | ------------- |', file=summary) + for filename, (hash, message) in sorted(hashes.items()): + message = message.replace('\n', ' ').replace('|', '\\|') + print(f'| {filename.name} | {hash:.05f} | {message}', file=summary) + print(file=summary) + +subprocess.run(['git', 'worktree', 'remove', gh_pages]) From 245c6507c9f6efe88cf69ee4fd24054c1d08f2d9 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 30 Jan 2024 09:58:24 +0000 Subject: [PATCH 37/65] Bump cartopy version --- requirements/requirements.in | 2 +- requirements/requirements.txt | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/requirements/requirements.in b/requirements/requirements.in index b3c566a..92f027c 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -1,6 +1,6 @@ autopep8 bump2version -cartopy==0.19.0.post1 +cartopy==0.22.0 flake8 matplotlib==3.5.0 mpl-sphinx-theme diff --git a/requirements/requirements.txt b/requirements/requirements.txt index a24e784..66fff0c 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -16,10 +16,12 @@ beautifulsoup4==4.10.0 # via pydata-sphinx-theme bump2version==1.0.1 # via -r requirements.in -cartopy==0.19.0.post1 +cartopy==0.22.0 # via -r requirements.in certifi==2021.10.8 - # via requests + # via + # pyproj + # requests cffi==1.15.0 # via cryptography cfgv==3.3.1 @@ -61,7 +63,9 @@ kiwisolver==1.3.2 markupsafe==2.1.0 # via jinja2 matplotlib==3.5.0 - # via -r requirements.in + # via + # -r requirements.in + # cartopy mccabe==0.6.1 # via flake8 mpl-sphinx-theme==3.5.0 @@ -75,6 +79,7 @@ numpy==1.22.2 # scipy packaging==21.3 # via + # cartopy # matplotlib # setuptools-scm # sphinx @@ -110,6 +115,8 @@ pyparsing==3.0.7 # via # matplotlib # packaging +pyproj==3.6.1 + # via cartopy pyshp==2.2.0 # via cartopy python-dateutil==2.8.2 From 7f40833acc5dfea5dc062c92fcfc333b3099f164 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 28 Mar 2023 21:39:53 -0400 Subject: [PATCH 38/65] Save figures in a path relative to the script This allows running them from the `scripts` directory, _or_ the top of the checkout. --- scripts/adjustements.py | 7 ++++--- scripts/advanced-plots.py | 24 +++++++++++---------- scripts/anatomy.py | 7 ++++--- scripts/annotate.py | 6 +++++- scripts/annotation-arrow-styles.py | 7 ++++++- scripts/annotation-connection-styles.py | 8 ++++--- scripts/basic-plots.py | 28 +++++++++++++------------ scripts/colorbar.py | 7 ++++++- scripts/colormaps.py | 6 +++++- scripts/colornames.py | 6 ++++-- scripts/colors.py | 7 ++++++- scripts/extents.py | 7 ++++--- scripts/fonts.py | 4 +++- scripts/interpolations.py | 9 ++++---- scripts/layouts.py | 19 ++++++++++------- scripts/legend.py | 6 ++++-- scripts/linestyles.py | 6 +++++- scripts/markers.py | 6 +++++- scripts/plot-variations.py | 23 +++++++++++--------- scripts/projections.py | 13 ++++++------ scripts/scales.py | 13 ++++++++---- scripts/sine.py | 19 +++++++++-------- scripts/styles.py | 7 ++++++- scripts/text-alignments.py | 7 ++++++- scripts/tick-formatters.py | 8 +++++-- scripts/tick-locators.py | 8 +++++-- scripts/tick-multiple-locator.py | 8 ++++--- scripts/tip-color-range.py | 7 ++++++- scripts/tip-colorbar.py | 7 ++++++- scripts/tip-dotted.py | 8 ++++++- scripts/tip-dual-axis.py | 9 ++++++-- scripts/tip-font-family.py | 8 +++++-- scripts/tip-hatched.py | 7 ++++++- scripts/tip-multiline.py | 8 ++++++- scripts/tip-outline.py | 7 ++++++- scripts/tip-post-processing.py | 7 ++++++- scripts/tip-transparency.py | 7 ++++++- 37 files changed, 242 insertions(+), 109 deletions(-) diff --git a/scripts/adjustements.py b/scripts/adjustements.py index f433a69..26f9559 100644 --- a/scripts/adjustements.py +++ b/scripts/adjustements.py @@ -11,8 +11,10 @@ from matplotlib.collections import PatchCollection +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', ]) mpl.rc('font', size=4) mpl.rc('lines', linewidth=0.5) @@ -33,7 +35,6 @@ (fig, ax) = plt.subplots(**subplots_kw) - box = mpatches.FancyBboxPatch( (0, 0), 100, 83, mpatches.BoxStyle("Round", pad=0, rounding_size=2), facecolor="0.9", edgecolor="black") @@ -145,4 +146,4 @@ def int_arrow(p0, p1): rotation="vertical", ha="center", va="center") -plt.savefig("../figures/adjustments.pdf") +fig.savefig(ROOT_DIR / "figures/adjustments.pdf") diff --git a/scripts/advanced-plots.py b/scripts/advanced-plots.py index 4d86ba0..f598087 100644 --- a/scripts/advanced-plots.py +++ b/scripts/advanced-plots.py @@ -11,9 +11,11 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/plotlet.mplstyle', ]) @@ -29,7 +31,7 @@ Y = 4 + 2*np.sin(2*X) ax.step(X, Y, color="C1") ax.grid() -fig.savefig("../figures/advanced-step.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-step.pdf") # Violin plot # ----------------------------------------------------------------------------- @@ -43,7 +45,7 @@ body.set_alpha(1) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-violin.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-violin.pdf") # Boxplot # ----------------------------------------------------------------------------- @@ -63,7 +65,7 @@ "linewidth": 0.75}) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-boxplot.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-boxplot.pdf") # Barbs plot # ----------------------------------------------------------------------------- @@ -76,7 +78,7 @@ ax.barbs(X, Y, U, V, barbcolor="C1", flagcolor="C1", length=5, linewidth=0.5) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-barbs.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-barbs.pdf") # Event plot # ----------------------------------------------------------------------------- @@ -88,7 +90,7 @@ linewidth=0.25) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-event.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-event.pdf") # Errorbar plot # ----------------------------------------------------------------------------- @@ -100,7 +102,7 @@ ax.errorbar(X, Y, E, color="C1", linewidth=0.75, capsize=1) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-errorbar.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-errorbar.pdf") # Hexbin plot # ----------------------------------------------------------------------------- @@ -113,7 +115,7 @@ cmap=plt.get_cmap("Wistia"), alpha=1.0) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-hexbin.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-hexbin.pdf") # Hist plot # ----------------------------------------------------------------------------- @@ -124,7 +126,7 @@ ax.set_ylim(0, 80), ax.set_yticks(np.arange(1, 80, 10)) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-hist.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-hist.pdf") # Xcorr plot # ----------------------------------------------------------------------------- @@ -138,4 +140,4 @@ ax.set_ylim(-.25, .25), ax.set_yticks(np.linspace(-.25, .25, 9)) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-xcorr.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-xcorr.pdf") diff --git a/scripts/anatomy.py b/scripts/anatomy.py index a79037e..e8f95cc 100644 --- a/scripts/anatomy.py +++ b/scripts/anatomy.py @@ -11,11 +11,12 @@ from matplotlib.ticker import AutoMinorLocator, MultipleLocator, FuncFormatter +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', ]) - np.random.seed(123) X = np.linspace(0.5, 3.5, 100) @@ -144,5 +145,5 @@ def text(x, y, text): connectionstyle="arc3", color=color)) -plt.savefig("../figures/anatomy.pdf") +fig.savefig(ROOT_DIR / "figures/anatomy.pdf") # plt.show() diff --git a/scripts/annotate.py b/scripts/annotate.py index 4254941..6535368 100644 --- a/scripts/annotate.py +++ b/scripts/annotate.py @@ -2,11 +2,15 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + fig = plt.figure(figsize=(6, 1)) # ax = plt.subplot(111, frameon=False, aspect=.1) # b = 0.0 @@ -23,5 +27,5 @@ plt.text( 5.5, 0.6, "xy\nxycoords", size=10, va="top", ha="center", color=".5") plt.text( .75, 0.6, "xytext\ntextcoords", size=10, va="top", ha="center", color=".5") -plt.savefig("../figures/annotate.pdf") +fig.savefig(ROOT_DIR / "figures/annotate.pdf") # plt.show() diff --git a/scripts/annotation-arrow-styles.py b/scripts/annotation-arrow-styles.py index 648a4c4..26ac950 100644 --- a/scripts/annotation-arrow-styles.py +++ b/scripts/annotation-arrow-styles.py @@ -1,6 +1,11 @@ +import pathlib + import matplotlib.pyplot as plt import matplotlib.patches as mpatches + +ROOT_DIR = pathlib.Path(__file__).parent.parent + styles = mpatches.ArrowStyle.get_styles() @@ -29,5 +34,5 @@ def demo_con_style(ax, connectionstyle): transform=ax.transAxes, family="Source Code Pro", ha="center", va="top") -plt.savefig("../figures/annotation-arrow-styles.pdf") +fig.savefig(ROOT_DIR / "figures/annotation-arrow-styles.pdf") # plt.show() diff --git a/scripts/annotation-connection-styles.py b/scripts/annotation-connection-styles.py index 81908d7..057b5cd 100644 --- a/scripts/annotation-connection-styles.py +++ b/scripts/annotation-connection-styles.py @@ -4,9 +4,11 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/plotlet-grid.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/plotlet-grid.mplstyle', ]) mpl.rc('lines', markersize=3) @@ -41,4 +43,4 @@ def demo_con_style(ax, connectionstyle): for ax in axs.flat: ax.set(xlim=(0, 1), ylim=(0, 1), xticks=[], yticks=[], aspect=1) -plt.savefig("../figures/annotation-connection-styles.pdf") +fig.savefig(ROOT_DIR / "figures/annotation-connection-styles.pdf") diff --git a/scripts/basic-plots.py b/scripts/basic-plots.py index 5dd8598..8350326 100644 --- a/scripts/basic-plots.py +++ b/scripts/basic-plots.py @@ -11,9 +11,11 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/plotlet.mplstyle', ]) @@ -29,7 +31,7 @@ Y = 4 + 2*np.sin(2*X) ax.plot(X, Y, color="C1") ax.grid() -fig.savefig("../figures/basic-plot.pdf") +fig.savefig(ROOT_DIR / "figures/basic-plot.pdf") # Basic line plot (color) # ----------------------------------------------------------------------------- @@ -38,7 +40,7 @@ Y = 4 + 2*np.sin(2*X) ax.plot(X, Y, color="black") ax.grid() -fig.savefig("../figures/basic-plot-color.pdf") +fig.savefig(ROOT_DIR / "figures/basic-plot-color.pdf") # Basic scatter plot # ----------------------------------------------------------------------------- @@ -49,7 +51,7 @@ ax.scatter(X, Y, 5, zorder=10, edgecolor="white", facecolor="C1", linewidth=0.25) ax.grid() -fig.savefig("../figures/basic-scatter.pdf") +fig.savefig(ROOT_DIR / "figures/basic-scatter.pdf") # Basic bar plot # ----------------------------------------------------------------------------- @@ -61,7 +63,7 @@ edgecolor="white", facecolor="C1", linewidth=0.25) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/basic-bar.pdf") +fig.savefig(ROOT_DIR / "figures/basic-bar.pdf") # Basic imshow plot # ----------------------------------------------------------------------------- @@ -72,7 +74,7 @@ Z[..., 3] = np.random.uniform(0.25, 1.0, (8, 8)) ax.imshow(Z, extent=[0, 8, 0, 8], interpolation="nearest") ax.grid(linewidth=0.25, color="white") -fig.savefig("../figures/basic-imshow.pdf") +fig.savefig(ROOT_DIR / "figures/basic-imshow.pdf") # Basic pcolormesh plot # ----------------------------------------------------------------------------- @@ -84,7 +86,7 @@ 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)) -fig.savefig("../figures/basic-pcolormesh.pdf") +fig.savefig(ROOT_DIR / "figures/basic-pcolormesh.pdf") # Basic contour plot # ----------------------------------------------------------------------------- @@ -95,7 +97,7 @@ 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) -fig.savefig("../figures/basic-contour.pdf") +fig.savefig(ROOT_DIR / "figures/basic-contour.pdf") # Basic pie plot # ----------------------------------------------------------------------------- @@ -110,7 +112,7 @@ 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) -fig.savefig("../figures/basic-pie.pdf") +fig.savefig(ROOT_DIR / "figures/basic-pie.pdf") # Basic text plot # ----------------------------------------------------------------------------- @@ -119,7 +121,7 @@ ax.grid(linewidth=0.25, color="0.75") ax.text(4, 4, "TEXT", color="C1", size=8, weight="bold", ha="center", va="center", rotation=25) -fig.savefig("../figures/basic-text.pdf") +fig.savefig(ROOT_DIR / "figures/basic-text.pdf") # Basic fill plot # ----------------------------------------------------------------------------- @@ -132,7 +134,7 @@ plt.plot(X, (Y1+Y2)/2, color="C1", linewidth=0.5) ax.set_axisbelow(True) ax.grid(color="0.75") -fig.savefig("../figures/basic-fill.pdf") +fig.savefig(ROOT_DIR / "figures/basic-fill.pdf") # Basic quiver plot # ----------------------------------------------------------------------------- @@ -145,4 +147,4 @@ angles='xy', scale_units='xy', scale=0.5, width=.05) ax.set_axisbelow(True) ax.grid(color="0.75") -fig.savefig("../figures/basic-quiver.pdf") +fig.savefig(ROOT_DIR / "figures/basic-quiver.pdf") diff --git a/scripts/colorbar.py b/scripts/colorbar.py index 495cccc..6ffba8f 100644 --- a/scripts/colorbar.py +++ b/scripts/colorbar.py @@ -2,11 +2,16 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- + +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + fig = plt.figure(figsize=(6, .65)) # ax = plt.subplot(111, frameon=False, aspect=.1) b = 0.025 @@ -19,5 +24,5 @@ plt.colorbar(sm, cax=ax, ticks=np.linspace(0, 1, 11), orientation="horizontal") -plt.savefig("../figures/colorbar.pdf") +fig.savefig(ROOT_DIR / "figures/colorbar.pdf") # plt.show() diff --git a/scripts/colormaps.py b/scripts/colormaps.py index a0a0f4b..8858299 100644 --- a/scripts/colormaps.py +++ b/scripts/colormaps.py @@ -1,7 +1,11 @@ +import pathlib + import numpy as np import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + figsize = 4.0, 0.25 fig = plt.figure(figsize=figsize) ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1) @@ -62,5 +66,5 @@ family = "Source Pro Serif", size=10, ha="center", va="center") """ - plt.savefig("../figures/colormap-%s.pdf" % cmap) + fig.savefig(ROOT_DIR / f"figures/colormap-{cmap}.pdf") ax.clear() diff --git a/scripts/colornames.py b/scripts/colornames.py index d88d381..a059787 100644 --- a/scripts/colornames.py +++ b/scripts/colornames.py @@ -11,8 +11,10 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', ]) mpl.rc('figure.constrained_layout', h_pad=0, w_pad=0, hspace=0, wspace=0) @@ -54,4 +56,4 @@ ax.set_ylim(0, Y) ax.set_axis_off() -plt.savefig("../figures/colornames.pdf") +fig.savefig(ROOT_DIR / "figures/colornames.pdf") diff --git a/scripts/colors.py b/scripts/colors.py index 9d323e3..1bd76f8 100644 --- a/scripts/colors.py +++ b/scripts/colors.py @@ -2,11 +2,16 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- + +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + figsize = 4.0, 0.25 fig = plt.figure(figsize=figsize) ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1) @@ -36,5 +41,5 @@ ax.text((i+0.5)*dx, (ymin+ymax)/2, text, color=color, zorder=10, family="Source Code Pro", size=9, ha="center", va="center") - plt.savefig("../figures/colors-%s.pdf" % name) + fig.savefig(ROOT_DIR / f"figures/colors-{name}.pdf") ax.clear() diff --git a/scripts/extents.py b/scripts/extents.py index c3bec1d..2eab814 100644 --- a/scripts/extents.py +++ b/scripts/extents.py @@ -9,12 +9,13 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', ]) mpl.rc('figure.constrained_layout', wspace=0.05) - Z = np.arange(5*5).reshape(5, 5) (fig, axs) = plt.subplots(figsize=(8, 5), nrows=2, ncols=2) @@ -64,4 +65,4 @@ ax.text(5.0, -0.5, "extent=[10,0,0,5]", ha="center", va="center", color="black", size="large") -plt.savefig("../figures/extents.pdf", dpi=600) +fig.savefig(ROOT_DIR / "figures/extents.pdf", dpi=600) diff --git a/scripts/fonts.py b/scripts/fonts.py index 9766453..7d39e10 100644 --- a/scripts/fonts.py +++ b/scripts/fonts.py @@ -7,6 +7,8 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + 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]) @@ -105,5 +107,5 @@ y += 1.65* max(sizes[size], sizes["small"]) -plt.savefig("../figures/fonts.pdf") +fig.savefig(ROOT_DIR / "figures/fonts.pdf") # plt.show() diff --git a/scripts/interpolations.py b/scripts/interpolations.py index 783d26c..3cd1308 100644 --- a/scripts/interpolations.py +++ b/scripts/interpolations.py @@ -5,12 +5,13 @@ import numpy as np +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/plotlet-grid.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/plotlet-grid.mplstyle', ]) - methods = [None, 'none', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos'] @@ -28,5 +29,5 @@ ax.text(0.5, 0.1, str(interp_method), weight="bold", color="white", size=6, ha="center", va="center") -plt.savefig("../figures/interpolations.pdf", dpi=600) +fig.savefig(ROOT_DIR / "figures/interpolations.pdf", dpi=600) # plt.show() diff --git a/scripts/layouts.py b/scripts/layouts.py index 9438c5d..49f7340 100644 --- a/scripts/layouts.py +++ b/scripts/layouts.py @@ -2,11 +2,16 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable + +ROOT_DIR = pathlib.Path(__file__).parent.parent + fig = plt.figure(figsize=(0.4, 0.4)) margin = 0.01 fig.subplots_adjust(left=margin, right=1-margin, top=1-margin, bottom=margin) @@ -18,7 +23,7 @@ for i in range(nrows*ncols): ax = plt.subplot(ncols, nrows, i+1) ax.set_xticks([]), ax.set_yticks([]) -plt.savefig("../figures/layout-subplot.pdf") +fig.savefig(ROOT_DIR / "figures/layout-subplot.pdf") fig.clear() # Subplots (colored) @@ -29,7 +34,7 @@ ax.set_xticks([]), ax.set_yticks([]) if i == 0: ax.set_facecolor("#ddddff") if i == 8: ax.set_facecolor("#ffdddd") -plt.savefig("../figures/layout-subplot-color.pdf") +fig.savefig(ROOT_DIR / "figures/layout-subplot-color.pdf") fig.clear() # Spines @@ -37,7 +42,7 @@ 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") +fig.savefig(ROOT_DIR / "figures/layout-spines.pdf") fig.clear() @@ -49,7 +54,7 @@ ax3 = fig.add_subplot(gs[1:, -1], xticks=[], yticks=[]) ax4 = fig.add_subplot(gs[-1, 0], xticks=[], yticks=[]) ax5 = fig.add_subplot(gs[-1, -2], xticks=[], yticks=[]) -plt.savefig("../figures/layout-gridspec.pdf") +fig.savefig(ROOT_DIR / "figures/layout-gridspec.pdf") fig.clear() # Gridspec (colored) @@ -61,7 +66,7 @@ ax3 = fig.add_subplot(gs[1:, -1], xticks=[], yticks=[]) ax4 = fig.add_subplot(gs[-1, 0], xticks=[], yticks=[]) ax5 = fig.add_subplot(gs[-1, -2], xticks=[], yticks=[]) -plt.savefig("../figures/layout-gridspec-color.pdf") +fig.savefig(ROOT_DIR / "figures/layout-gridspec-color.pdf") fig.clear() # Inset axes @@ -70,7 +75,7 @@ margin = 0.0125 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.savefig(ROOT_DIR / "figures/layout-inset.pdf") fig.clear() @@ -82,4 +87,4 @@ cax = divider.new_horizontal(size="10%", pad=0.025) fig.add_axes(cax) cax.set_xticks([]), cax.set_yticks([]) -plt.savefig("../figures/layout-divider.pdf") +fig.savefig(ROOT_DIR / "figures/layout-divider.pdf") diff --git a/scripts/legend.py b/scripts/legend.py index f75f147..5faf885 100644 --- a/scripts/legend.py +++ b/scripts/legend.py @@ -9,8 +9,10 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', ]) mpl.rc('font', size=6) mpl.rc('lines', markersize=4) @@ -63,4 +65,4 @@ def point(x, y): 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), -fig.savefig("../figures/legend-placement.pdf") +fig.savefig(ROOT_DIR / "figures/legend-placement.pdf") diff --git a/scripts/linestyles.py b/scripts/linestyles.py index b1c619e..6f9deaa 100644 --- a/scripts/linestyles.py +++ b/scripts/linestyles.py @@ -2,10 +2,14 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + 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=[]) @@ -53,5 +57,5 @@ def split(n_segment): size=14, ha="left", va="baseline") -plt.savefig("../figures/linestyles.pdf", dpi=200) +fig.savefig(ROOT_DIR / "figures/linestyles.pdf", dpi=200) # plt.show() diff --git a/scripts/markers.py b/scripts/markers.py index 50c5e36..48f1d01 100644 --- a/scripts/markers.py +++ b/scripts/markers.py @@ -2,10 +2,14 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + # Markers # ----------------------------------------------------------------------------- fig = plt.figure(figsize=(3.5, 1.5)) @@ -52,4 +56,4 @@ plt.text(.7, 1, "markevery", size="medium", ha="left", va="center", family="Source Code Pro") -plt.savefig("../figures/markers.pdf", dpi=600) +fig.savefig(ROOT_DIR / "figures/markers.pdf", dpi=600) diff --git a/scripts/plot-variations.py b/scripts/plot-variations.py index 60f9463..65b9ff1 100644 --- a/scripts/plot-variations.py +++ b/scripts/plot-variations.py @@ -10,9 +10,11 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/plotlet.mplstyle', ]) mpl.rc('axes', titlepad=1) @@ -29,7 +31,7 @@ Y = 4+2*np.sin(2*X) ax.plot(X, Y, color="black", linewidth=0.75) ax.grid() -fig.savefig("../figures/plot-color.pdf") +fig.savefig(ROOT_DIR / "figures/plot-color.pdf") # Basic line plot (linestyle) # ----------------------------------------------------------------------------- @@ -38,7 +40,7 @@ Y = 4+2*np.sin(2*X) ax.plot(X, Y, color="C1", linewidth=0.75, linestyle="--") ax.grid() -fig.savefig("../figures/plot-linestyle.pdf") +fig.savefig(ROOT_DIR / "figures/plot-linestyle.pdf") # Basic line plot (linewidth) # ----------------------------------------------------------------------------- @@ -48,6 +50,7 @@ ax.plot(X, Y, color="C1", linewidth=1.5) ax.grid() fig.savefig("../figures/plot-linewidth.pdf") +fig.savefig(ROOT_DIR / "figures/plot-linewidth.pdf") # Basic line plot (marker) # ----------------------------------------------------------------------------- @@ -56,7 +59,7 @@ Y = 4+2*np.sin(2*X) ax.plot(X, Y, color="C1", linewidth=0.75, marker="o", markevery=5, markersize=2) ax.grid() -fig.savefig("../figures/plot-marker.pdf") +fig.savefig(ROOT_DIR / "figures/plot-marker.pdf") # Basic line plot (multi) # ----------------------------------------------------------------------------- @@ -67,7 +70,7 @@ ax.plot(X, Y1, color="C1", linewidth=0.75) ax.plot(X, Y2, color="C0", linewidth=0.75) ax.grid() -fig.savefig("../figures/plot-multi.pdf") +fig.savefig(ROOT_DIR / "figures/plot-multi.pdf") # Basic line plot (vsplit) # ----------------------------------------------------------------------------- @@ -85,7 +88,7 @@ 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) -fig.savefig("../figures/plot-vsplit.pdf") +fig.savefig(ROOT_DIR / "figures/plot-vsplit.pdf") # Basic line plot (hsplit) # ----------------------------------------------------------------------------- @@ -103,7 +106,7 @@ 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) -fig.savefig("../figures/plot-hsplit.pdf") +fig.savefig(ROOT_DIR / "figures/plot-hsplit.pdf") # Basic line plot (title) # ----------------------------------------------------------------------------- @@ -114,7 +117,7 @@ ax.set_ylim(0, 6), ax.set_yticks(np.arange(1, 6)) ax.grid() ax.set_title("A Sine wave", size=4, weight="bold") -fig.savefig("../figures/plot-title.pdf") +fig.savefig(ROOT_DIR / "figures/plot-title.pdf") # Basic line plot (xlabel) # ----------------------------------------------------------------------------- @@ -126,4 +129,4 @@ ax.grid() ax.text(4, -1, "Time", transform=ax.transData, clip_on=False, size=3.5, ha="center", va="center") -fig.savefig("../figures/plot-xlabel.pdf") +fig.savefig(ROOT_DIR / "figures/plot-xlabel.pdf") diff --git a/scripts/projections.py b/scripts/projections.py index fde46cb..1f623a9 100644 --- a/scripts/projections.py +++ b/scripts/projections.py @@ -10,12 +10,13 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/plotlet.mplstyle', ]) - CARTOPY_SOURCE_TEMPLATE = 'https://naturalearth.s3.amazonaws.com/%7Bresolution%7D_%7Bcategory%7D/ne_%7Bresolution%7D_%7Bname%7D.zip' @@ -39,7 +40,7 @@ ax.set_yticklabels([]) ax.set_ylim(0, 2) ax.grid(linewidth=0.2) -plt.savefig("../figures/projection-polar.pdf") +fig.savefig(ROOT_DIR / "figures/projection-polar.pdf") fig.clear() # 3D plot @@ -57,7 +58,7 @@ ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) -plt.savefig("../figures/projection-3d.pdf") +fig.savefig(ROOT_DIR / "figures/projection-3d.pdf") fig.clear() # Cartopy plot @@ -67,4 +68,4 @@ projection=cartopy.crs.Orthographic()) ax.add_feature(cartopy.feature.LAND, zorder=0, facecolor="C1", edgecolor="0.0", linewidth=0) -plt.savefig("../figures/projection-cartopy.pdf") +fig.savefig(ROOT_DIR / "figures/projection-cartopy.pdf") diff --git a/scripts/scales.py b/scripts/scales.py index 7520d00..70192ca 100644 --- a/scripts/scales.py +++ b/scripts/scales.py @@ -1,6 +1,11 @@ +import pathlib + import numpy as np import matplotlib.pyplot as plt + +ROOT_DIR = pathlib.Path(__file__).parent.parent + 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) @@ -19,7 +24,7 @@ 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) -plt.savefig("../figures/scale-linear.pdf") +fig.savefig(ROOT_DIR / "figures/scale-linear.pdf") ax.clear() # Log scale @@ -31,7 +36,7 @@ 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) -plt.savefig("../figures/scale-log.pdf") +fig.savefig(ROOT_DIR / "figures/scale-log.pdf") ax.clear() # Symlog scale @@ -43,7 +48,7 @@ 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) -plt.savefig("../figures/scale-symlog.pdf") +fig.savefig(ROOT_DIR / "figures/scale-symlog.pdf") ax.clear() # Symlog scale @@ -55,5 +60,5 @@ 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) -plt.savefig("../figures/scale-logit.pdf") +fig.savefig(ROOT_DIR / "figures/scale-logit.pdf") ax.clear() diff --git a/scripts/sine.py b/scripts/sine.py index 6b30775..0e6a347 100644 --- a/scripts/sine.py +++ b/scripts/sine.py @@ -9,31 +9,32 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/sine-plot.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/sine-plot.mplstyle', ]) - X = np.linspace(0.1, 10*np.pi, 10000) Y = np.sin(X) (fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.2/2.54)) ax.set_yticks(np.linspace(-1, 1, 5)) ax.plot(X, Y, color="orange") -plt.savefig("../figures/sine.pdf") +fig.savefig(ROOT_DIR / "figures/sine.pdf") (fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) ax.plot(X, Y, "C1o:", markevery=500, mec="1.0") ax.set_ylim(-1.5, 1.5) -fig.savefig("../figures/sine-marker.pdf") +fig.savefig(ROOT_DIR / "figures/sine-marker.pdf") fig, ax = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) ax.set_xscale("log") ax.plot(X, Y, "-") ax.plot(X, Y, "C1o-", markevery=500, mec="1.0") ax.set_ylim(-1.5, 1.5) -fig.savefig("../figures/sine-logscale.pdf") +fig.savefig(ROOT_DIR / "figures/sine-logscale.pdf") (fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) @@ -41,7 +42,7 @@ ax.fill_betweenx([-1.5, 1.5], [0], [2*np.pi], color=".9") ax.text(0, -1, r" Period $\Phi$", va="top") ax.set_ylim(-1.5, 1.5) -fig.savefig("../figures/sine-period.pdf") +fig.savefig(ROOT_DIR / "figures/sine-period.pdf") (fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) @@ -52,7 +53,7 @@ ax.set_title("Sine and Cosine") ax.set_xticks([]), ax.set_yticks([]) ax.set_ylim(-1.25, 1.25) -fig.savefig("../figures/sine-legend.pdf") +fig.savefig(ROOT_DIR / "figures/sine-legend.pdf") (fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) @@ -66,4 +67,4 @@ arrowprops=dict(arrowstyle="->", color="C1", linewidth=0.5, patchA=None, shrinkA=4, shrinkB=0.5)) ax.annotate(" ", (X[300], Y[300]), (X[250], -1), ha="center", va="center", arrowprops=dict(arrowstyle="->", color="C1", linewidth=0.5, patchA=None, shrinkA=4, shrinkB=0.5)) -fig.savefig("../figures/sine-annotate.pdf") +fig.savefig(ROOT_DIR / "figures/sine-annotate.pdf") diff --git a/scripts/styles.py b/scripts/styles.py index 94ff839..bedf9d9 100644 --- a/scripts/styles.py +++ b/scripts/styles.py @@ -2,10 +2,15 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + +ROOT_DIR = pathlib.Path(__file__).parent.parent + for style in ['default'] + plt.style.available: with plt.style.context(style): fig = plt.figure(figsize=(5, 3), dpi=100) @@ -15,5 +20,5 @@ ax.plot(X, Y) plt.title(style, family="Source Serif Pro", size=32) plt.tight_layout() - plt.savefig("../figures/style-%s.pdf" % style) + fig.savefig(ROOT_DIR / f"figures/style-{style}.pdf") plt.close(fig) diff --git a/scripts/text-alignments.py b/scripts/text-alignments.py index c329ae0..0d653b9 100644 --- a/scripts/text-alignments.py +++ b/scripts/text-alignments.py @@ -2,9 +2,14 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib.pyplot as plt + +ROOT_DIR = pathlib.Path(__file__).parent.parent + dpi = 100 fig = plt.figure(figsize=(4.25, 1.5), dpi=dpi) ax = fig.add_axes([0, 0, 1, 1], frameon=False, @@ -66,5 +71,5 @@ 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") +fig.savefig(ROOT_DIR / "figures/text-alignments.pdf") # plt.show() diff --git a/scripts/tick-formatters.py b/scripts/tick-formatters.py index fe5bb40..bcdce04 100644 --- a/scripts/tick-formatters.py +++ b/scripts/tick-formatters.py @@ -3,12 +3,16 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import pathlib + import matplotlib.pyplot as plt import matplotlib.ticker as ticker -# Setup a plot such that only the bottom spine is shown +ROOT_DIR = pathlib.Path(__file__).parent.parent + +# Setup a plot such that only the bottom spine is shown def setup(ax): """Set up Axes with just an x-Axis.""" ax.spines['right'].set_color('none') @@ -107,5 +111,5 @@ def major_formatter(x, pos): # bottom spine. fig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=1.05) -plt.savefig("../figures/tick-formatters.pdf", transparent=True) +fig.savefig(ROOT_DIR / "figures/tick-formatters.pdf", transparent=True) # plt.show() diff --git a/scripts/tick-locators.py b/scripts/tick-locators.py index 276f8a3..4c0985c 100644 --- a/scripts/tick-locators.py +++ b/scripts/tick-locators.py @@ -3,13 +3,17 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as ticker -# Setup a plot such that only the bottom spine is shown +ROOT_DIR = pathlib.Path(__file__).parent.parent + +# 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') @@ -103,5 +107,5 @@ def setup(ax): # bottom spine. plt.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=1.05) -plt.savefig("../figures/tick-locators.pdf", transparent=True) +fig.savefig(ROOT_DIR / "figures/tick-locators.pdf", transparent=True) # plt.show() diff --git a/scripts/tick-multiple-locator.py b/scripts/tick-multiple-locator.py index c8a799e..2976a63 100644 --- a/scripts/tick-multiple-locator.py +++ b/scripts/tick-multiple-locator.py @@ -11,9 +11,11 @@ import matplotlib.ticker as ticker +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/ticks.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/ticks.mplstyle', ]) @@ -30,4 +32,4 @@ ax.tick_params(axis='both', which='major', labelsize=5) ax.tick_params(axis='x', which='minor', rotation=90) -plt.savefig("../figures/tick-multiple-locator.pdf", transparent=True) +fig.savefig(ROOT_DIR / "figures/tick-multiple-locator.pdf", transparent=True) diff --git a/scripts/tip-color-range.py b/scripts/tip-color-range.py index b8b43eb..5743940 100644 --- a/scripts/tip-color-range.py +++ b/scripts/tip-color-range.py @@ -4,10 +4,15 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + +ROOT_DIR = pathlib.Path(__file__).parent.parent + fig = plt.figure(figsize=(2, 2)) mpl.rcParams['axes.linewidth'] = 1.5 d = 0.01 @@ -20,5 +25,5 @@ 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") +fig.savefig(ROOT_DIR / "figures/tip-color-range.pdf") # plt.show() diff --git a/scripts/tip-colorbar.py b/scripts/tip-colorbar.py index 2a46357..9e8da79 100644 --- a/scripts/tip-colorbar.py +++ b/scripts/tip-colorbar.py @@ -4,11 +4,16 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import pathlib + 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 + fig = plt.figure(figsize=(2.15, 2)) mpl.rcParams['axes.linewidth'] = 1.5 d = 0.01 @@ -21,5 +26,5 @@ cb = fig.colorbar(im, fraction=0.046, pad=0.04) cb.set_ticks([]) -plt.savefig("../figures/tip-colorbar.pdf") +fig.savefig(ROOT_DIR / "figures/tip-colorbar.pdf") # plt.show() diff --git a/scripts/tip-dotted.py b/scripts/tip-dotted.py index ebfae99..8f52a2c 100644 --- a/scripts/tip-dotted.py +++ b/scripts/tip-dotted.py @@ -4,9 +4,15 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + + +ROOT_DIR = pathlib.Path(__file__).parent.parent + fig = plt.figure(figsize=(5, .25)) ax = fig.add_axes([0, 0, 1, 1], frameon=False, @@ -17,5 +23,5 @@ 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") +fig.savefig(ROOT_DIR / "figures/tip-dotted.pdf") # plt.show() diff --git a/scripts/tip-dual-axis.py b/scripts/tip-dual-axis.py index 74677eb..9d72f34 100644 --- a/scripts/tip-dual-axis.py +++ b/scripts/tip-dual-axis.py @@ -1,9 +1,14 @@ +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt -mpl.rcParams['axes.linewidth'] = 1.5 +ROOT_DIR = pathlib.Path(__file__).parent.parent + +mpl.rcParams['axes.linewidth'] = 1.5 + fig = plt.figure(figsize=(2, 2)) d = 0.01 ax1 = fig.add_axes([d, d, 1-2*d, 1-2*d], label="cartesian") @@ -21,5 +26,5 @@ ax2.set_xticklabels([]) ax2.set_yticklabels([]) -plt.savefig("../figures/tip-dual-axis.pdf") +fig.savefig(ROOT_DIR / "figures/tip-dual-axis.pdf") # plt.show() diff --git a/scripts/tip-font-family.py b/scripts/tip-font-family.py index 8689b3b..53564ac 100644 --- a/scripts/tip-font-family.py +++ b/scripts/tip-font-family.py @@ -3,13 +3,17 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as ticker -# Setup a plot such that only the bottom spine is shown +ROOT_DIR = pathlib.Path(__file__).parent.parent + +# 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') @@ -46,5 +50,5 @@ def setup(ax): tick.set_fontname("Roboto Condensed") plt.tight_layout() -plt.savefig("../figures/tip-font-family.pdf", transparent=True) +fig.savefig(ROOT_DIR / "figures/tip-font-family.pdf", transparent=True) # plt.show() diff --git a/scripts/tip-hatched.py b/scripts/tip-hatched.py index 56ac515..f1a38d4 100644 --- a/scripts/tip-hatched.py +++ b/scripts/tip-hatched.py @@ -1,6 +1,11 @@ +import pathlib + import numpy as np import matplotlib.pyplot as plt + +ROOT_DIR = pathlib.Path(__file__).parent.parent + cmap = plt.get_cmap("Oranges") color1, color2 = cmap(0.3), cmap(0.5) @@ -36,5 +41,5 @@ ax.spines['top'].set_visible(False) plt.tight_layout() -plt.savefig("../figures/tip-hatched.pdf") +fig.savefig(ROOT_DIR / "figures/tip-hatched.pdf") # plt.show() diff --git a/scripts/tip-multiline.py b/scripts/tip-multiline.py index 1b62b76..99d704c 100644 --- a/scripts/tip-multiline.py +++ b/scripts/tip-multiline.py @@ -2,9 +2,15 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + + +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.rcParams['axes.linewidth'] = 1.5 fig = plt.figure(figsize=(8, 1.5)) @@ -20,5 +26,5 @@ plt.xlim(-0.25, 10*np.pi+.25) plt.ylim(-1.5, 1.5) plt.tight_layout() -plt.savefig("../figures/tip-multiline.pdf", dpi=100) +fig.savefig(ROOT_DIR / "figures/tip-multiline.pdf", dpi=100) # plt.show() diff --git a/scripts/tip-outline.py b/scripts/tip-outline.py index e376149..6fe1a6f 100644 --- a/scripts/tip-outline.py +++ b/scripts/tip-outline.py @@ -4,11 +4,16 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import pathlib + 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 + fig = plt.figure(figsize=(2, 2)) mpl.rcParams['axes.linewidth'] = 1.5 d = 0.01 @@ -24,4 +29,4 @@ 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") +fig.savefig(ROOT_DIR / "figures/tip-outline.pdf") diff --git a/scripts/tip-post-processing.py b/scripts/tip-post-processing.py index 4086d03..3280efe 100644 --- a/scripts/tip-post-processing.py +++ b/scripts/tip-post-processing.py @@ -1,9 +1,14 @@ +import pathlib + import numpy as np import matplotlib.pyplot as plt from matplotlib.figure import Figure from matplotlib.backends.backend_agg import FigureCanvas from scipy.ndimage import gaussian_filter + +ROOT_DIR = pathlib.Path(__file__).parent.parent + # First pass for drop-shadow fig = Figure(figsize=(6, 1.5)) canvas = FigureCanvas(fig) @@ -23,5 +28,5 @@ ax.text(0.5, 0.5, "Matplotlib", transform=ax.transAxes, ha="center", va="center", size=64, color="black") -plt.savefig("../figures/tip-post-processing.pdf", dpi=600) +fig.savefig(ROOT_DIR / "figures/tip-post-processing.pdf", dpi=600) # plt.show() diff --git a/scripts/tip-transparency.py b/scripts/tip-transparency.py index 2d9abc6..320ea0c 100644 --- a/scripts/tip-transparency.py +++ b/scripts/tip-transparency.py @@ -2,9 +2,14 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.rc('axes', linewidth=1.5) np.random.seed(123) @@ -21,5 +26,5 @@ ax.set_xlim([-1, 1]), ax.set_xticks([]), ax.set_ylim([-1, 1]), ax.set_yticks([]) -plt.savefig("../figures/tip-transparency.pdf") +fig.savefig(ROOT_DIR / "figures/tip-transparency.pdf") # plt.show() From 987c8ce3fac808b411255e87611a4defb2223d31 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 30 Jan 2024 10:23:40 +0000 Subject: [PATCH 39/65] Bump pyshp version --- requirements/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 66fff0c..16d96e2 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -117,7 +117,7 @@ pyparsing==3.0.7 # packaging pyproj==3.6.1 # via cartopy -pyshp==2.2.0 +pyshp==2.3.1 # via cartopy python-dateutil==2.8.2 # via matplotlib From 60b4a6b47d77a5ba89c00d23d9ed4fa3b92f7686 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 30 Jan 2024 11:19:37 +0000 Subject: [PATCH 40/65] Bump Matplotlib to 3.6 --- .bumpversion.cfg | 2 +- Makefile | 2 +- cheatsheets.tex | 2 +- check-matplotlib-version.py | 2 +- handout-beginner.tex | 2 +- handout-intermediate.tex | 2 +- handout-tips.tex | 2 +- requirements/requirements.in | 2 +- requirements/requirements.txt | 12 +++++------- 9 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 46fdeb8..3b8f56d 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 3.5.0 +current_version = 3.6.3 [bumpversion:file:./check-matplotlib-version.py] search = __version__ == '{current_version}' diff --git a/Makefile b/Makefile index 4e0ef4c..a5b05d5 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ all: logos figures cheatsheets handouts docs .PHONY: logos logos: - wget https://github.com/matplotlib/matplotlib/raw/v3.5.0/doc/_static/logo2.png -O ./logos/logo2.png + wget https://github.com/matplotlib/matplotlib/raw/v3.6.3/doc/_static/logo2.png -O ./logos/logo2.png .PHONY: figures figures: diff --git a/cheatsheets.tex b/cheatsheets.tex index 3f34564..736fc53 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -264,7 +264,7 @@ \begin{multicols*}{5} \begin{overpic}[width=\columnwidth,tics=6,trim=12 6 18 6, clip]{logo2.png} \put (16.5,1.5) {\scriptsize\RobotoCon \textcolor[HTML]{11557c}{Cheat sheet}} - \put (80,1.5) {\tiny\Roboto \textcolor[HTML]{11557c}{Version 3.5.0}} + \put (80,1.5) {\tiny\Roboto \textcolor[HTML]{11557c}{Version 3.6.3}} \end{overpic} %\textbf{\Large \RobotoCon Matplotlib 3.2 cheat sheet}\\ %{\ttfamily https://matplotlib.org} \hfill CC-BY 4.0 diff --git a/check-matplotlib-version.py b/check-matplotlib-version.py index d8f88d3..aea9dea 100755 --- a/check-matplotlib-version.py +++ b/check-matplotlib-version.py @@ -2,4 +2,4 @@ import matplotlib as mpl -assert mpl.__version__ == '3.5.0' +assert mpl.__version__ == '3.6.3' diff --git a/handout-beginner.tex b/handout-beginner.tex index 1c9d32c..0459774 100644 --- a/handout-beginner.tex +++ b/handout-beginner.tex @@ -297,7 +297,7 @@ \subsection*{\rmfamily Save \mdseries (bitmap or vector format)} \vfill % {\scriptsize - Matplotlib 3.5.0 handout for beginners. + Matplotlib 3.6.3 handout for beginners. Copyright (c) 2021 Matplotlib Development Team. Released under a CC-BY 4.0 International License. Supported by NumFOCUS. diff --git a/handout-intermediate.tex b/handout-intermediate.tex index 7af7e8c..239c256 100644 --- a/handout-intermediate.tex +++ b/handout-intermediate.tex @@ -198,7 +198,7 @@ \subsection*{\rmfamily Size \& DPI} \vfill % {\scriptsize - Matplotlib 3.5.0 handout for intermediate users. + Matplotlib 3.6.3 handout for intermediate users. Copyright (c) 2021 Matplotlib Development Team. Released under a CC-BY 4.0 International License. Supported by NumFOCUS. diff --git a/handout-tips.tex b/handout-tips.tex index 40ea3f1..f523112 100644 --- a/handout-tips.tex +++ b/handout-tips.tex @@ -243,7 +243,7 @@ \subsection*{\rmfamily Read the documentation} \vfill % {\scriptsize - Matplotlib 3.5.0 handout for tips \& tricks. + Matplotlib 3.6.3 handout for tips \& tricks. Copyright (c) 2021 Matplotlib Development Team. Released under a CC-BY 4.0 International License. Supported by NumFOCUS. diff --git a/requirements/requirements.in b/requirements/requirements.in index 92f027c..3e9986f 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -2,7 +2,7 @@ autopep8 bump2version cartopy==0.22.0 flake8 -matplotlib==3.5.0 +matplotlib==3.6.3 mpl-sphinx-theme pillow>=9 pdfx diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 16d96e2..2b41346 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -34,6 +34,8 @@ charset-normalizer==2.0.12 # via requests click==8.0.4 # via pip-tools +contourpy==1.2.0 + # via matplotlib cryptography==36.0.1 # via pdfminer-six cycler==0.11.0 @@ -62,7 +64,7 @@ kiwisolver==1.3.2 # via matplotlib markupsafe==2.1.0 # via jinja2 -matplotlib==3.5.0 +matplotlib==3.6.3 # via # -r requirements.in # cartopy @@ -75,13 +77,13 @@ nodeenv==1.6.0 numpy==1.22.2 # via # cartopy + # contourpy # matplotlib # scipy packaging==21.3 # via # cartopy # matplotlib - # setuptools-scm # sphinx pdfminer-six==20201018 # via pdfx @@ -129,8 +131,6 @@ requests==2.27.1 # via sphinx scipy==1.8.0 # via -r requirements.in -setuptools-scm==6.4.2 - # via matplotlib shapely==1.8.1.post1 # via cartopy six==1.16.0 @@ -164,9 +164,7 @@ toml==0.10.2 # autopep8 # pre-commit tomli==2.0.1 - # via - # pep517 - # setuptools-scm + # via pep517 urllib3==1.26.8 # via requests virtualenv==20.13.1 From 9ddb500d79c810ffe2c6297f3569c0c0b68358d4 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 30 Jan 2024 11:30:18 +0000 Subject: [PATCH 41/65] Update seaborn pdf filenames --- cheatsheets.tex | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index 736fc53..a7400bd 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -682,19 +682,11 @@ \fbox{\includegraphics[width=.32\columnwidth]{style-classic.pdf}} \fbox{\includegraphics[width=.32\columnwidth]{style-grayscale.pdf}} \fbox{\includegraphics[width=.32\columnwidth]{style-ggplot.pdf}} - \fbox{\includegraphics[width=.32\columnwidth]{style-seaborn.pdf}} + \fbox{\includegraphics[width=.32\columnwidth]{style-seaborn-v0_8.pdf}} \fbox{\includegraphics[width=.32\columnwidth]{style-fast.pdf}} \fbox{\includegraphics[width=.32\columnwidth]{style-bmh.pdf}} \fbox{\includegraphics[width=.32\columnwidth]{style-Solarize_Light2.pdf}} - \fbox{\includegraphics[width=.32\columnwidth]{style-seaborn-notebook.pdf}} - %% \fbox{\includegraphics[width=.24\columnwidth]{style-default.pdf}} - %% \fbox{\includegraphics[width=.24\columnwidth]{style-classic.pdf}} - %% \fbox{\includegraphics[width=.24\columnwidth]{style-grayscale.pdf}} - %% \fbox{\includegraphics[width=.24\columnwidth]{style-ggplot.pdf}} - %% \fbox{\includegraphics[width=.24\columnwidth]{style-seaborn.pdf}} - %% \fbox{\includegraphics[width=.24\columnwidth]{style-fast.pdf}} - %% \fbox{\includegraphics[width=.24\columnwidth]{style-bmh.pdf}} - %% \fbox{\includegraphics[width=.24\columnwidth]{style-Solarize_Light2.pdf}} + \fbox{\includegraphics[width=.32\columnwidth]{style-seaborn-v0_8-notebook.pdf}} \end{myboxed} % \vspace{\fill} From 0190fa6bab9076e4af490b17f3c7a33b33048c67 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 28 Mar 2023 04:34:45 -0400 Subject: [PATCH 42/65] Bump to Matplotlib 3.7.1 And also Cartopy to latest version to make it installable on current versions of Python. --- .bumpversion.cfg | 2 +- Makefile | 2 +- cheatsheets.tex | 2 +- check-matplotlib-version.py | 2 +- docs/conf.py | 3 +- handout-beginner.tex | 2 +- handout-intermediate.tex | 2 +- handout-tips.tex | 2 +- requirements/requirements.in | 4 +- requirements/requirements.txt | 139 ++++++++++++++++++---------------- 10 files changed, 84 insertions(+), 76 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 3b8f56d..776285c 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 3.6.3 +current_version = 3.7.4 [bumpversion:file:./check-matplotlib-version.py] search = __version__ == '{current_version}' diff --git a/Makefile b/Makefile index a5b05d5..b7e8177 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ all: logos figures cheatsheets handouts docs .PHONY: logos logos: - wget https://github.com/matplotlib/matplotlib/raw/v3.6.3/doc/_static/logo2.png -O ./logos/logo2.png + wget https://github.com/matplotlib/matplotlib/raw/v3.7.4/doc/_static/logo2.png -O ./logos/logo2.png .PHONY: figures figures: diff --git a/cheatsheets.tex b/cheatsheets.tex index a7400bd..f7462c7 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -264,7 +264,7 @@ \begin{multicols*}{5} \begin{overpic}[width=\columnwidth,tics=6,trim=12 6 18 6, clip]{logo2.png} \put (16.5,1.5) {\scriptsize\RobotoCon \textcolor[HTML]{11557c}{Cheat sheet}} - \put (80,1.5) {\tiny\Roboto \textcolor[HTML]{11557c}{Version 3.6.3}} + \put (80,1.5) {\tiny\Roboto \textcolor[HTML]{11557c}{Version 3.7.4}} \end{overpic} %\textbf{\Large \RobotoCon Matplotlib 3.2 cheat sheet}\\ %{\ttfamily https://matplotlib.org} \hfill CC-BY 4.0 diff --git a/check-matplotlib-version.py b/check-matplotlib-version.py index aea9dea..18b903f 100755 --- a/check-matplotlib-version.py +++ b/check-matplotlib-version.py @@ -2,4 +2,4 @@ import matplotlib as mpl -assert mpl.__version__ == '3.6.3' +assert mpl.__version__ == '3.7.4' diff --git a/docs/conf.py b/docs/conf.py index cc15a6d..a1f9ab2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -31,8 +31,7 @@ html_theme = "mpl_sphinx_theme" html_favicon = "_static/favicon.ico" html_theme_options = { - "logo_link": "https://matplotlib.org/stable/", - "native_site": False, + "navbar_links": ("absolute", "server-stable"), } html_sidebars = { "**": [] diff --git a/handout-beginner.tex b/handout-beginner.tex index 0459774..da99d28 100644 --- a/handout-beginner.tex +++ b/handout-beginner.tex @@ -297,7 +297,7 @@ \subsection*{\rmfamily Save \mdseries (bitmap or vector format)} \vfill % {\scriptsize - Matplotlib 3.6.3 handout for beginners. + Matplotlib 3.7.4 handout for beginners. Copyright (c) 2021 Matplotlib Development Team. Released under a CC-BY 4.0 International License. Supported by NumFOCUS. diff --git a/handout-intermediate.tex b/handout-intermediate.tex index 239c256..7a6b679 100644 --- a/handout-intermediate.tex +++ b/handout-intermediate.tex @@ -198,7 +198,7 @@ \subsection*{\rmfamily Size \& DPI} \vfill % {\scriptsize - Matplotlib 3.6.3 handout for intermediate users. + Matplotlib 3.7.4 handout for intermediate users. Copyright (c) 2021 Matplotlib Development Team. Released under a CC-BY 4.0 International License. Supported by NumFOCUS. diff --git a/handout-tips.tex b/handout-tips.tex index f523112..3e5e261 100644 --- a/handout-tips.tex +++ b/handout-tips.tex @@ -243,7 +243,7 @@ \subsection*{\rmfamily Read the documentation} \vfill % {\scriptsize - Matplotlib 3.6.3 handout for tips \& tricks. + Matplotlib 3.7.4 handout for tips \& tricks. Copyright (c) 2021 Matplotlib Development Team. Released under a CC-BY 4.0 International License. Supported by NumFOCUS. diff --git a/requirements/requirements.in b/requirements/requirements.in index 3e9986f..f36a79f 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -2,8 +2,8 @@ autopep8 bump2version cartopy==0.22.0 flake8 -matplotlib==3.6.3 -mpl-sphinx-theme +matplotlib==3.7.4 +mpl-sphinx-theme~=3.7.1 pillow>=9 pdfx pip-tools diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 2b41346..ea4ee51 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -6,168 +6,177 @@ # --no-binary shapely -alabaster==0.7.12 +accessible-pygments==0.0.4 + # via pydata-sphinx-theme +alabaster==0.7.16 # via sphinx -autopep8==1.6.0 +autopep8==2.0.4 # via -r requirements.in -babel==2.9.1 - # via sphinx -beautifulsoup4==4.10.0 +babel==2.14.0 + # via + # pydata-sphinx-theme + # sphinx +beautifulsoup4==4.12.3 # via pydata-sphinx-theme +build==1.0.3 + # via pip-tools bump2version==1.0.1 # via -r requirements.in cartopy==0.22.0 # via -r requirements.in -certifi==2021.10.8 +certifi==2023.11.17 # via # pyproj # requests -cffi==1.15.0 +cffi==1.16.0 # via cryptography -cfgv==3.3.1 +cfgv==3.4.0 # via pre-commit chardet==4.0.0 # via # pdfminer-six # pdfx -charset-normalizer==2.0.12 +charset-normalizer==3.3.2 # via requests -click==8.0.4 +click==8.1.7 # via pip-tools contourpy==1.2.0 # via matplotlib -cryptography==36.0.1 +cryptography==42.0.2 # via pdfminer-six -cycler==0.11.0 +cycler==0.12.1 # via matplotlib -distlib==0.3.4 +distlib==0.3.8 # via virtualenv -docutils==0.17.1 +docutils==0.20.1 # via # pydata-sphinx-theme # sphinx -filelock==3.6.0 +filelock==3.13.1 # via virtualenv -flake8==4.0.1 +flake8==7.0.0 # via -r requirements.in -fonttools==4.29.1 +fonttools==4.47.2 # via matplotlib -identify==2.4.11 +identify==2.5.33 # via pre-commit -idna==3.3 +idna==3.6 # via requests -imagesize==1.3.0 +imagesize==1.4.1 # via sphinx -jinja2==3.0.3 +jinja2==3.1.3 # via sphinx -kiwisolver==1.3.2 +kiwisolver==1.4.5 # via matplotlib -markupsafe==2.1.0 +markupsafe==2.1.4 # via jinja2 -matplotlib==3.6.3 +matplotlib==3.7.4 # via # -r requirements.in # cartopy -mccabe==0.6.1 + # mpl-sphinx-theme +mccabe==0.7.0 # via flake8 -mpl-sphinx-theme==3.5.0 +mpl-sphinx-theme==3.7.1 # via -r requirements.in -nodeenv==1.6.0 +nodeenv==1.8.0 # via pre-commit -numpy==1.22.2 +numpy==1.26.3 # via # cartopy # contourpy # matplotlib # scipy -packaging==21.3 + # shapely +packaging==23.2 # via + # build # cartopy # matplotlib + # pydata-sphinx-theme # sphinx pdfminer-six==20201018 # via pdfx pdfx==1.4.1 # via -r requirements.in -pep517==0.12.0 - # via pip-tools -pillow==9.0.1 +pillow==10.2.0 # via # -r requirements.in # matplotlib -pip-tools==6.5.1 +pip-tools==7.3.0 # via -r requirements.in -platformdirs==2.5.1 +platformdirs==4.2.0 # via virtualenv -pre-commit==2.17.0 +pre-commit==3.6.0 # via -r requirements.in -pycodestyle==2.8.0 +pycodestyle==2.11.1 # via # autopep8 # flake8 pycparser==2.21 # via cffi -pydata-sphinx-theme==0.8.0 +pydata-sphinx-theme==0.15.2 # via mpl-sphinx-theme -pyflakes==2.4.0 +pyflakes==3.2.0 # via flake8 -pygments==2.11.2 - # via sphinx -pyparsing==3.0.7 +pygments==2.17.2 # via - # matplotlib - # packaging + # accessible-pygments + # pydata-sphinx-theme + # sphinx +pyparsing==3.1.1 + # via matplotlib pyproj==3.6.1 # via cartopy +pyproject-hooks==1.0.0 + # via build pyshp==2.3.1 # via cartopy python-dateutil==2.8.2 # via matplotlib -pytz==2021.3 - # via babel -pyyaml==6.0 +pyyaml==6.0.1 # via pre-commit -requests==2.27.1 +requests==2.31.0 # via sphinx -scipy==1.8.0 +scipy==1.12.0 # via -r requirements.in -shapely==1.8.1.post1 +shapely==2.0.2 # via cartopy six==1.16.0 - # via - # python-dateutil - # virtualenv + # via python-dateutil snowballstemmer==2.2.0 # via sphinx sortedcontainers==2.4.0 # via pdfminer-six -soupsieve==2.3.1 +soupsieve==2.5 # via beautifulsoup4 -sphinx==4.4.0 +sphinx==7.2.6 # via # -r requirements.in # pydata-sphinx-theme -sphinxcontrib-applehelp==1.0.2 +sphinxcontrib-applehelp==1.0.8 # via sphinx -sphinxcontrib-devhelp==1.0.2 +sphinxcontrib-devhelp==1.0.6 # via sphinx -sphinxcontrib-htmlhelp==2.0.0 +sphinxcontrib-htmlhelp==2.0.5 # via sphinx sphinxcontrib-jsmath==1.0.1 # via sphinx -sphinxcontrib-qthelp==1.0.3 +sphinxcontrib-qthelp==1.0.7 # via sphinx -sphinxcontrib-serializinghtml==1.1.5 +sphinxcontrib-serializinghtml==1.1.10 # via sphinx -toml==0.10.2 +tomli==2.0.1 # via # autopep8 - # pre-commit -tomli==2.0.1 - # via pep517 -urllib3==1.26.8 + # build + # pip-tools + # pyproject-hooks +typing-extensions==4.9.0 + # via pydata-sphinx-theme +urllib3==2.2.0 # via requests -virtualenv==20.13.1 +virtualenv==20.25.0 # via pre-commit wheel==0.42.0 # via pip-tools From 8e95ca73289a196964ffcb5d8e4d994b024600d4 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 6 Feb 2024 02:21:16 -0500 Subject: [PATCH 43/65] Allow binary shapely wheels A locally-compiled shapely was necessary for older Cartopy that compiled against the same libraries, but it's no longer doing that, so we can use binary Shapely again. --- .github/workflows/main.yaml | 2 -- requirements/requirements.in | 2 -- requirements/requirements.txt | 2 -- 3 files changed, 6 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 8c50ad0..be64b1d 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -22,8 +22,6 @@ jobs: sudo apt install \ fontconfig \ imagemagick \ - libgeos++-dev \ - libproj-dev \ poppler-utils python -m pip install --upgrade pip pip install -r requirements/requirements.txt diff --git a/requirements/requirements.in b/requirements/requirements.in index f36a79f..2f86e7a 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -10,5 +10,3 @@ pip-tools pre-commit scipy sphinx - ---no-binary shapely diff --git a/requirements/requirements.txt b/requirements/requirements.txt index ea4ee51..ce90c73 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -4,8 +4,6 @@ # # pip-compile requirements.in # ---no-binary shapely - accessible-pygments==0.0.4 # via pydata-sphinx-theme alabaster==0.7.16 From 982b0634ca33492294b3672f849bcfdb94615949 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 6 Feb 2024 03:08:01 -0500 Subject: [PATCH 44/65] Add spaces after commas wherever possible Only a couple don't fit, so try to combine things that are related in those cases. --- cheatsheets.tex | 56 ++++++++++++++++++++-------------------- handout-beginner.tex | 10 +++---- handout-intermediate.tex | 20 +++++++------- handout-tips.tex | 14 +++++----- 4 files changed, 50 insertions(+), 50 deletions(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index f7462c7..977de19 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -301,13 +301,13 @@ % --- Layout --------------------------------------------------------------- \begin{myboxed}{Subplots layout \hfill \API{https://matplotlib.org/tutorials/intermediate/gridspec.html} } - \plot{layout-subplot.pdf}{\textbf{subplot[s]}(rows,cols,…)} + \plot{layout-subplot.pdf}{\textbf{subplot[s]}(rows, cols, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html} {\ttfamily fig, axs = plt.subplots(3, 3)} {} - \plot{layout-gridspec.pdf}{G = \textbf{gridspec}(rows,cols,…)} + \plot{layout-gridspec.pdf}{G = \textbf{gridspec}(rows,cols, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.gridspec.GridSpec.html} - {\ttfamily ax = G[0,:]}{} + {\ttfamily ax = G[0, :]}{} \plot{layout-inset.pdf}{ax.\textbf{inset\_axes}(extent)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.inset_axes.html} {}{} @@ -338,7 +338,7 @@ % --- Basic plots ----------------------------------------------------------- \begin{myboxed}{Basic plots} - \plot{basic-plot.pdf}{\textbf{plot}([X],Y,[fmt],…)} + \plot{basic-plot.pdf}{\textbf{plot}([X], Y, [fmt], …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html} {\optional{X}, \mandatory{Y}, @@ -347,7 +347,7 @@ \optional{marker}, \optional{linestyle}} {} - \plot{basic-scatter.pdf}{\textbf{scatter}(X,Y,…)} + \plot{basic-scatter.pdf}{\textbf{scatter}(X, Y, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.scatter.html} {\mandatory{X}, \mandatory{Y}, @@ -356,7 +356,7 @@ \optional{marker}, \optional{cmap}} {} - \plot{basic-bar.pdf}{\textbf{bar[h]}(x,height,…)} + \plot{basic-bar.pdf}{\textbf{bar[h]}(x, height, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.bar.html} { \mandatory{x}, \mandatory{height}, @@ -364,7 +364,7 @@ \optional{bottom}, \optional{align}, \optional{color} }{} - \plot{basic-imshow.pdf}{\textbf{imshow}(Z,…)} + \plot{basic-imshow.pdf}{\textbf{imshow}(Z, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html} { \mandatory{Z}, \optional{cmap}, @@ -372,7 +372,7 @@ \optional{extent}, \optional{origin} } {} - \plot{basic-contour.pdf}{\textbf{contour[f]}([X],[Y],Z,…)} + \plot{basic-contour.pdf}{\textbf{contour[f]}([X], [Y], Z, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contour.html} { \optional{X}, \optional{Y}, @@ -382,7 +382,7 @@ \optional{extent}, \optional{origin} } {} - \plot{basic-pcolormesh.pdf}{\textbf{pcolormesh}([X],[Y],Z,…)} + \plot{basic-pcolormesh.pdf}{\textbf{pcolormesh}([X], [Y], Z, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pcolormesh.html} { \optional{X}, \optional{Y}, @@ -391,7 +391,7 @@ \optional{vmax}, \optional{cmap}} {} - \plot{basic-quiver.pdf}{\textbf{quiver}([X],[Y],U,V,…)} + \plot{basic-quiver.pdf}{\textbf{quiver}([X], [Y], U, V, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.quiver.html} { \optional{X}, \optional{Y}, @@ -401,7 +401,7 @@ \optional{units}, \optional{angles} } {} - \plot{basic-pie.pdf}{\textbf{pie}(X,…)} + \plot{basic-pie.pdf}{\textbf{pie}(X, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pie.html} {\mandatory{Z}, \optional{explode}, @@ -409,7 +409,7 @@ \optional{colors}, \optional{radius}} {} - \plot{basic-text.pdf}{\textbf{text}(x,y,text,…)} + \plot{basic-text.pdf}{\textbf{text}(x, y, text, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.text.html} {\mandatory{x}, \mandatory{y}, @@ -432,7 +432,7 @@ \vspace{\fill} % --- Advanced plots -------------------------------------------------------- \begin{myboxed}{Advanced plots} - \plot{advanced-step.pdf}{\textbf{step}(X,Y,[fmt],…)} + \plot{advanced-step.pdf}{\textbf{step}(X, Y, [fmt], …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.step.html} {\mandatory{X}, \mandatory{Y}, @@ -441,7 +441,7 @@ \optional{marker}, \optional{where} } {} - \plot{advanced-boxplot.pdf}{\textbf{boxplot}(X,…)} + \plot{advanced-boxplot.pdf}{\textbf{boxplot}(X, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.boxplot.html} { \mandatory{X}, \optional{notch}, @@ -449,7 +449,7 @@ \optional{bootstrap}, \optional{widths} } {} - \plot{advanced-errorbar.pdf}{\textbf{errorbar}(X,Y,xerr,yerr,…)} + \plot{advanced-errorbar.pdf}{\textbf{errorbar}(X,Y,xerr,yerr, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.errorbar.html} { \mandatory{X}, \mandatory{Y}, @@ -465,14 +465,14 @@ \optional{density}, \optional{weights}} {} - \plot{advanced-violin.pdf}{\textbf{violinplot}(D,…)} + \plot{advanced-violin.pdf}{\textbf{violinplot}(D, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.violinplot.html} {\mandatory{D}, \optional{positions}, \optional{widths}, \optional{vert} } {} - \plot{advanced-barbs.pdf}{\textbf{barbs}([X],[Y], U, V, …)} + \plot{advanced-barbs.pdf}{\textbf{barbs}([X], [Y], U, V, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.barbs.html} { \optional{X}, \optional{Y}, @@ -483,13 +483,13 @@ \optional{pivot}, \optional{sizes} } {} - \plot{advanced-event.pdf}{\textbf{eventplot}(positions,…)} + \plot{advanced-event.pdf}{\textbf{eventplot}(positions, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.eventplot.html} {\mandatory{positions}, \optional{orientation}, \optional{lineoffsets} } {} - \plot{advanced-hexbin.pdf}{\textbf{hexbin}(X,Y,C,…)} + \plot{advanced-hexbin.pdf}{\textbf{hexbin}(X, Y, C, …)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hexbin.html} {\mandatory{X}, \mandatory{Y}, @@ -503,7 +503,7 @@ % --- Scale --------------------------------------------------------------- \begin{myboxed}{Scales \hfill \API{https://matplotlib.org/stable/api/scale_api.html}} - {\ttfamily ax.\textbf{set\_[xy]scale}(scale,…)} + {\ttfamily ax.\textbf{set\_[xy]scale}(scale, …)} \smallskip \scale{scale-linear.pdf}{\textbf{linear}}{any values} \scale{scale-log.pdf}{\textbf{log}}{values > 0} @@ -516,7 +516,7 @@ % --- Projections ----------------------------------------------------------- \begin{myboxed}{Projections \hfill \API{https://matplotlib.org/stable/api/projections_api.html}} - {\ttfamily \textbf{subplot}(…,projection=p)} + {\ttfamily \textbf{subplot}(…, projection=p)} \smallskip \scale{projection-polar.pdf}{p='polar'}{} \scale{projection-3d.pdf} @@ -906,7 +906,7 @@ \begin{myboxed}{Legend placement} \includegraphics[width=\columnwidth]{legend-placement.pdf} - ax.\textbf{legend}(loc="string", bbox\_to\_anchor=(x,y))\\ + ax.\textbf{legend}(loc="string", bbox\_to\_anchor=(x, y))\\ \begin{tabular}{@{}p{0.33\columnwidth} p{0.33\columnwidth} p{0.33\columnwidth}@{}} @@ -919,12 +919,12 @@ \begin{tabular}{@{}p{0.495\columnwidth} p{0.495\columnwidth}@{}} \scriptsize \rule{0pt}{1.25em}\noindent - \tiny A: upper right / {\ttfamily (-0.1,0.9)} & \tiny B: center right / {\ttfamily (-0.1,0.5)}\\ - \tiny C: lower right / {\ttfamily (-0.1,0.1)} & \tiny D: upper left / {\ttfamily (0.1,-0.1)}\\ - \tiny E: upper center / {\ttfamily (0.5,-0.1)} & \tiny F: upper right / {\ttfamily (0.9,-0.1)}\\ - \tiny G: lower left / {\ttfamily (1.1,0.1)} & \tiny H: center left / {\ttfamily (1.1,0.5)}\\ - \tiny I: upper left / {\ttfamily (1.1,0.9)} & \tiny J: lower right / {\ttfamily (0.9,1.1)}\\ - \tiny K: lower center / {\ttfamily (0.5,1.1)} & \tiny L: lower left / {\ttfamily (0.1,1.1)} + \tiny A: upper right / {\ttfamily (-0.1, 0.9)} & \tiny B: center right / {\ttfamily (-0.1, 0.5)}\\ + \tiny C: lower right / {\ttfamily (-0.1, 0.1)} & \tiny D: upper left / {\ttfamily (0.1, -0.1)}\\ + \tiny E: upper center / {\ttfamily (0.5, -0.1)} & \tiny F: upper right / {\ttfamily (0.9, -0.1)}\\ + \tiny G: lower left / {\ttfamily (1.1, 0.1)} & \tiny H: center left / {\ttfamily (1.1, 0.5)}\\ + \tiny I: upper left / {\ttfamily (1.1, 0.9)} & \tiny J: lower right / {\ttfamily (0.9, 1.1)}\\ + \tiny K: lower center / {\ttfamily (0.5, 1.1)} & \tiny L: lower left / {\ttfamily (0.1, 1.1)} \end{tabular} \end{myboxed} % diff --git a/handout-beginner.tex b/handout-beginner.tex index da99d28..1d5b11a 100644 --- a/handout-beginner.tex +++ b/handout-beginner.tex @@ -123,7 +123,7 @@ \subsection*{\rmfamily Choose} % ----------------------------------------------------------------------------- \begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}} \begin{lstlisting}[belowskip=-\baselineskip] - Z = np.random.uniform(0, 1, (8,8)) + Z = np.random.uniform(0, 1, (8, 8)) ax.imshow(Z) \end{lstlisting} @@ -132,7 +132,7 @@ \subsection*{\rmfamily Choose} % ----------------------------------------------------------------------------- \begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}} \begin{lstlisting}[belowskip=-\baselineskip] - Z = np.random.uniform(0, 1, (8,8)) + Z = np.random.uniform(0, 1, (8, 8)) ax.contourf(Z) \end{lstlisting} @@ -168,7 +168,7 @@ \subsection*{\rmfamily Choose} % ----------------------------------------------------------------------------- \begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}} \begin{lstlisting}[belowskip=-\baselineskip] - Z = np.random.normal(0, 1, (100,3)) + Z = np.random.normal(0, 1, (100, 3)) ax.boxplot(Z) \end{lstlisting} @@ -240,7 +240,7 @@ \subsection*{\rmfamily Organize} % ----------------------------------------------------------------------------- \begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}} \begin{lstlisting}[belowskip=-\baselineskip] - fig, (ax1, ax2) = plt.subplots(2,1) + fig, (ax1, ax2) = plt.subplots(2, 1) ax1.plot(X, Y1, color="C1") ax2.plot(X, Y2, color="C0") \end{lstlisting} @@ -249,7 +249,7 @@ \subsection*{\rmfamily Organize} % ----------------------------------------------------------------------------- \begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}} \begin{lstlisting}[belowskip=-\baselineskip] - fig, (ax1, ax2) = plt.subplots(1,2) + fig, (ax1, ax2) = plt.subplots(1, 2) ax1.plot(Y1, X, color="C1") ax2.plot(Y2, X, color="C0") \end{lstlisting} diff --git a/handout-intermediate.tex b/handout-intermediate.tex index 7a6b679..9deff8e 100644 --- a/handout-intermediate.tex +++ b/handout-intermediate.tex @@ -83,9 +83,9 @@ \subsection*{\rmfamily Figure, axes \& spines} % ----------------------------------------------------------------------------- \begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}} \begin{lstlisting}[belowskip=-\baselineskip] - fig, axs = plt.subplots(3,3) - axs[0,0].set_facecolor("#ddddff") - axs[2,2].set_facecolor("#ffffdd") + fig, axs = plt.subplots(3, 3) + axs[0, 0].set_facecolor("#ddddff") + axs[2, 2].set_facecolor("#ffffdd") \end{lstlisting} & \raisebox{-0.75em}{\includegraphics[width=\linewidth]{layout-subplot-color.pdf}} \end{tabular} @@ -146,7 +146,7 @@ \subsection*{\rmfamily Scales \& projections} \subsection*{\rmfamily Text \& ornaments} \begin{lstlisting}[] - ax.fill_betweenx([-1,1],[0],[2*np.pi]) + ax.fill_betweenx([-1, 1], [0], [2*np.pi]) ax.text(0, -1, r" Period $\Phi$") \end{lstlisting} \includegraphics[width=\linewidth]{sine-period.pdf} @@ -157,17 +157,17 @@ \subsection*{\rmfamily Legend} \begin{lstlisting}[] ax.plot(X, np.sin(X), "C0", label="Sine") ax.plot(X, np.cos(X), "C1", label="Cosine") - ax.legend(bbox_to_anchor=(0,1,1,.1),ncol=2, - mode="expand", loc="lower left") + ax.legend(bbox_to_anchor=(0,1,1,.1), ncol=2, + mode="expand", loc="lower left") \end{lstlisting} \includegraphics[width=\linewidth]{sine-legend.pdf} % ----------------------------------------------------------------------------- \subsection*{\rmfamily Annotation} \begin{lstlisting}[] - ax.annotate("A", (X[250],Y[250]),(X[250],-1), - ha="center", va="center",arrowprops = - {"arrowstyle" : "->", "color": "C1"}) + ax.annotate("A", (X[250],Y[250]), (X[250],-1), + ha="center", va="center", arrowprops={ + "arrowstyle": "->", "color": "C1"}) \end{lstlisting} \includegraphics[width=\linewidth]{sine-annotate.pdf} @@ -190,7 +190,7 @@ \subsection*{\rmfamily Size \& DPI} a figure is (21 - 2*2 - 1)/2 = 8cm. One inch being 2.54cm, figure size should be 3.15$\times$3.15 in. \begin{lstlisting}[] - fig = plt.figure(figsize=(3.15,3.15), dpi=50) + fig = plt.figure(figsize=(3.15, 3.15), dpi=50) plt.savefig("figure.pdf", dpi=600) \end{lstlisting} diff --git a/handout-tips.tex b/handout-tips.tex index 3e5e261..5e4d0a9 100644 --- a/handout-tips.tex +++ b/handout-tips.tex @@ -168,10 +168,10 @@ \subsection*{\rmfamily Dotted lines} To have rounded dotted lines, use a custom {\ttfamily linestyle} and modify {\ttfamily dash\_capstyle}. \begin{lstlisting} - ax.plot([0,1], [0,0], "C1", - linestyle = (0, (0.01, 1)), dash_capstyle="round") - ax.plot([0,1], [1,1], "C1", - linestyle = (0, (0.01, 2)), dash_capstyle="round") + ax.plot([0, 1], [0, 0], "C1", + linestyle=(0, (0.01, 1)), dash_capstyle="round") + ax.plot([0, 1], [1, 1], "C1", + linestyle=(0, (0.01, 2)), dash_capstyle="round") \end{lstlisting} \includegraphics[width=\linewidth]{tip-dotted.pdf} @@ -181,9 +181,9 @@ \subsection*{\rmfamily Combining axes} \begin{tabular}{@{}m{.774\linewidth}m{.216\linewidth}} \begin{lstlisting}[belowskip=-\baselineskip] - ax1 = fig.add_axes([0,0,1,1], + ax1 = fig.add_axes([0, 0, 1, 1], label="cartesian") - ax2 = fig.add_axes([0,0,1,1], + ax2 = fig.add_axes([0, 0, 1, 1], label="polar", projection="polar") \end{lstlisting} & @@ -227,7 +227,7 @@ \subsection*{\rmfamily Hatching} cmap = plt.get_cmap("Oranges") plt.rcParams['hatch.color'] = cmap(0.2) plt.rcParams['hatch.linewidth'] = 8 - ax.bar(X, Y, color=cmap(0.6), hatch="/" ) + ax.bar(X, Y, color=cmap(0.6), hatch="/") \end{lstlisting} & \raisebox{-0.75em}{\includegraphics[width=\linewidth]{tip-hatched.pdf}} \end{tabular} From d5bdedd793917d90305495dc0348301ade22c3a1 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 6 Feb 2024 03:15:00 -0500 Subject: [PATCH 45/65] Fix typos in sine plots - Use `C1` instead of `orange` to match other plots. - Remove extra plot in `sine-logscale.pdf`, which causes a bit of artifacting around the line. - Ensure text matches what is actually plotted for `markevery` settings; note I divided by 10 so that the text would fit in the block. Fixes #133 --- handout-beginner.tex | 2 +- handout-intermediate.tex | 4 ++-- scripts/sine.py | 26 ++++++++++++++++---------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/handout-beginner.tex b/handout-beginner.tex index 1d5b11a..30a106a 100644 --- a/handout-beginner.tex +++ b/handout-beginner.tex @@ -83,7 +83,7 @@ \section*{\LARGE \rmfamily % \fbox{2} \textbf{Prepare} \begin{lstlisting} - X = np.linspace(0, 4*np.pi, 1000) + X = np.linspace(0, 10*np.pi, 1000) Y = np.sin(X) \end{lstlisting} % diff --git a/handout-intermediate.tex b/handout-intermediate.tex index 9deff8e..0efd05d 100644 --- a/handout-intermediate.tex +++ b/handout-intermediate.tex @@ -130,7 +130,7 @@ \subsection*{\rmfamily Lines \& markers} \begin{lstlisting} X = np.linspace(0.1, 10*np.pi, 1000) Y = np.sin(X) - ax.plot(X, Y, "C1o:", markevery=25, mec="1.0") + ax.plot(X, Y, "C1o:", markevery=50, mec="1.0") \end{lstlisting} \includegraphics[width=\linewidth]{sine-marker.pdf} @@ -140,7 +140,7 @@ \subsection*{\rmfamily Scales \& projections} \begin{lstlisting} fig, ax = plt.subplots() ax.set_xscale("log") - ax.plot(X, Y, "C1o-", markevery=25, mec="1.0") + ax.plot(X, Y, "C1o-", markevery=50, mec="1.0") \end{lstlisting} \includegraphics[width=\linewidth]{sine-logscale.pdf} diff --git a/scripts/sine.py b/scripts/sine.py index 0e6a347..6307629 100644 --- a/scripts/sine.py +++ b/scripts/sine.py @@ -16,28 +16,34 @@ ROOT_DIR / 'styles/sine-plot.mplstyle', ]) -X = np.linspace(0.1, 10*np.pi, 10000) +X = np.linspace(0, 10*np.pi, 1000) Y = np.sin(X) -(fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.2/2.54)) + +fig, ax = plt.subplots(figsize=(5.7/2.54, 1.2/2.54)) ax.set_yticks(np.linspace(-1, 1, 5)) -ax.plot(X, Y, color="orange") +ax.plot(X, Y, color="C1") fig.savefig(ROOT_DIR / "figures/sine.pdf") -(fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) -ax.plot(X, Y, "C1o:", markevery=500, mec="1.0") + +X = np.linspace(0.1, 10*np.pi, 1000) +Y = np.sin(X) + + +fig, ax = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) +ax.plot(X, Y, "C1o:", markevery=50, mec="1.0") ax.set_ylim(-1.5, 1.5) fig.savefig(ROOT_DIR / "figures/sine-marker.pdf") + fig, ax = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) ax.set_xscale("log") -ax.plot(X, Y, "-") -ax.plot(X, Y, "C1o-", markevery=500, mec="1.0") +ax.plot(X, Y, "C1o-", markevery=50, mec="1.0") ax.set_ylim(-1.5, 1.5) fig.savefig(ROOT_DIR / "figures/sine-logscale.pdf") -(fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) +fig, ax = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) ax.plot(X, Y, "C1") ax.fill_betweenx([-1.5, 1.5], [0], [2*np.pi], color=".9") ax.text(0, -1, r" Period $\Phi$", va="top") @@ -45,7 +51,7 @@ fig.savefig(ROOT_DIR / "figures/sine-period.pdf") -(fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) +fig, ax = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) ax.plot(X, np.sin(X), "C0", label="Sine") ax.plot(X, np.cos(X), "C1", label="Cosine") ax.legend(bbox_to_anchor=(0.0, .9, 1.02, 0.1), @@ -56,7 +62,7 @@ fig.savefig(ROOT_DIR / "figures/sine-legend.pdf") -(fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) +fig, ax = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) X = np.linspace(0, 10*np.pi, 1000) Y = np.sin(X) ax.plot(X, Y, "C1o-", markevery=50, mec="1.0") From 1b461e7e36b5e4ab2e3203612b92339cba5cd0f5 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 6 Feb 2024 05:02:37 -0500 Subject: [PATCH 46/65] Fix typos in tips I'm not sure what the tip in Performance section is supposed to do, but the slow part plots nothing, and the fast part doesn't run. --- cheatsheets.tex | 8 ++++---- handout-beginner.tex | 4 ++-- handout-intermediate.tex | 8 ++++---- handout-tips.tex | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index 977de19..2b5ccfe 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -1000,12 +1000,12 @@ plot(X, Y, marker="o", ls="") \hfill fast% \vskip.5\baselineskip % - \textcolor{red}{for i in range(n): plot(X[i]) \hfill slow}\\ - plot(sum([x+[None] for x in X],[])) \hfill fast% + \textcolor{red}{for i in range(n): plot(i, X[i], "o") \hfill slow}\\ + plot(X, marker="o", ls="") \hfill fast% \vskip.5\baselineskip % - \textcolor{red}{cla(), imshow(…), canvas.draw() \hfill slow}\\ - im.set\_data(…), canvas.draw() \hfill fast% + \textcolor{red}{cla(); imshow(…); canvas.draw() \hfill slow}\\ + im.set\_data(…); canvas.draw() \hfill fast% \vskip.1\baselineskip } \end{myboxed} diff --git a/handout-beginner.tex b/handout-beginner.tex index 30a106a..37b0e05 100644 --- a/handout-beginner.tex +++ b/handout-beginner.tex @@ -225,8 +225,8 @@ \subsection*{\rmfamily Tweak} \subsection*{\rmfamily Organize} % ----------------------------------------------------------------------------- -You can plot several data on the the same figure, but you can also -split a figure in several subplots (named {\em Axes}): \medskip +You can plot several data on the same figure, but you can also split a figure +in several subplots (named {\em Axes}): \medskip % ----------------------------------------------------------------------------- \begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}} diff --git a/handout-intermediate.tex b/handout-intermediate.tex index 0efd05d..16f85f5 100644 --- a/handout-intermediate.tex +++ b/handout-intermediate.tex @@ -185,10 +185,10 @@ \subsection*{\rmfamily Colors} \vspace{-1em} \subsection*{\rmfamily Size \& DPI} -Consider a square figure to be included in a two-columns A4 paper with -2cm margins on each side and a column separation of 1cm. The width of -a figure is (21 - 2*2 - 1)/2 = 8cm. One inch being 2.54cm, figure size -should be 3.15$\times$3.15 in. +Consider a square figure to be included in a two-column A4 paper with +2\,cm margins on each side and a column separation of 1\,cm. The width of +a figure is (21 - 2*2 - 1)/2 = 8\,cm. One inch being 2.54\,cm, figure size +should be 3.15$\times$3.15\,in. \begin{lstlisting}[] fig = plt.figure(figsize=(3.15, 3.15), dpi=50) plt.savefig("figure.pdf", dpi=600) diff --git a/handout-tips.tex b/handout-tips.tex index 5e4d0a9..a6f7dd4 100644 --- a/handout-tips.tex +++ b/handout-tips.tex @@ -153,7 +153,7 @@ \subsection*{\rmfamily Text outline} % ----------------------------------------------------------------------------- \subsection*{\rmfamily Multiline plot} -You can plot several lines at once using None as separator. +You can plot several lines at once using {\em None} as separator. \begin{lstlisting} X,Y = [], [] From 82a1f802d198dc2218c1da032639e077cf34f858 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 24 Jan 2024 11:42:48 +0000 Subject: [PATCH 47/65] Bump version of pydata-sphinx-theme --- requirements/requirements.in | 4 +++- requirements/requirements.txt | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/requirements/requirements.in b/requirements/requirements.in index 2f86e7a..e792140 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -3,10 +3,12 @@ bump2version cartopy==0.22.0 flake8 matplotlib==3.7.4 -mpl-sphinx-theme~=3.7.1 pillow>=9 pdfx pip-tools pre-commit scipy +# Docs +mpl-sphinx-theme==3.8.0 +pydata-sphinx-theme==0.13.3 sphinx diff --git a/requirements/requirements.txt b/requirements/requirements.txt index ce90c73..acee927 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -75,7 +75,7 @@ matplotlib==3.7.4 # mpl-sphinx-theme mccabe==0.7.0 # via flake8 -mpl-sphinx-theme==3.7.1 +mpl-sphinx-theme==3.8.0 # via -r requirements.in nodeenv==1.8.0 # via pre-commit @@ -113,8 +113,10 @@ pycodestyle==2.11.1 # flake8 pycparser==2.21 # via cffi -pydata-sphinx-theme==0.15.2 - # via mpl-sphinx-theme +pydata-sphinx-theme==0.13.3 + # via + # -r requirements.in + # mpl-sphinx-theme pyflakes==3.2.0 # via flake8 pygments==2.17.2 From 15b1482fdc5a12eeaa506f28837e1a0c334e0eea Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 24 Jan 2024 12:42:44 +0000 Subject: [PATCH 48/65] Use sphinx-design for columns --- docs/conf.py | 2 +- docs/index.rst | 64 ++++++++++++++++------------------- requirements/requirements.in | 3 +- requirements/requirements.txt | 3 ++ 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index a1f9ab2..6a558b0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,7 +14,7 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = [] +extensions = ["sphinx_design"] # Add any paths that contain templates here, relative to this directory. diff --git a/docs/index.rst b/docs/index.rst index b9993ca..b5e442f 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -7,23 +7,21 @@ Matplotlib cheatsheets and handouts Cheatsheets *********** -.. container:: twocol +.. grid:: 2 - .. container:: + .. grid-item:: - .. image:: ../cheatsheets-1.png - :width: 270px - :align: center - :alt: image of first page of cheatsheets + .. image:: ../cheatsheets-1.png + :width: 270px + :align: center + :alt: image of first page of cheatsheets + .. grid-item:: - .. container:: - - .. image:: ../cheatsheets-2.png - :width: 270px - :align: center - :alt: image of second page of cheatsheets - + .. image:: ../cheatsheets-2.png + :width: 270px + :align: center + :alt: image of second page of cheatsheets `Cheatsheets [pdf] <./cheatsheets.pdf>`_ @@ -32,36 +30,34 @@ Cheatsheets Handouts ******** -.. container:: twocol - - .. container:: - - .. image:: ../handout-beginner.png - :width: 270px - :align: center - :alt: image of beginner handout +.. grid:: 3 - `Beginner [pdf] <./handout-beginner.pdf>`_ + .. grid-item:: + .. image:: ../handout-beginner.png + :width: 270px + :align: center + :alt: image of beginner handout - .. container:: + `Beginner [pdf] <./handout-beginner.pdf>`_ - .. image:: ../handout-intermediate.png - :width: 270px - :align: center - :alt: image of intermediate handout + .. grid-item:: - `Intermediate [pdf] <./handout-intermediate.pdf>`_ + .. image:: ../handout-intermediate.png + :width: 270px + :align: center + :alt: image of intermediate handout + `Intermediate [pdf] <./handout-intermediate.pdf>`_ - .. container:: + .. grid-item:: - .. image:: ../handout-tips.png - :width: 270px - :align: center - :alt: image of tips handout + .. image:: ../handout-tips.png + :width: 270px + :align: center + :alt: image of tips handout - `Tips [pdf] <./handout-tips.pdf>`_ + `Tips [pdf] <./handout-tips.pdf>`_ Contribute ********** diff --git a/requirements/requirements.in b/requirements/requirements.in index e792140..4c5f41f 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -9,6 +9,7 @@ pip-tools pre-commit scipy # Docs -mpl-sphinx-theme==3.8.0 +mpl-sphinx-theme~=3.8 pydata-sphinx-theme==0.13.3 sphinx +sphinx-design diff --git a/requirements/requirements.txt b/requirements/requirements.txt index acee927..1b00994 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -154,6 +154,9 @@ sphinx==7.2.6 # via # -r requirements.in # pydata-sphinx-theme + # sphinx-design +sphinx-design==0.5.0 + # via -r requirements.in sphinxcontrib-applehelp==1.0.8 # via sphinx sphinxcontrib-devhelp==1.0.6 From 405f125fc9ee55973361d36b2f299f9b891d4151 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Mon, 12 Feb 2024 09:57:54 +0000 Subject: [PATCH 49/65] Allow resizing of grid Co-authored-by: Elliott Sales de Andrade --- docs/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index b5e442f..1024ddd 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -30,7 +30,7 @@ Cheatsheets Handouts ******** -.. grid:: 3 +.. grid:: 1 2 3 3 .. grid-item:: From 746eff2b629f7fc99c112c8776fbafe053ff36c5 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 13 Feb 2024 09:03:51 +0000 Subject: [PATCH 50/65] Fix mpl-sphinx-theme pinning Co-authored-by: Elliott Sales de Andrade --- requirements/requirements.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/requirements.in b/requirements/requirements.in index 4c5f41f..bf5cc75 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -9,7 +9,7 @@ pip-tools pre-commit scipy # Docs -mpl-sphinx-theme~=3.8 +mpl-sphinx-theme~=3.8.0 pydata-sphinx-theme==0.13.3 sphinx sphinx-design From 8551a497641c12e8b4fcf05fcaad25eeb644149f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 29 Mar 2023 00:11:26 -0400 Subject: [PATCH 51/65] Simplify getting colormap sizes All the special cases other than Greys are just the size of the colormap themselves, but we want to drop that special case as well. Also, colormaps are at most 256 elements long, so using `n=512` is probably not necessary. --- scripts/colormaps.py | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/scripts/colormaps.py b/scripts/colormaps.py index 8858299..1ccdea8 100644 --- a/scripts/colormaps.py +++ b/scripts/colormaps.py @@ -35,36 +35,14 @@ 'terrain', 'ocean', 'gist_earth', 'cubehelix', 'rainbow' ) -for cmap in cmaps: - n = 512 +for name in cmaps: + # The maximum number of segments in a cmap is 256, and for anything smaller, + # the cmap will map as a suitably discrete set of colours. + Z = np.linspace(0, 1, 256).reshape(1, 256) - if cmap in ['tab10']: n = 10 - if cmap in ['tab20', 'tab20b', 'tab20c']: n = 20 - if cmap in ['Pastel1', 'Set1']: n = 9 - 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) - - ax.imshow(Z, extent=[xmin, xmax, ymin, ymax], cmap=plt.get_cmap(cmap)) + ax.imshow(Z, extent=[xmin, xmax, ymin, ymax], cmap=name) ax.set_xlim(xmin, xmax), ax.set_xticks([]) ax.set_ylim(ymin, ymax), ax.set_yticks([]) - """ - if cmap == "tab10": - x = np.linspace(xmin, xmax, 11, endpoint=True) + 0.5*(xmax-xmin)/11 - for i in range(10): - ax.text(x[i], (ymin+ymax)/2, "C%d"%i, color="white", zorder=10, - family = "Source Pro Serif", size=10, ha="center", va="center") - - if cmap == "Greys": - x = np.linspace(xmin, xmax, 12, endpoint=True) + 0.5*(xmax-xmin)/12 - for i in range(11): - color = "%.1f"%(i/10) - text = "%.1f"%(1-i/10) - ax.text(x[i], (ymin+ymax)/2, text, color=color, zorder=10, - family = "Source Pro Serif", size=10, ha="center", va="center") - """ - - fig.savefig(ROOT_DIR / f"figures/colormap-{cmap}.pdf") + fig.savefig(ROOT_DIR / f"figures/colormap-{name}.pdf") ax.clear() From 61c26ab1b4f09dfa008f1e040e3a773b5e855554 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 6 Feb 2024 01:36:15 -0500 Subject: [PATCH 52/65] Use luminance to choose text colour over colour cycles This uses the same algorithm as the [Specifying colors tutorial](https://matplotlib.org/stable/users/explain/colors/colors.html#comparison-between-x11-css4-and-xkcd-colors). --- scripts/colors.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/scripts/colors.py b/scripts/colors.py index 1bd76f8..c72d1d9 100644 --- a/scripts/colors.py +++ b/scripts/colors.py @@ -33,12 +33,19 @@ for name, colors in palettes.items(): C = mpl.colors.to_rgba_array(colors).reshape((1, len(colors), 4)) ax.imshow(C, extent=[xmin, xmax, ymin, ymax]) + + # Drop alpha by assuming we're on a white background PDF. + alpha = C[0, :, 3] + rgb = C[0, :, :3] * alpha[:, np.newaxis] + (1 - alpha[:, np.newaxis]) + # Same calculation for luminance as + # https://matplotlib.org/stable/users/explain/colors/colors.html#comparison-between-x11-css4-and-xkcd-colors + luma = 0.299 * rgb[:, 0] + 0.587 * rgb[:, 1] + 0.114 * rgb[:, 2] + dx = (xmax-xmin)/len(colors) for i in range(len(colors)): - color = "white" - if colors[i] in ['1.0', 'w']: color = "black" + text_color = "black" if luma[i] > 0.5 else "white" text = str(colors[i]).replace(' ', '') - ax.text((i+0.5)*dx, (ymin+ymax)/2, text, color=color, zorder=10, + ax.text((i+0.5)*dx, (ymin+ymax)/2, text, color=text_color, zorder=10, family="Source Code Pro", size=9, ha="center", va="center") fig.savefig(ROOT_DIR / f"figures/colors-{name}.pdf") From a5c2769f61eae9849cfe5dcc68e181e91781c9ff Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 15 Feb 2024 15:59:02 -0500 Subject: [PATCH 53/65] Simplify link checker ... and debug a bit. --- Makefile | 2 +- check-links.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b7e8177..1b7fbd1 100644 --- a/Makefile +++ b/Makefile @@ -50,8 +50,8 @@ check: ./check-num-pages.sh handout-tips.pdf 1 ./check-num-pages.sh handout-beginner.pdf 1 ./check-num-pages.sh handout-intermediate.pdf 1 - ./check-links.py cheatsheets.pdf ./check-diffs.py + ./check-links.py cheatsheets.pdf .PHONY: docs docs: diff --git a/check-links.py b/check-links.py index 3a3e797..aa6f449 100755 --- a/check-links.py +++ b/check-links.py @@ -8,12 +8,12 @@ refs = [ref for ref in pdf.get_references() if ref.reftype == 'url'] -status_codes = list(map(lambda ref: pdfx.downloader.get_status_code(ref.ref), refs)) +status_codes = [pdfx.downloader.get_status_code(ref.ref) for ref in refs] -broken_links = [refs[idx].ref for idx in range(len(refs)) if status_codes[idx] != 200] +broken_links = [(ref.ref, code) for ref, code in zip(refs, status_codes) if code != 200] # it seems that Twitter does not respond well to the link checker and throws a 400 -if all(['twitter.com' in url for url in broken_links]): +if all(['twitter.com' in url for url, _ in broken_links]): sys.exit(0) else: print('Broken links:', broken_links) From 170eb4a1e412a6fc8599d76adc2870105a5618a3 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Mon, 4 Mar 2024 20:19:11 +0000 Subject: [PATCH 54/65] Fix broken link --- cheatsheets.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index 2b5ccfe..1bc2079 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -1019,7 +1019,7 @@ \href{https://yt-project.org/doc/index.html}{\textbf{yt}}: Volumetric data visualization\\ \href{https://mpld3.github.io}{\textbf{mpld3}}: Bringing Matplotlib to the browser\\ \href{https://datashader.org/}{\textbf{Datashader}}: Large data processing pipeline\\ - \href{https://plotnine.readthedocs.io/en/latest/}{\textbf{plotnine}}: A grammar of graphics for Python + \href{https://plotnine.org/}{\textbf{plotnine}}: A grammar of graphics for Python \end{myboxed} % \begin{center} From 5f01d6d6749a850ec93120e26ff6e77ade0cf8f0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 5 Mar 2024 08:34:15 +0000 Subject: [PATCH 55/65] Bump cryptography from 42.0.2 to 42.0.4 in /requirements Bumps [cryptography](https://github.com/pyca/cryptography) from 42.0.2 to 42.0.4. - [Changelog](https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pyca/cryptography/compare/42.0.2...42.0.4) --- updated-dependencies: - dependency-name: cryptography dependency-type: indirect ... Signed-off-by: dependabot[bot] --- requirements/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 1b00994..2fc7f3a 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -40,7 +40,7 @@ click==8.1.7 # via pip-tools contourpy==1.2.0 # via matplotlib -cryptography==42.0.2 +cryptography==42.0.4 # via pdfminer-six cycler==0.12.1 # via matplotlib From e8d9284034c05474792f202be514028b65435115 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Apr 2024 04:39:34 +0000 Subject: [PATCH 56/65] Bump idna from 3.6 to 3.7 in /requirements Bumps [idna](https://github.com/kjd/idna) from 3.6 to 3.7. - [Release notes](https://github.com/kjd/idna/releases) - [Changelog](https://github.com/kjd/idna/blob/master/HISTORY.rst) - [Commits](https://github.com/kjd/idna/compare/v3.6...v3.7) --- updated-dependencies: - dependency-name: idna dependency-type: indirect ... Signed-off-by: dependabot[bot] --- requirements/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 2fc7f3a..8b7532b 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -58,7 +58,7 @@ fonttools==4.47.2 # via matplotlib identify==2.5.33 # via pre-commit -idna==3.6 +idna==3.7 # via requests imagesize==1.4.1 # via sphinx From 0322b1b6fb5c69ad5af4a24520ef54f132c34e64 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 11 Dec 2024 04:30:22 +0000 Subject: [PATCH 57/65] Bump certifi in /requirements in the pip group across 1 directory Bumps the pip group with 1 update in the /requirements directory: [certifi](https://github.com/certifi/python-certifi). Updates `certifi` from 2023.11.17 to 2024.7.4 - [Commits](https://github.com/certifi/python-certifi/compare/2023.11.17...2024.07.04) --- updated-dependencies: - dependency-name: certifi dependency-type: indirect dependency-group: pip ... Signed-off-by: dependabot[bot] --- requirements/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 8b7532b..ad81fd1 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -22,7 +22,7 @@ bump2version==1.0.1 # via -r requirements.in cartopy==0.22.0 # via -r requirements.in -certifi==2023.11.17 +certifi==2024.7.4 # via # pyproj # requests From 1af9cc23d1803374dc0636703a37eb2bbb73123d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Feb 2025 06:10:17 +0000 Subject: [PATCH 58/65] Bump the pip group in /requirements with 6 updates Bumps the pip group in /requirements with 6 updates: | Package | From | To | | --- | --- | --- | | [cryptography](https://github.com/pyca/cryptography) | `42.0.4` | `44.0.1` | | [jinja2](https://github.com/pallets/jinja) | `3.1.3` | `3.1.5` | | [pillow](https://github.com/python-pillow/Pillow) | `10.2.0` | `10.3.0` | | [requests](https://github.com/psf/requests) | `2.31.0` | `2.32.2` | | [urllib3](https://github.com/urllib3/urllib3) | `2.2.0` | `2.2.2` | | [virtualenv](https://github.com/pypa/virtualenv) | `20.25.0` | `20.26.6` | Updates `cryptography` from 42.0.4 to 44.0.1 - [Changelog](https://github.com/pyca/cryptography/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pyca/cryptography/compare/42.0.4...44.0.1) Updates `jinja2` from 3.1.3 to 3.1.5 - [Release notes](https://github.com/pallets/jinja/releases) - [Changelog](https://github.com/pallets/jinja/blob/main/CHANGES.rst) - [Commits](https://github.com/pallets/jinja/compare/3.1.3...3.1.5) Updates `pillow` from 10.2.0 to 10.3.0 - [Release notes](https://github.com/python-pillow/Pillow/releases) - [Changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst) - [Commits](https://github.com/python-pillow/Pillow/compare/10.2.0...10.3.0) Updates `requests` from 2.31.0 to 2.32.2 - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.31.0...v2.32.2) Updates `urllib3` from 2.2.0 to 2.2.2 - [Release notes](https://github.com/urllib3/urllib3/releases) - [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst) - [Commits](https://github.com/urllib3/urllib3/compare/2.2.0...2.2.2) Updates `virtualenv` from 20.25.0 to 20.26.6 - [Release notes](https://github.com/pypa/virtualenv/releases) - [Changelog](https://github.com/pypa/virtualenv/blob/main/docs/changelog.rst) - [Commits](https://github.com/pypa/virtualenv/compare/20.25.0...20.26.6) --- updated-dependencies: - dependency-name: cryptography dependency-type: indirect dependency-group: pip - dependency-name: jinja2 dependency-type: indirect dependency-group: pip - dependency-name: pillow dependency-type: direct:production dependency-group: pip - dependency-name: requests dependency-type: indirect dependency-group: pip - dependency-name: urllib3 dependency-type: indirect dependency-group: pip - dependency-name: virtualenv dependency-type: indirect dependency-group: pip ... Signed-off-by: dependabot[bot] --- requirements/requirements.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/requirements/requirements.txt b/requirements/requirements.txt index ad81fd1..528adaf 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -40,7 +40,7 @@ click==8.1.7 # via pip-tools contourpy==1.2.0 # via matplotlib -cryptography==42.0.4 +cryptography==44.0.1 # via pdfminer-six cycler==0.12.1 # via matplotlib @@ -62,7 +62,7 @@ idna==3.7 # via requests imagesize==1.4.1 # via sphinx -jinja2==3.1.3 +jinja2==3.1.5 # via sphinx kiwisolver==1.4.5 # via matplotlib @@ -97,7 +97,7 @@ pdfminer-six==20201018 # via pdfx pdfx==1.4.1 # via -r requirements.in -pillow==10.2.0 +pillow==10.3.0 # via # -r requirements.in # matplotlib @@ -136,7 +136,7 @@ python-dateutil==2.8.2 # via matplotlib pyyaml==6.0.1 # via pre-commit -requests==2.31.0 +requests==2.32.2 # via sphinx scipy==1.12.0 # via -r requirements.in @@ -177,9 +177,9 @@ tomli==2.0.1 # pyproject-hooks typing-extensions==4.9.0 # via pydata-sphinx-theme -urllib3==2.2.0 +urllib3==2.2.2 # via requests -virtualenv==20.25.0 +virtualenv==20.26.6 # via pre-commit wheel==0.42.0 # via pip-tools From 8158282806729e58511539d59bcf79ffb526f30f Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 23 Mar 2025 14:31:25 +0000 Subject: [PATCH 59/65] Add dependabot config to update GitHub actions --- .github/dependabot.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..34902e5 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +--- +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + groups: + actions: + patterns: + - "*" From 83df500573457221c9a819f6ff3931202970114a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 23 Mar 2025 14:47:19 +0000 Subject: [PATCH 60/65] Bump the actions group with 5 updates Bumps the actions group with 5 updates: | Package | From | To | | --- | --- | --- | | [actions/checkout](https://github.com/actions/checkout) | `3` | `4` | | [actions/setup-python](https://github.com/actions/setup-python) | `4` | `5` | | [pre-commit/action](https://github.com/pre-commit/action) | `3.0.0` | `3.0.1` | | [actions/upload-artifact](https://github.com/actions/upload-artifact) | `3` | `4` | | [peaceiris/actions-gh-pages](https://github.com/peaceiris/actions-gh-pages) | `3` | `4` | Updates `actions/checkout` from 3 to 4 - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) Updates `actions/setup-python` from 4 to 5 - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4...v5) Updates `pre-commit/action` from 3.0.0 to 3.0.1 - [Release notes](https://github.com/pre-commit/action/releases) - [Commits](https://github.com/pre-commit/action/compare/v3.0.0...v3.0.1) Updates `actions/upload-artifact` from 3 to 4 - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v3...v4) Updates `peaceiris/actions-gh-pages` from 3 to 4 - [Release notes](https://github.com/peaceiris/actions-gh-pages/releases) - [Changelog](https://github.com/peaceiris/actions-gh-pages/blob/main/CHANGELOG.md) - [Commits](https://github.com/peaceiris/actions-gh-pages/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major dependency-group: actions - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major dependency-group: actions - dependency-name: pre-commit/action dependency-type: direct:production update-type: version-update:semver-patch dependency-group: actions - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major dependency-group: actions - dependency-name: peaceiris/actions-gh-pages dependency-type: direct:production update-type: version-update:semver-major dependency-group: actions ... Signed-off-by: dependabot[bot] --- .github/workflows/main.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index be64b1d..8ea3441 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -6,14 +6,14 @@ jobs: pre-commit: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - - uses: pre-commit/action@v3.0.0 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + - uses: pre-commit/action@v3.0.1 build: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: "3.10" - name: Install dependencies @@ -52,7 +52,7 @@ jobs: - name: Run checks run: | make check - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 if: ${{ always() }} with: name: build @@ -74,7 +74,7 @@ jobs: >> $GITHUB_STEP_SUMMARY - name: Publish cheatsheets and handouts if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./docs/_build/html/ From 5aab1b43b2e8ed190cf26bee592c8c934d3da783 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 23 Mar 2025 19:22:30 +0000 Subject: [PATCH 61/65] Fix downloading pacifico font --- fonts/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fonts/Makefile b/fonts/Makefile index 7525dcf..96d20ee 100644 --- a/fonts/Makefile +++ b/fonts/Makefile @@ -7,7 +7,7 @@ ROBOTO_SLAB_ZIP := https://github.com/googlefonts/robotoslab/archive/a65e6d SOURCE_CODE_PRO_ZIP := https://github.com/adobe-fonts/source-code-pro/releases/download/2.038R-ro%2F1.058R-it%2F1.018R-VAR/OTF-source-code-pro-2.038R-ro-1.058R-it.zip SOURCE_SANS_PRO_ZIP := https://github.com/adobe-fonts/source-sans/releases/download/2.045R-ro%2F1.095R-it/source-sans-pro-2.045R-ro-1.095R-it.zip SOURCE_SERIF_PRO_ZIP := https://github.com/adobe-fonts/source-serif/releases/download/3.001R/source-serif-pro-3.001R.zip -PACIFICO_ZIP := https://fonts.google.com/download?family=Pacifico +PACIFICO := https://raw.githubusercontent.com/googlefonts/Pacifico/refs/heads/main/fonts/ttf/Pacifico-Regular.ttf UNZIP_FLAGS := -x "__MACOSX/*" @@ -25,7 +25,7 @@ all: sources cd source-code-pro && unzip -j /tmp/source-code-pro.zip "*.otf" $(UNZIP_FLAGS) cd source-sans-pro && unzip -j /tmp/source-sans-pro.zip "source-sans-pro-2.045R-ro-1.095R-it/OTF/*.otf" $(UNZIP_FLAGS) cd source-serif-pro && unzip -j /tmp/source-serif-pro.zip "source-serif-pro-3.001R/OTF/*.otf" $(UNZIP_FLAGS) - cd pacifico && unzip -j /tmp/pacifico.zip "*.ttf" $(UNZIP_FLAGS) + cd pacifico && cp /tmp/pacifico.ttf . .PHONY: sources sources: @@ -36,7 +36,7 @@ sources: wget $(SOURCE_CODE_PRO_ZIP) -O /tmp/source-code-pro.zip wget $(SOURCE_SANS_PRO_ZIP) -O /tmp/source-sans-pro.zip wget $(SOURCE_SERIF_PRO_ZIP) -O /tmp/source-serif-pro.zip - wget $(PACIFICO_ZIP) -O /tmp/pacifico.zip + wget $(PACIFICO) -O /tmp/pacifico.ttf .PHONY: clean clean: From a6112c96b4996f9446467a273f286937fc3646e3 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 3 Feb 2024 11:12:09 +0000 Subject: [PATCH 62/65] Update Matplotlib version to 3.8 --- .bumpversion.cfg | 2 +- Makefile | 2 +- cheatsheets.tex | 2 +- check-matplotlib-version.py | 2 +- handout-beginner.tex | 2 +- handout-intermediate.tex | 2 +- handout-tips.tex | 2 +- requirements/requirements.in | 3 ++- requirements/requirements.txt | 2 +- 9 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 776285c..7e284e4 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 3.7.4 +current_version = 3.8.2 [bumpversion:file:./check-matplotlib-version.py] search = __version__ == '{current_version}' diff --git a/Makefile b/Makefile index 1b7fbd1..38a8f25 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ all: logos figures cheatsheets handouts docs .PHONY: logos logos: - wget https://github.com/matplotlib/matplotlib/raw/v3.7.4/doc/_static/logo2.png -O ./logos/logo2.png + wget https://github.com/matplotlib/matplotlib/raw/v3.8.2/doc/_static/logo2.png -O ./logos/logo2.png .PHONY: figures figures: diff --git a/cheatsheets.tex b/cheatsheets.tex index 1bc2079..c6a5257 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -264,7 +264,7 @@ \begin{multicols*}{5} \begin{overpic}[width=\columnwidth,tics=6,trim=12 6 18 6, clip]{logo2.png} \put (16.5,1.5) {\scriptsize\RobotoCon \textcolor[HTML]{11557c}{Cheat sheet}} - \put (80,1.5) {\tiny\Roboto \textcolor[HTML]{11557c}{Version 3.7.4}} + \put (80,1.5) {\tiny\Roboto \textcolor[HTML]{11557c}{Version 3.8.2}} \end{overpic} %\textbf{\Large \RobotoCon Matplotlib 3.2 cheat sheet}\\ %{\ttfamily https://matplotlib.org} \hfill CC-BY 4.0 diff --git a/check-matplotlib-version.py b/check-matplotlib-version.py index 18b903f..1430429 100755 --- a/check-matplotlib-version.py +++ b/check-matplotlib-version.py @@ -2,4 +2,4 @@ import matplotlib as mpl -assert mpl.__version__ == '3.7.4' +assert mpl.__version__ == '3.8.2' diff --git a/handout-beginner.tex b/handout-beginner.tex index 37b0e05..58be029 100644 --- a/handout-beginner.tex +++ b/handout-beginner.tex @@ -297,7 +297,7 @@ \subsection*{\rmfamily Save \mdseries (bitmap or vector format)} \vfill % {\scriptsize - Matplotlib 3.7.4 handout for beginners. + Matplotlib 3.8.2 handout for beginners. Copyright (c) 2021 Matplotlib Development Team. Released under a CC-BY 4.0 International License. Supported by NumFOCUS. diff --git a/handout-intermediate.tex b/handout-intermediate.tex index 16f85f5..93d7b68 100644 --- a/handout-intermediate.tex +++ b/handout-intermediate.tex @@ -198,7 +198,7 @@ \subsection*{\rmfamily Size \& DPI} \vfill % {\scriptsize - Matplotlib 3.7.4 handout for intermediate users. + Matplotlib 3.8.2 handout for intermediate users. Copyright (c) 2021 Matplotlib Development Team. Released under a CC-BY 4.0 International License. Supported by NumFOCUS. diff --git a/handout-tips.tex b/handout-tips.tex index a6f7dd4..84ddede 100644 --- a/handout-tips.tex +++ b/handout-tips.tex @@ -243,7 +243,7 @@ \subsection*{\rmfamily Read the documentation} \vfill % {\scriptsize - Matplotlib 3.7.4 handout for tips \& tricks. + Matplotlib 3.8.2 handout for tips \& tricks. Copyright (c) 2021 Matplotlib Development Team. Released under a CC-BY 4.0 International License. Supported by NumFOCUS. diff --git a/requirements/requirements.in b/requirements/requirements.in index bf5cc75..f2dc9f0 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -2,7 +2,8 @@ autopep8 bump2version cartopy==0.22.0 flake8 -matplotlib==3.7.4 +matplotlib==3.8.2 +mpl-sphinx-theme~=3.7.1 pillow>=9 pdfx pip-tools diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 528adaf..d157b29 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -68,7 +68,7 @@ kiwisolver==1.4.5 # via matplotlib markupsafe==2.1.4 # via jinja2 -matplotlib==3.7.4 +matplotlib==3.8.2 # via # -r requirements.in # cartopy From 6df46cfec756aadf18eb8e2f32ea849a114c7f99 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 3 Feb 2024 11:19:12 +0000 Subject: [PATCH 63/65] Remove make logos option --- Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 38a8f25..aa863ad 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,7 @@ CONVERTFLAGS = -density 150 -alpha remove -depth 8 default: all .PHONY: all -all: logos figures cheatsheets handouts docs - -.PHONY: logos -logos: - wget https://github.com/matplotlib/matplotlib/raw/v3.8.2/doc/_static/logo2.png -O ./logos/logo2.png +all: figures cheatsheets handouts docs .PHONY: figures figures: From f362f19fadf91d3139f0e845caa3a8669110f7c8 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 23 Mar 2025 19:33:56 +0000 Subject: [PATCH 64/65] Fix requirements file --- requirements/requirements.in | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements/requirements.in b/requirements/requirements.in index f2dc9f0..2b1dd17 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -3,7 +3,6 @@ bump2version cartopy==0.22.0 flake8 matplotlib==3.8.2 -mpl-sphinx-theme~=3.7.1 pillow>=9 pdfx pip-tools From 2944bfe31048cf296b48df0cb195493ce8adfc7a Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 23 Mar 2025 19:42:27 +0000 Subject: [PATCH 65/65] Fix marker facecolors --- scripts/markers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/markers.py b/scripts/markers.py index 48f1d01..0780d12 100644 --- a/scripts/markers.py +++ b/scripts/markers.py @@ -27,7 +27,6 @@ ".", "o", "s", "P", "X", "*", "p", "D", "<", ">", "^", "v", ] for x, y, marker in zip(X, Y, markers): if y == 3: fc = "white" - elif y == 2: fc = "None" else: fc = "C1" plt.scatter(x, 1+y, s=100, marker=marker, fc=fc, ec="C1", lw=0.5)