@@ -48,7 +48,10 @@ def __init__(self, result_set: ResultSet) -> None:
48
48
self .nplayers = self .result_set .nplayers
49
49
self .players = self .result_set .players
50
50
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 :
52
55
"""For making violinplots."""
53
56
if not self .matplotlib_installed : # pragma: no cover
54
57
return None
@@ -89,11 +92,13 @@ def _boxplot_xticks_locations(self):
89
92
def _boxplot_xticks_labels (self ):
90
93
return [str (n ) for n in self .result_set .ranked_names ]
91
94
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 :
93
98
"""For the specific mean score boxplot."""
94
99
data = self ._boxplot_dataset
95
100
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 )
97
102
return figure
98
103
99
104
@property
@@ -108,7 +113,9 @@ def _winplot_dataset(self):
108
113
ranked_names = [str (self .players [x [- 1 ]]) for x in medians ]
109
114
return wins , ranked_names
110
115
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 :
112
119
"""Plots the distributions for the number of wins for each strategy."""
113
120
if not self .matplotlib_installed : # pragma: no cover
114
121
return None
@@ -133,7 +140,9 @@ def _sdv_plot_dataset(self):
133
140
ranked_names = [str (self .players [i ]) for i in ordering ]
134
141
return diffs , ranked_names
135
142
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 :
137
146
"""Score difference violinplots to visualize the distributions of how
138
147
players attain their payoffs."""
139
148
diffs , ranked_names = self ._sdv_plot_dataset
@@ -147,7 +156,9 @@ def _lengthplot_dataset(self):
147
156
for length in rep [playeri ]] for playeri in
148
157
self .result_set .ranking ]
149
158
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 :
151
162
"""For the specific match length boxplot."""
152
163
data = self ._lengthplot_dataset
153
164
names = self ._boxplot_xticks_labels
@@ -173,7 +184,10 @@ def _pdplot_dataset(self):
173
184
ranked_names = [str (players [i ]) for i in ordering ]
174
185
return matrix , ranked_names
175
186
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 :
177
191
"""Generic heatmap plot"""
178
192
if not self .matplotlib_installed : # pragma: no cover
179
193
return None
@@ -202,13 +216,17 @@ def _payoff_heatmap(self, data: dataType, names: namesType, title: titleType =No
202
216
plt .colorbar (mat , cax = cax )
203
217
return figure
204
218
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 :
206
222
"""Payoff difference heatmap to visualize the distributions of how
207
223
players attain their payoffs."""
208
224
matrix , names = self ._pdplot_dataset
209
225
return self ._payoff_heatmap (matrix , names , title = title , ax = ax )
210
226
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 :
212
230
"""Payoff heatmap to visualize the distributions of how
213
231
players attain their payoffs."""
214
232
data = self ._payoff_dataset
@@ -217,7 +235,10 @@ def payoff(self, title: titleType =None, ax: matplotlib.axes.SubplotBase =None):
217
235
218
236
# Ecological Plot
219
237
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 :
221
242
if not self .matplotlib_installed : # pragma: no cover
222
243
return None
223
244
@@ -230,7 +251,10 @@ def stackplot(self, eco, title: titleType =None, logscale: bool =True, ax: matpl
230
251
231
252
figure = ax .get_figure ()
232
253
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
+ ]
234
258
ax .stackplot (turns , * pops )
235
259
236
260
ax .yaxis .tick_left ()
@@ -243,13 +267,15 @@ def stackplot(self, eco, title: titleType =None, logscale: bool =True, ax: matpl
243
267
if title is not None :
244
268
plt .title (title )
245
269
246
- trans = transforms .blended_transform_factory (ax .transAxes , ax .transData )
270
+ trans = transforms .blended_transform_factory (
271
+ ax .transAxes , ax .transData )
247
272
ticks = []
248
273
for i , n in enumerate (self .result_set .ranked_names ):
249
274
x = - 0.01
250
275
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 )
253
279
ticks .append (y )
254
280
ax .set_yticks (ticks )
255
281
ax .tick_params (direction = 'out' )
@@ -260,8 +286,10 @@ def stackplot(self, eco, title: titleType =None, logscale: bool =True, ax: matpl
260
286
261
287
return figure
262
288
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 :
265
293
"""
266
294
A method to save all plots to file.
267
295
0 commit comments