Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 92d26b5

Browse files
authored
Merge pull request matplotlib#56 from jimustafa/master
add `pre-commit` workflow for whitespace checking
2 parents afebd6b + bd74403 commit 92d26b5

27 files changed

+74
-63
lines changed

.github/workflows/main.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
pre-commit:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: actions/setup-python@v2
11+
- uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.4.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
files: (?x)^(
8+
[\w-]+[.]tex|
9+
scripts/[\w-]+[.]py|
10+
)$
11+
- id: trailing-whitespace
12+
files: (?x)^(
13+
[\w-]+[.]tex|
14+
scripts/[\w-]+[.]py|
15+
)$

handout-beginner.tex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ \subsection*{\rmfamily Tweak}
181181
% -----------------------------------------------------------------------------
182182
You can modify pretty much anything in a plot, including limits,
183183
colors, markers, line width and styles, ticks and ticks labels,
184-
titles, etc. \medskip
184+
titles, etc. \medskip
185185

186186
% -----------------------------------------------------------------------------
187187
\begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}}
@@ -302,4 +302,3 @@ \subsection*{\rmfamily Save \mdseries (bitmap or vector format)}
302302

303303
\end{multicols*}
304304
\end{document}
305-

handout-intermediate.tex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ \section*{\LARGE \rmfamily
7575

7676
A matplotlib figure is composed of a hierarchy of elements that forms
7777
the actual figure. Each element can be modified. \medskip
78-
78+
7979
\includegraphics[width=\linewidth]{anatomy-cropped.pdf}
8080

8181
\subsection*{\rmfamily Figure, axes \& spines}
@@ -204,4 +204,3 @@ \subsection*{\rmfamily Size \& DPI}
204204

205205
\end{multicols*}
206206
\end{document}
207-

handout-tips.tex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ \subsection*{\rmfamily Transparency}
8787
\begin{tabular}{@{}m{.774\linewidth}m{.216\linewidth}}
8888
\begin{lstlisting}[belowskip=-\baselineskip]
8989
X = np.random.normal(-1,1,500)
90-
Y = np.random.normal(-1,1,500)
90+
Y = np.random.normal(-1,1,500)
9191
ax.scatter(X, Y, 50, "0.0", lw=2) # optional
9292
ax.scatter(X, Y, 50, "1.0", lw=0) # optional
9393
ax.scatter(X, Y, 40, "C1", lw=0, alpha=0.1)
@@ -102,7 +102,7 @@ \subsection*{\rmfamily Rasterization}
102102
in vector format.
103103
\begin{lstlisting}
104104
X = np.random.normal(-1, 1, 10_000)
105-
Y = np.random.normal(-1, 1, 10_000)
105+
Y = np.random.normal(-1, 1, 10_000)
106106
ax.scatter(X, Y, rasterized=True)
107107
fig.savefig("rasterized-figure.pdf", dpi=600)
108108
\end{lstlisting}
@@ -117,7 +117,7 @@ \subsection*{\rmfamily Offline rendering}
117117
... # draw som stuff
118118
canvas.draw()
119119
Z = np.array(canvas.renderer.buffer_rgba())
120-
\end{lstlisting}
120+
\end{lstlisting}
121121

122122
% -----------------------------------------------------------------------------
123123
\subsection*{\rmfamily Range of continuous colors}
@@ -127,7 +127,7 @@ \subsection*{\rmfamily Range of continuous colors}
127127
X = np.random.randn(1000, 4)
128128
cmap = plt.get_cmap("Oranges")
129129
colors = cmap([0.2, 0.4, 0.6, 0.8])
130-
130+
131131
ax.hist(X, 2, histtype='bar', color=colors)
132132
\end{lstlisting} &
133133
\raisebox{-0.75em}{\includegraphics[width=\linewidth]{tip-color-range.pdf}}
@@ -166,9 +166,9 @@ \subsection*{\rmfamily Dotted lines}
166166
To have rounded dotted lines, use a custom {\ttfamily linestyle} and
167167
modify {\ttfamily dash\_capstyle}.
168168
\begin{lstlisting}
169-
ax.plot([0,1], [0,0], "C1",
169+
ax.plot([0,1], [0,0], "C1",
170170
linestyle = (0, (0.01, 1)), dash_capstyle="round")
171-
ax.plot([0,1], [1,1], "C1",
171+
ax.plot([0,1], [1,1], "C1",
172172
linestyle = (0, (0.01, 2)), dash_capstyle="round")
173173
\end{lstlisting}
174174
\includegraphics[width=\linewidth]{tip-dotted.pdf}
@@ -194,7 +194,7 @@ \subsection*{\rmfamily Colorbar adjustment}
194194
\begin{tabular}{@{}m{.754\linewidth}m{.236\linewidth}}
195195
\begin{lstlisting}[belowskip=-\baselineskip]
196196
im = ax.imshow(Z)
197-
197+
198198
cb = plt.colorbar(im,
199199
fraction=0.046, pad=0.04)
200200
cb.set_ticks([])

scripts/adjustements.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def ext_arrow(p0,p1,p2,p3):
6464
p0, p1 = np.asarray(p0), np.asarray(p1)
6565
p2, p3 = np.asarray(p2), np.asarray(p3)
6666
ax.arrow(*p0, *(p1-p0), zorder=20, linewidth=0,
67-
length_includes_head=True, width=.4,
67+
length_includes_head=True, width=.4,
6868
head_width=2, head_length=2, color="black")
6969
ax.arrow(*p3, *(p2-p3), zorder=20, linewidth=0,
7070
length_includes_head=True, width=.4,
@@ -74,13 +74,13 @@ def ext_arrow(p0,p1,p2,p3):
7474
def int_arrow(p0,p1):
7575
p0, p1 = np.asarray(p0), np.asarray(p1)
7676
ax.arrow(*((p0+p1)/2), *((p1-p0)/2), zorder=20, linewidth=0,
77-
length_includes_head=True, width=.4,
77+
length_includes_head=True, width=.4,
7878
head_width=2, head_length=2, color="black")
7979
ax.arrow(*((p0+p1)/2), *(-(p1-p0)/2), zorder=20, linewidth=0,
80-
length_includes_head=True, width=.4,
80+
length_includes_head=True, width=.4,
8181
head_width=2, head_length=2, color="black")
8282

83-
83+
8484

8585
x = 0
8686
y = 10

scripts/advanced-plots.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Released under the BSD License
44
# -----------------------------------------------------------------------------
55

6-
# Scripts to generate all the basic plots
6+
# Scripts to generate all the basic plots
77
import numpy as np
88
import matplotlib as mpl
99
import matplotlib.pyplot as plt
@@ -149,4 +149,3 @@
149149
ax.grid(linewidth=0.125)
150150
plt.savefig("../figures/advanced-xcorr.pdf")
151151
ax.clear()
152-

scripts/basic-plots.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Released under the BSD License
44
# -----------------------------------------------------------------------------
55

6-
# Scripts to generate all the basic plots
6+
# Scripts to generate all the basic plots
77
import numpy as np
88
import matplotlib as mpl
99
import matplotlib.pyplot as plt
@@ -56,7 +56,7 @@
5656
np.random.seed(3)
5757
X = 0.5 + np.arange(8)
5858
Y = np.random.uniform(2, 7, len(X))
59-
ax.bar(X, Y, bottom=0, width=1,
59+
ax.bar(X, Y, bottom=0, width=1,
6060
edgecolor="white", facecolor="C1", linewidth=0.25)
6161
ax.set_xlim(0, 8), ax.set_xticks(np.arange(1,8))
6262
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
@@ -110,9 +110,9 @@
110110
ax.set_ylim(0, 8), ax.set_yticks(np.arange(1,8))
111111
ax.set_axisbelow(True)
112112
ax.grid(linewidth=0.25, color="0.75")
113-
ax.pie(X, colors=["white",]*len(X), radius=3, center=(4,4),
113+
ax.pie(X, colors=["white",]*len(X), radius=3, center=(4,4),
114114
wedgeprops = {"linewidth": 0.25, "edgecolor": "white"}, frame=True)
115-
ax.pie(X, colors=colors, radius=3, center=(4,4),
115+
ax.pie(X, colors=colors, radius=3, center=(4,4),
116116
wedgeprops = {"linewidth": 0.25, "edgecolor": "white"}, frame=True)
117117
plt.savefig("../figures/basic-pie.pdf")
118118
ax.clear()
@@ -158,4 +158,3 @@
158158
ax.grid(linewidth=0.125, color="0.75")
159159
plt.savefig("../figures/basic-quiver.pdf")
160160
ax.clear()
161-

scripts/colormaps.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# Uniform colormaps
1212
# -----------------------------------------------------------------------------
1313
cmaps = ('viridis', 'plasma', 'inferno', 'magma', 'cividis',
14-
14+
1515
'PRGn', 'PiYG', 'RdYlGn', 'BrBG', 'RdGy', 'PuOr', 'RdBu',
1616
'RdYlBu', 'Spectral', 'coolwarm', 'bwr', 'seismic',
1717

@@ -23,7 +23,7 @@
2323
'PuRd', 'RdPu', 'BuPu', 'Purples', 'YlGnBu', 'Blues',
2424
'PuBu', 'GnBu', 'PuBuGn', 'BuGn','Greens', 'YlGn',
2525

26-
'bone', 'gray', 'pink', 'afmhot', 'hot', 'gist_heat', 'copper',
26+
'bone', 'gray', 'pink', 'afmhot', 'hot', 'gist_heat', 'copper',
2727
'Wistia', 'autumn', 'summer', 'spring', 'cool', 'winter',
2828

2929
'twilight', 'twilight_shifted', 'hsv',
@@ -41,7 +41,7 @@
4141
if cmap in ['Set3']: n = 12
4242
if cmap in ['Greys']: n = 11
4343
Z = np.linspace(0,1,n).reshape(1,n)
44-
44+
4545
ax.imshow(Z, extent=[xmin, xmax, ymin, ymax], cmap=plt.get_cmap(cmap))
4646
ax.set_xlim(xmin, xmax), ax.set_xticks([])
4747
ax.set_ylim(ymin, ymax), ax.set_yticks([])
@@ -61,6 +61,6 @@
6161
ax.text(x[i], (ymin+ymax)/2, text, color=color, zorder=10,
6262
family = "Source Pro Serif", size=10, ha="center", va="center")
6363
"""
64-
64+
6565
plt.savefig("../figures/colormap-%s.pdf" % cmap)
6666
ax.clear()

scripts/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@
3535
text = str(colors[i]).replace(' ', '')
3636
ax.text((i+0.5)*dx, (ymin+ymax)/2, text, color=color, zorder=10,
3737
family = "Source Code Pro", size=9, ha="center", va="center")
38-
38+
3939
plt.savefig("../figures/colors-%s.pdf" % name)
4040
ax.clear()

scripts/extents.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Released under the BSD License
44
# -----------------------------------------------------------------------------
55

6-
# Scripts to generate all the basic plots
6+
# Scripts to generate all the basic plots
77
import numpy as np
88
import matplotlib as mpl
99
import matplotlib.pyplot as plt
@@ -64,6 +64,3 @@
6464

6565
plt.savefig("../figures/extents.pdf", dpi=600)
6666
plt.show()
67-
68-
69-

scripts/figure.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def ext_arrow(p0,p1,p2,p3):
6464
p0, p1 = np.asarray(p0), np.asarray(p1)
6565
p2, p3 = np.asarray(p2), np.asarray(p3)
6666
ax.arrow(*p0, *(p1-p0), zorder=20, linewidth=0,
67-
length_includes_head=True, width=.4,
67+
length_includes_head=True, width=.4,
6868
head_width=2, head_length=2, color="black")
6969
ax.arrow(*p3, *(p2-p3), zorder=20, linewidth=0,
7070
length_includes_head=True, width=.4,
@@ -74,13 +74,13 @@ def ext_arrow(p0,p1,p2,p3):
7474
def int_arrow(p0,p1):
7575
p0, p1 = np.asarray(p0), np.asarray(p1)
7676
ax.arrow(*((p0+p1)/2), *((p1-p0)/2), zorder=20, linewidth=0,
77-
length_includes_head=True, width=.4,
77+
length_includes_head=True, width=.4,
7878
head_width=2, head_length=2, color="black")
7979
ax.arrow(*((p0+p1)/2), *(-(p1-p0)/2), zorder=20, linewidth=0,
80-
length_includes_head=True, width=.4,
80+
length_includes_head=True, width=.4,
8181
head_width=2, head_length=2, color="black")
8282

83-
83+
8484

8585
x = 0
8686
y = 10

scripts/fonts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"%s" % (families[family]),
6060
color="0.25", va="center", ha="right",
6161
size="small", family = "Source Code Pro", weight = 400)
62-
y += 1.65
62+
y += 1.65
6363
y += 1
6464

6565

@@ -98,7 +98,7 @@
9898
for i,size in enumerate(sizes.keys()):
9999
ax.text(1, y, text, size=size,
100100
ha="left", va="center", family = "Source Sans Pro", weight="light")
101-
101+
102102
ax.text(39, y, "%s (%.2f)" % (size, sizes[size]),
103103
color="0.25", va="center", ha="right",
104104
size="small", family = "Source Code Pro", weight = 400)

scripts/layouts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,3 @@
8383
fig.add_axes(cax)
8484
cax.set_xticks([]), cax.set_yticks([])
8585
plt.savefig("../figures/layout-divider.pdf")
86-

scripts/line.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
fig = plt.figure(figsize=(4.25,4*.45))
66
ax = fig.add_axes([0,0,1,1], xlim=[0,11], ylim=[0.5,4.5], frameon=False,
7-
xticks=[], yticks=[])
7+
xticks=[], yticks=[])
88
y = 4
99

1010
def split(n_segment):
@@ -28,7 +28,7 @@ def split(n_segment):
2828
ax.text(X0[0]-0.25, y+0.2, "Line width", size="small", ha="left", va="baseline")
2929
ax.text(X1[-1]+0.25, y+0.2, "linewidth / lw", color="blue",
3030
size="small", ha="right", va="baseline", family="monospace")
31-
y -= 1
31+
y -= 1
3232

3333
# Solid capstyle
3434
# ----------------------------------------------------------------------------
@@ -45,7 +45,7 @@ def split(n_segment):
4545
ax.text(X0[0]-0.25, y+0.2, "Cap style", size="small", ha="left", va="baseline")
4646
ax.text(X1[-1]+0.25, y+0.2, "solid_capstyle", color="blue",
4747
size="small", ha="right", va="baseline", family="monospace")
48-
y -= 1
48+
y -= 1
4949

5050
# Dash capstyle
5151
# ----------------------------------------------------------------------------
@@ -61,7 +61,7 @@ def split(n_segment):
6161
ax.text(X0[0]-0.25, y+0.2, "Dash cap style", size="small", ha="left", va="baseline")
6262
ax.text(X1[-1]+0.25, y+0.2, "dash_capstyle", color="blue",
6363
size="small", ha="right", va="baseline", family="monospace")
64-
y -= 1
64+
y -= 1
6565

6666
# Line style
6767
# ----------------------------------------------------------------------------
@@ -79,7 +79,7 @@ def split(n_segment):
7979
ax.text(X0[0]-0.25, y+0.2, "Line style", size="small", ha="left", va="baseline")
8080
ax.text(X1[-1]+0.25, y+0.2, "linestyle / ls", color="blue",
8181
size="small", ha="right", va="baseline", family="monospace")
82-
y -= 1
82+
y -= 1
8383

8484
plt.savefig("line.pdf", dpi=200)
8585
plt.show()

scripts/markers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
markers = [
2121
"$♠$", "$♣$", "$♥$","$♦$", "$→$","$←$","$↑$","$↓$", "$◐$","$◑$","$◒$","$◓$",
2222
"1", "2", "3", "4", "+", "x", "|", "_", 4, 5, 6, 7,
23-
".", "o", "s", "P", "X", "*", "p", "D", "<", ">", "^", "v", ]
23+
".", "o", "s", "P", "X", "*", "p", "D", "<", ">", "^", "v", ]
2424
for x,y,marker in zip(X,Y,markers):
2525
if y == 3: fc = "white"
2626
elif y == 2: fc = "None"
@@ -44,7 +44,7 @@
4444
y = .6
4545
for x0, mark in zip(X0,marks):
4646
X = np.linspace(x0, x0+segment_width, 50)
47-
Y = y*np.ones(len(X))
47+
Y = y*np.ones(len(X))
4848
ax.plot(X, Y, linewidth=1, color="black",
4949
marker=".", mfc="white", mec="black", mew="1", markevery=mark)
5050
ax.text((X[0]+X[-1])/2, y-0.2, '%s' % str(mark),
@@ -53,4 +53,3 @@
5353
plt.text(.7, 1, "markevery",
5454
size="medium", ha="left", va="center", family="Source Code Pro")
5555
plt.savefig("../figures/markers.pdf", dpi=600)
56-

scripts/performance-tips.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
X = np.random.uniform(0,1,n)
1515
Y = np.random.uniform(0,1,n)
1616

17-
start = time.perf_counter()
17+
start = time.perf_counter()
1818
ax.plot(X, Y, marker="o", ls="")
1919
end = time.perf_counter()
2020
print(f"Time: {end-start}s")
2121

2222
ax.clear()
2323

24-
start = time.perf_counter()
24+
start = time.perf_counter()
2525
ax.scatter(X, Y)
2626
end = time.perf_counter()
2727
print(f"Time: {end-start}s")
@@ -54,4 +54,3 @@
5454
# plt.plot(X,Y)
5555
end = time.perf_counter()
5656
print(f"Time: {end-start}s")
57-

scripts/plot-variations.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Released under the BSD License
44
# -----------------------------------------------------------------------------
55

6-
# Scripts to generate all the basic plots
6+
# Scripts to generate all the basic plots
77
import numpy as np
88
import matplotlib as mpl
99
import matplotlib.pyplot as plt
@@ -149,4 +149,3 @@
149149
# plt.show()
150150
plt.savefig("../figures/plot-xlabel.pdf")
151151
fig.clear()
152-

0 commit comments

Comments
 (0)