-
Notifications
You must be signed in to change notification settings - Fork 7
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
update plot scripts to work with Python 3 changes; improve heatmap legibility #10
Open
milthorpe
wants to merge
10
commits into
UoB-HPC:main
Choose a base branch
from
milthorpe:heatmap2024
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2480e28
use portable interpreter line; updates for Numpy, Matplotlib deprecat…
milthorpe c6934d2
data-dependent heatmap size
milthorpe 351c55b
replace removed DataFrame.append with pd.concat; return 0 for geomean…
milthorpe 277aead
fix pandas concat, delimiter issues
milthorpe e87190f
mask out non-values, use viridis for colorblind viewing
milthorpe b714add
heatmap: display percentages to one decimal place
milthorpe af1a550
colour labels white on dark background
milthorpe 0ce563d
Pandas: use separator but not delimiter for CSV; use concat instead o…
milthorpe 1bc67cb
updates to heatmap for percentage, color for range
milthorpe cbea2ac
cleanup
milthorpe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/python | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2020 Performance Portability authors | ||
# SPDX-License-Identifier: MIT | ||
|
||
|
@@ -37,6 +37,8 @@ | |
|
||
# Get the list of headings from first row | ||
headings = data.fieldnames[1:] | ||
if len(headings) < 1: | ||
raise Exception("No input fields found") | ||
|
||
# Name of the series, what the rows in the CSV actually are | ||
series_key = data.fieldnames[0] | ||
|
@@ -47,6 +49,13 @@ | |
heatmap = [] # empty, to be populated by reading the input file | ||
labels = [] # labels to display in each heatmap entry | ||
|
||
plt.rc('text', usetex=True) | ||
plt.rc('font', family='serif', serif='Times') | ||
fig, ax = plt.subplots() | ||
|
||
max_all = -np.inf | ||
min_all = np.inf | ||
|
||
for result in data: | ||
def get(name): | ||
str = result[name] | ||
|
@@ -58,7 +67,7 @@ def get(name): | |
def eff(a, b): | ||
if isinstance(a, float) and isinstance(b, float): | ||
return float(100.0 * (a / b)) | ||
elif a is '-' or b is '-': | ||
elif a == '-' or b == '-': | ||
return float(-100.0) | ||
else: | ||
return float(0.0) | ||
|
@@ -70,7 +79,9 @@ def eff(a, b): | |
continue | ||
|
||
series.append(result[series_key]) | ||
heatmap.append([r if isinstance(r, float) else 0.0 for r in raw]) | ||
heatmap.append([r if isinstance(r, float) else float('nan') for r in raw]) | ||
max_all = max(max_all, max(heatmap[len(heatmap)-1])) | ||
min_all = min(min_all, min(heatmap[len(heatmap)-1])) | ||
|
||
l = [] | ||
for i in range(len(raw)): | ||
|
@@ -79,57 +90,61 @@ def eff(a, b): | |
else: | ||
if args.percent: | ||
if plt.rcParams['text.usetex']: | ||
l.append('%.0f\\%%' % (raw[i] / args.factorize)) | ||
if raw[i] / args.factorize < 100.0: | ||
l.append('%.1f\\%%' % (raw[i] / args.factorize)) | ||
else: | ||
l.append('%.0f\\%%' % (raw[i] / args.factorize)) | ||
else: | ||
l.append('%.0f%%' % (raw[i] / args.factorize)) | ||
if raw[i] / args.factorize < 100.0: | ||
l.append('%.1f%%' % (raw[i] / args.factorize)) | ||
else: | ||
l.append('%.0f%%' % (raw[i] / args.factorize)) | ||
else: | ||
if raw[i] / args.factorize < 100.0: | ||
if not raw[i].is_integer(): | ||
l.append('%.1f' % (raw[i] / args.factorize)) | ||
else: | ||
l.append('%.0f' % (raw[i] / args.factorize)) | ||
labels.append(l) | ||
|
||
plt.rcParams.update({ | ||
"font.family": "serif", # use serif/main font for text elements | ||
"text.usetex": False, # use inline math for ticks | ||
"pgf.rcfonts": False, # don't setup fonts from rc parameters | ||
}) | ||
fig, ax = plt.subplots() | ||
fig.set_size_inches(4, 3) | ||
|
||
# Set color map to match blackbody, growing brighter for higher values | ||
colors = "gist_heat" | ||
fig.set_figwidth(fig.get_figwidth() / 5 * len(l)) | ||
colors = "viridis" | ||
Comment on lines
109
to
+111
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. Is the comment above this still accurate? |
||
if not args.higher_is_better: | ||
colors = colors + "_r" | ||
cmap = plt.cm.get_cmap(colors) | ||
x = np.arange(7) | ||
y = np.arange(11) | ||
cmap = plt.get_cmap(colors) | ||
x = np.arange(len(l)+1) | ||
y = np.arange(len(heatmap)+1) | ||
masked = np.ma.masked_where(np.isnan(heatmap),heatmap) | ||
cmesh = plt.pcolormesh( | ||
x, | ||
y, | ||
np.array(heatmap), | ||
masked, | ||
cmap=cmap, | ||
edgecolors='k', | ||
vmin=1.0E-6) | ||
ax.set_yticks(np.arange(len(heatmap)) + 0.5, minor=False) | ||
ax.set_xticks(np.arange(len(heatmap[0])) + 0.5, minor=False) | ||
|
||
ax.set_yticklabels(series) | ||
ax.set_yticklabels(series, fontsize='xx-large') | ||
for i in range(len(headings)): | ||
heading = headings[i].replace('_', r'\_') | ||
if not plt.rcParams['text.usetex']: | ||
heading = heading.replace(r"\%", "%") | ||
headings[i] = heading | ||
ax.set_xticklabels(headings, rotation=45, ha="right", rotation_mode="anchor") | ||
headings[i] = headings[i].replace('_', '\_') | ||
ax.set_xticklabels(headings, fontsize='xx-large', rotation=45) | ||
plt.gca().invert_yaxis() | ||
|
||
# Add colorbar | ||
plt.colorbar(cmesh) | ||
|
||
one_third = max_all / 3.0 | ||
two_thirds = 2.0 * max_all / 3.0 | ||
|
||
# Add labels | ||
for i in range(len(headings)): | ||
for j in range(len(series)): | ||
plt.text(i + 0.9, j + 0.5, labels[j][i], | ||
ha='right', va='center', color='#b9c5bf', fontsize='small') | ||
labelcolor = 'black' | ||
if args.higher_is_better and heatmap[j][i] < one_third: | ||
labelcolor='white' | ||
elif not args.higher_is_better and heatmap[j][i] > two_thirds: | ||
labelcolor='white' | ||
plt.text(i + 0.5, j + 0.55, labels[j][i], | ||
ha='center', va='center', color=labelcolor, weight='bold', size='xx-large') | ||
|
||
plt.savefig(args.output, bbox_inches='tight') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Previously this branch was being used to prevent
geometric_mean
from being imported with Python versions that didn't exist. I don't think this new code will work with older Python versions. That may be okay, but I'm not sure what @tomdeakin plans for compatibility here.