I am solving an optimization problem. There are n iterations and at each one I have a point x_n=[x_n1, x_n2]. I want to plot the iterates x_n so that as n increases the color of the points gets dark or lighter or whatever. Currently I can plot the iterates but they are all the same color so i cannot tell which points correspond to higher values of n.
The variable x_test is an array which contains all the iterates from x_0 to x_n. Here is my code to plot it:
pl.scatter(x_test[:,0], x_test[:,1])
pl.show()
I have found a lot of info on how to color graphs but not in the way I am desiring, where each point corresponds to a different light/darkness.
Here is a minimal, complete, verifiable example:
import numpy as np
import pylab as pl
x = np.array([[1,1],[1,2],[1,3],[2,4]])
pl.plot(x[:,0], x[:,1])
This gives the scatter plot of the points in the array x but I need them to each be a different color corresponding to the position in x, i.e. [1,1] should be the lightest, then [1,2] will be slightly dark, etc until [2,4] is the darkest.
edit: here is the solution I went with:
scaled_itera = np.array(range(x_test.shape[0]))/(float(x_test.shape[0])-1)
colors = pl.cm.coolwarm(scaled_itera)
pl.scatter(x_test[:,0], x_test[:,1], color=colors)
pl.show()