I would like to achieve two objectives with matplotlib:
- Dynamically update a scatter plot
- Slowly make the points that were plotted at previous iterations more transparent.
Currently, I am able to achieve the opposite goal using colormaps. That is, I can plot points over time but the recent points look more transparent.
Is it possible to get a 'fading' effect on matplotlib using cmap or other tools? Thanks! My code is below:
def plotter_fader(iterations = 100, stay_open = True):
# Set up plot
fig, ax = plt.subplots()
x_data = []
y_data = []
plt.ion()
fig = plt.figure()
ax = fig.add_subplot(111)
t_vals = np.linspace(0,1, iterations)
cmap = (0.09803921568627451, 0.09803921568627451, 0.09803921568627451, .05)
for t in t_vals:
# Get intermediate points
intermediate = (1-t)*A + t*B
new_xvals, new_yvals = ... #Get these through some process
x_vals.extend(new_xvals)
y_vals.extend(new_yvals)
# Put new values in your plot
plt.plot(x_vals, y_vals, '.', color = cmap)
# Recompute plot limits
ax.relim()
# Set title and wait a little bit for 'smoothness'
ax.set_xlabel('X Axis', size = 12)
ax.set_ylabel('Y Axis', size = 12)
ax.set_title('Time: %0.3f' %t)
ax.autoscale_view()
fig.canvas.draw()
time.sleep(0.005)
# Stay open after plotting ends
while stay_open:
pass