@@ -280,15 +280,39 @@ def fingerprint(self, turns=50, repetitions=10, step=0.01, processes=None,
280
280
self .data = self .generate_data (self .interactions , self .points , edges )
281
281
return self .data
282
282
283
- def plot (self , col_map = 'seismic' , interpolation = 'none' , title = None ):
283
+ @staticmethod
284
+ def reshape_data (data , points , size ):
285
+ """Shape the data so that it can be plotted easily.
286
+
287
+ Parameters
288
+ ----------
289
+ data : dictionary
290
+ A dictionary where the keys are Points of the form (x, y) and
291
+ the values are the mean score for the corresponding interactions.
292
+
293
+ points : list
294
+ of Point objects with coordinates (x, y).
295
+
296
+ size : int
297
+ The number of Points in every row/column.
298
+
299
+ Returns
300
+ ----------
301
+ plotting_data : list
302
+ 2-D numpy array of the scores, correctly shaped to ensure that the
303
+ score corresponding to Point (0, 0) is in the left hand corner ie.
304
+ the standard origin.
305
+ """
306
+ ordered_data = [data [point ] for point in points ]
307
+ shaped_data = np .reshape (ordered_data , (size , size ), order = 'F' )
308
+ plotting_data = np .flipud (shaped_data )
309
+ return plotting_data
310
+
311
+ def plot (self , col_map = 'seismic' , interpolation = 'none' , title = None , colorbar = True , labels = True ):
284
312
"""Plot the results of the spatial tournament.
285
313
286
314
Parameters
287
315
----------
288
- filename : str, optional
289
- The location and name that the resulting plot should be saved to.
290
- Defaults to the current directory with the name
291
- `Strategy and Probe.pdf`
292
316
col_map : str, optional
293
317
A matplotlib colour map, full list can be found at
294
318
http://matplotlib.org/examples/color/colormaps_reference.html
@@ -297,18 +321,36 @@ def plot(self, col_map='seismic', interpolation='none', title=None):
297
321
http://matplotlib.org/examples/images_contours_and_fields/interpolation_methods.html
298
322
title : str, optional
299
323
A title for the plot
324
+ colorbar : bool, optional
325
+ Choose whether the colorbar should be included or not
326
+ labels : bool, optional
327
+ Choose whether the axis labels and ticks should be included
300
328
301
329
Returns
302
330
----------
303
331
figure : matplotlib figure
304
332
A heat plot of the results of the spatial tournament
305
333
"""
306
334
size = int ((1 / self .step ) // 1 ) + 1
307
- ordered_data = [self .data [point ] for point in self .points ]
308
- plotting_data = np .reshape (ordered_data , (size , size ))
309
- figure = plt .figure ()
310
- plt .imshow (plotting_data , cmap = col_map , interpolation = interpolation )
311
- plt .axis ('off' )
335
+ plotting_data = self .reshape_data (self .data , self .points , size )
336
+ fig , ax = plt .subplots ()
337
+ cax = ax .imshow (plotting_data , cmap = col_map , interpolation = interpolation )
338
+
339
+ if colorbar :
340
+ max_score = max (self .data .values ())
341
+ min_score = min (self .data .values ())
342
+ ticks = [min_score , (max_score + min_score ) / 2 , max_score ]
343
+ fig .colorbar (cax , ticks = ticks )
344
+
345
+ plt .xlabel ('$x$' )
346
+ plt .ylabel ('$y$' , rotation = 0 )
347
+ ax .tick_params (axis = 'both' , which = 'both' , length = 0 )
348
+ plt .xticks ([0 , len (plotting_data ) - 1 ], ['0' , '1' ])
349
+ plt .yticks ([0 , len (plotting_data ) - 1 ], ['1' , '0' ])
350
+
351
+ if not labels :
352
+ plt .axis ('off' )
353
+
312
354
if title is not None :
313
355
plt .title (title )
314
- return figure
356
+ return fig
0 commit comments