-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_results.py
More file actions
29 lines (22 loc) · 1.03 KB
/
Copy pathplot_results.py
File metadata and controls
29 lines (22 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import matplotlib.pyplot as plt
def plot_results(result, numbers, shots=1024):
sorted_result = dict(sorted(result.items()))
bitstrings = list(sorted_result.keys())
# Dynamic threshold inversely proportional to the number of possible outputs
mean_occurrence = shots / 2**len(numbers)
threshold = mean_occurrence * 3
subsets = []
for bitstring in bitstrings:
# bitstring is in reverse order
indices = [i for i, bit in enumerate(bitstring[::-1]) if bit == '1']
values = [numbers[i] for i in indices]
subsets.append(f"{values}\n(idx: {bitstring})")
occurrences = list(sorted_result.values())
# Only display the labels of subsets that occur more times than the threshold
display_labels = [label if val > threshold else "" for label, val in zip(subsets, occurrences)]
plt.figure(figsize=(15, 9))
plt.bar(subsets, occurrences)
plt.xlabel("Values")
plt.xticks(ticks=range(len(subsets)), labels=display_labels, rotation=90)
plt.ylabel("Occurrences")
plt.show()