Last active
September 29, 2021 13:19
-
-
Save cbrnr/0cc95f2c2002e72a6698f032418bd712 to your computer and use it in GitHub Desktop.
Visualization of approximate number system
This file contains hidden or 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
import matplotlib.pyplot as plt | |
from matplotlib.animation import FuncAnimation | |
import numpy as np | |
from scipy.stats import norm | |
fps = 25 | |
fig, ax = plt.subplots(figsize=(8, 6)) | |
x = np.linspace(0, 20, 1000) | |
ax.set(title="Approximate representation of numerical quantities", | |
xlabel="Objective number", ylabel="Subjective magnitude") | |
ax.set_xticks(range(0, 22, 2)) | |
ax.set_yticklabels([]) | |
ax.spines["top"].set_visible(False) | |
ax.spines["right"].set_visible(False) | |
lines = [] | |
color = plt.cm.viridis(np.linspace(0, 0.75, 7)) | |
for i, n in enumerate(range(2, 16, 2)): | |
line = ax.plot(x, norm(loc=n, scale=0.2 * (n - 1)).pdf(x), color=color[i]) | |
lines.append(line) | |
line = ax.plot(x, norm(loc=8, scale=0.2 * 7).pdf(x), color=color[3], | |
linestyle="dashed", visible=False) # shown after second 2 | |
lines.append(line) | |
def update(frame): | |
if 0 <= frame < 2 * fps: # first two seconds | |
for line in lines[:-1]: | |
line[0].set_visible(True) | |
else: # after second two | |
for i, line in enumerate(lines): | |
if i == 3: # number 8 | |
scale = 0.2 * (7 - frame / (3 * fps)) | |
line[0].set_data(x, norm(loc=8, scale=scale).pdf(x)) | |
line[0].set_zorder(5) | |
line[0].set_visible(True) | |
elif i == 7: # also number 8, but dashed | |
line[0].set_visible(True) | |
else: # all other numbers | |
line[0].set_visible(False) | |
animation = FuncAnimation(fig, update, frames=np.arange(0, 12 * fps), | |
interval=1000/fps, repeat=False) | |
plt.show() |
This file contains hidden or 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
import matplotlib.pyplot as plt | |
import numpy as np | |
from scipy.stats import norm | |
x = np.linspace(0, 20, 1000) | |
color = plt.cm.gray(np.linspace(0, 0.75, 7)) | |
fig, ax = plt.subplots() | |
for i, n in enumerate(range(2, 16, 2)): | |
ax.plot(x, norm(loc=n, scale=0.2 * (n - 1)).pdf(x), color=color[i]) | |
ax.set(title="Approximate representation of numerical quantities", | |
xlabel="Objective number", ylabel="Subjective magnitude") | |
ax.set_xticks(range(0, 22, 2)) | |
ax.set_yticklabels([]) | |
ax.spines["top"].set_visible(False) | |
ax.spines["right"].set_visible(False) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment