-
Notifications
You must be signed in to change notification settings - Fork 271
Add plotting option to Fingerprint plot #787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a26c39d
a8e24bf
81663c3
2923f12
bab7a76
e385382
a8287f5
addebb5
9003610
8ebad22
9bf7392
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ target/ | |
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
*.ipynb | ||
# pyenv | ||
.python-version | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,15 +280,39 @@ def fingerprint(self, turns=50, repetitions=10, step=0.01, processes=None, | |
self.data = self.generate_data(self.interactions, self.points, edges) | ||
return self.data | ||
|
||
def plot(self, col_map='seismic', interpolation='none', title=None): | ||
@staticmethod | ||
def reshape_data(data, points, size): | ||
"""Shape the data so that it can be plotted easily. | ||
|
||
Parameters | ||
---------- | ||
data : dictionary | ||
A dictionary where the keys are Points of the form (x, y) and | ||
the values are the mean score for the corresponding interactions. | ||
|
||
points : list | ||
of Point objects with coordinates (x, y). | ||
|
||
size : int | ||
The number of Points in every row/column. | ||
|
||
Returns | ||
---------- | ||
plotting_data : list | ||
2-D numpy array of the scores, correctly shaped to ensure that the | ||
score corresponding to Point (0, 0) is in the left hand corner ie. | ||
the standard origin. | ||
""" | ||
ordered_data = [data[point] for point in points] | ||
shaped_data = np.reshape(ordered_data, (size, size), order='F') | ||
plotting_data = np.flipud(shaped_data) | ||
return plotting_data | ||
|
||
def plot(self, col_map='seismic', interpolation='none', title=None, colorbar=True, labels=True): | ||
"""Plot the results of the spatial tournament. | ||
|
||
Parameters | ||
---------- | ||
filename : str, optional | ||
The location and name that the resulting plot should be saved to. | ||
Defaults to the current directory with the name | ||
`Strategy and Probe.pdf` | ||
col_map : str, optional | ||
A matplotlib colour map, full list can be found at | ||
http://matplotlib.org/examples/color/colormaps_reference.html | ||
|
@@ -297,18 +321,36 @@ def plot(self, col_map='seismic', interpolation='none', title=None): | |
http://matplotlib.org/examples/images_contours_and_fields/interpolation_methods.html | ||
title : str, optional | ||
A title for the plot | ||
colorbar : bool, optional | ||
Choose whether the colorbar should be included or not | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. labels needs to be added here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also col_map and interpolation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. col_map and interpolation are already in there There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agghh. sorry - that was github folding lines on me and I hadn't noticed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nah, i've just got rid |
||
labels : bool, optional | ||
Choose whether the axis labels and ticks should be included | ||
|
||
Returns | ||
---------- | ||
figure : matplotlib figure | ||
A heat plot of the results of the spatial tournament | ||
""" | ||
size = int((1 / self.step) // 1) + 1 | ||
ordered_data = [self.data[point] for point in self.points] | ||
plotting_data = np.reshape(ordered_data, (size, size)) | ||
figure = plt.figure() | ||
plt.imshow(plotting_data, cmap=col_map, interpolation=interpolation) | ||
plt.axis('off') | ||
plotting_data = self.reshape_data(self.data, self.points, size) | ||
fig, ax = plt.subplots() | ||
cax = ax.imshow(plotting_data, cmap=col_map, interpolation=interpolation) | ||
|
||
if colorbar: | ||
max_score = max(self.data.values()) | ||
min_score = min(self.data.values()) | ||
ticks = [min_score, (max_score + min_score) / 2, max_score] | ||
fig.colorbar(cax, ticks=ticks) | ||
|
||
plt.xlabel('$x$') | ||
plt.ylabel('$y$', rotation=0) | ||
ax.tick_params(axis='both', which='both', length=0) | ||
plt.xticks([0, len(plotting_data) - 1], ['0', '1']) | ||
plt.yticks([0, len(plotting_data) - 1], ['1', '0']) | ||
|
||
if not labels: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test with |
||
plt.axis('off') | ||
|
||
if title is not None: | ||
plt.title(title) | ||
return figure | ||
return fig |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely this has to be colourbar? 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I know it's called colorbar in matplotlib, but still.....)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear - I'm not actually asking for any change here.