python - Matplotlib - color as third variable for already normalized data - not in grayscale -
i've searched haven't been able find answer - how implement color third variable in matplotlib if data normalized? data in range 0-1 , produces graph in grayscale, 1 fades say, blue yellow, blue = 1, sort of green values 0.5 , yellow values around 0.
my code reads:
line in lines: if line: x1.append(line.split()[0]) y1.append(line.split()[1]) z1.append(line.split()[4]) xv = np.array(x1) yv = np.array(y1) zv = np.array(z1) plt.scatter(xv, yv, c=zv, cmap=?)
i've tried sorts of variations, including no_norm best can still grayscale plot... don't think using vmin , vmax going down right route, , i've tried doing
cmap = plt.cm.get_cmap('autumn') plt.scatter(xv, yv, c=cmap(zv))
but produces error:
typeerror: cannot cast array data dtype('s11') dtype('int64') according rule 'safe'
thanks in advance, anna
after reading @tcaswell's comment, found this page. solutions seems way more elegant. can pick cmap want page , use like:
import matplotlib.pyplot plt xs = range(11) ys = [0] * 11 colors = [ * 0.1 in range(11) ] plt.scatter(xs, ys, s=600, c = colors, cmap='ylgnbu') plt.colorbar() plt.show()
Comments
Post a Comment