Skip to content

Commit 331390f

Browse files
committed
[#894] Fix PEP8 and mypy errors
1 parent e600d75 commit 331390f

File tree

1 file changed

+44
-16
lines changed

1 file changed

+44
-16
lines changed

axelrod/plot.py

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ def __init__(self, result_set: ResultSet) -> None:
4848
self.nplayers = self.result_set.nplayers
4949
self.players = self.result_set.players
5050

51-
def _violinplot(self, data: dataType, names: namesType, title: titleType =None, ax: matplotlib.axes.SubplotBase =None) -> matplotlib.figure.Figure:
51+
def _violinplot(
52+
self, data: dataType, names: namesType, title: titleType = None,
53+
ax: matplotlib.axes.SubplotBase = None
54+
) -> matplotlib.figure.Figure:
5255
"""For making violinplots."""
5356
if not self.matplotlib_installed: # pragma: no cover
5457
return None
@@ -89,11 +92,13 @@ def _boxplot_xticks_locations(self):
8992
def _boxplot_xticks_labels(self):
9093
return [str(n) for n in self.result_set.ranked_names]
9194

92-
def boxplot(self, title: titleType =None, ax: matplotlib.axes.SubplotBase =None) -> matplotlib.figure.Figure:
95+
def boxplot(
96+
self, title: titleType =None, ax: matplotlib.axes.SubplotBase = None
97+
) -> matplotlib.figure.Figure:
9398
"""For the specific mean score boxplot."""
9499
data = self._boxplot_dataset
95100
names = self._boxplot_xticks_labels
96-
figure = self._violinplot(data, names, title=title, ax=ax)
101+
figure = self._violinplot(data, names, title=title, ax=ax)
97102
return figure
98103

99104
@property
@@ -108,7 +113,9 @@ def _winplot_dataset(self):
108113
ranked_names = [str(self.players[x[-1]]) for x in medians]
109114
return wins, ranked_names
110115

111-
def winplot(self, title: titleType =None, ax: matplotlib.axes.SubplotBase =None) -> matplotlib.figure.Figure:
116+
def winplot(
117+
self, title: titleType = None, ax: matplotlib.axes.SubplotBase = None
118+
) -> matplotlib.figure.Figure:
112119
"""Plots the distributions for the number of wins for each strategy."""
113120
if not self.matplotlib_installed: # pragma: no cover
114121
return None
@@ -133,7 +140,9 @@ def _sdv_plot_dataset(self):
133140
ranked_names = [str(self.players[i]) for i in ordering]
134141
return diffs, ranked_names
135142

136-
def sdvplot(self, title: titleType =None, ax: matplotlib.axes.SubplotBase =None) -> matplotlib.figure.Figure:
143+
def sdvplot(
144+
self, title: titleType = None, ax: matplotlib.axes.SubplotBase = None
145+
) -> matplotlib.figure.Figure:
137146
"""Score difference violinplots to visualize the distributions of how
138147
players attain their payoffs."""
139148
diffs, ranked_names = self._sdv_plot_dataset
@@ -147,7 +156,9 @@ def _lengthplot_dataset(self):
147156
for length in rep[playeri]] for playeri in
148157
self.result_set.ranking]
149158

150-
def lengthplot(self, title: titleType =None, ax: matplotlib.axes.SubplotBase =None) -> matplotlib.figure.Figure:
159+
def lengthplot(
160+
self, title: titleType = None, ax: matplotlib.axes.SubplotBase = None
161+
) -> matplotlib.figure.Figure:
151162
"""For the specific match length boxplot."""
152163
data = self._lengthplot_dataset
153164
names = self._boxplot_xticks_labels
@@ -173,7 +184,10 @@ def _pdplot_dataset(self):
173184
ranked_names = [str(players[i]) for i in ordering]
174185
return matrix, ranked_names
175186

176-
def _payoff_heatmap(self, data: dataType, names: namesType, title: titleType =None, ax: matplotlib.axes.SubplotBase =None) -> matplotlib.figure.Figure:
187+
def _payoff_heatmap(
188+
self, data: dataType, names: namesType, title: titleType = None,
189+
ax: matplotlib.axes.SubplotBase = None
190+
) -> matplotlib.figure.Figure:
177191
"""Generic heatmap plot"""
178192
if not self.matplotlib_installed: # pragma: no cover
179193
return None
@@ -202,13 +216,17 @@ def _payoff_heatmap(self, data: dataType, names: namesType, title: titleType =No
202216
plt.colorbar(mat, cax=cax)
203217
return figure
204218

205-
def pdplot(self, title: titleType =None, ax: matplotlib.axes.SubplotBase =None):
219+
def pdplot(
220+
self, title: titleType = None, ax: matplotlib.axes.SubplotBase = None
221+
) -> matplotlib.figure.Figure:
206222
"""Payoff difference heatmap to visualize the distributions of how
207223
players attain their payoffs."""
208224
matrix, names = self._pdplot_dataset
209225
return self._payoff_heatmap(matrix, names, title=title, ax=ax)
210226

211-
def payoff(self, title: titleType =None, ax: matplotlib.axes.SubplotBase =None):
227+
def payoff(
228+
self, title: titleType = None, ax: matplotlib.axes.SubplotBase = None
229+
) -> matplotlib.figure.Figure:
212230
"""Payoff heatmap to visualize the distributions of how
213231
players attain their payoffs."""
214232
data = self._payoff_dataset
@@ -217,7 +235,10 @@ def payoff(self, title: titleType =None, ax: matplotlib.axes.SubplotBase =None):
217235

218236
# Ecological Plot
219237

220-
def stackplot(self, eco, title: titleType =None, logscale: bool =True, ax: matplotlib.axes.SubplotBase =None) -> matplotlib.figure.Figure:
238+
def stackplot(
239+
self, eco, title: titleType = None, logscale: bool = True,
240+
ax: matplotlib.axes.SubplotBase =None
241+
) -> matplotlib.figure.Figure:
221242
if not self.matplotlib_installed: # pragma: no cover
222243
return None
223244

@@ -230,7 +251,10 @@ def stackplot(self, eco, title: titleType =None, logscale: bool =True, ax: matpl
230251

231252
figure = ax.get_figure()
232253
turns = range(len(populations))
233-
pops = [[populations[iturn][ir] for iturn in turns] for ir in self.result_set.ranking]
254+
pops = [
255+
[populations[iturn][ir] for iturn in turns]
256+
for ir in self.result_set.ranking
257+
]
234258
ax.stackplot(turns, *pops)
235259

236260
ax.yaxis.tick_left()
@@ -243,13 +267,15 @@ def stackplot(self, eco, title: titleType =None, logscale: bool =True, ax: matpl
243267
if title is not None:
244268
plt.title(title)
245269

246-
trans = transforms.blended_transform_factory(ax.transAxes, ax.transData)
270+
trans = transforms.blended_transform_factory(
271+
ax.transAxes, ax.transData)
247272
ticks = []
248273
for i, n in enumerate(self.result_set.ranked_names):
249274
x = -0.01
250275
y = (i + 0.5) * 1 / self.result_set.nplayers
251-
ax.annotate(n, xy=(x, y), xycoords=trans, clip_on=False,
252-
va='center', ha='right', fontsize=5)
276+
ax.annotate(
277+
n, xy=(x, y), xycoords=trans, clip_on=False, va='center',
278+
ha='right', fontsize=5)
253279
ticks.append(y)
254280
ax.set_yticks(ticks)
255281
ax.tick_params(direction='out')
@@ -260,8 +286,10 @@ def stackplot(self, eco, title: titleType =None, logscale: bool =True, ax: matpl
260286

261287
return figure
262288

263-
def save_all_plots(self, prefix: str ="axelrod", title_prefix: str ="axelrod",
264-
filetype: str ="svg", progress_bar: bool =True):
289+
def save_all_plots(
290+
self, prefix: str ="axelrod", title_prefix: str ="axelrod",
291+
filetype: str ="svg", progress_bar: bool = True
292+
) -> None:
265293
"""
266294
A method to save all plots to file.
267295

0 commit comments

Comments
 (0)