2010/12/19 Pawel <pawe...@gmail.com>: > Hi, > > I am a new user of matplotlib so maybe my question is elementary, but > have not been able to find an answer to my problem in the archive. > > I would like to make a 2D plot of colored points of 3D data (clusters). > My data looks like this: > > 11837.2120 -0.0858 2.0000 > 23975.2120 -0.0672 2.0000 > 37609.2120 -0.0306 2.0000 > 53263.9800 -0.0690 2.0000 > 72106.6760 0.2708 1.0000 > 92674.6760 -0.0129 3.0000 > 116758.676 -0.1245 3.0000 > ... > > So I need to plot the first and second column as points on the x-y axis > and color the points according to the numbers in the third column (which > are integers ranging from 1 to5). > > I'd appreciate any help. I realize something so typical should be > somewhere in the documentation but I was not able to find it.
Try this: import numpy as np import matplotlib.pyplot as plt from matplotlib.colors import ListedColormap x, y, z = np.loadtxt('data.txt', unpack=True) cmap = ListedColormap(['b', 'g', 'r', 'c', 'm']) plt.scatter(x, y, c=z, cmap=cmap, vmin=1, vmax=5) plt.show() You'll need to use a single space as column delimiter in your data file or deal with more loadtxt arguments. If your z data were color specifications you could just use plt.scatter(x, y, c=z) as stated in the scatter docstring. Converting arbitrary data to color specifications is the non trivial issue here. You can write your own code to do this or use colormaps. Goyo ------------------------------------------------------------------------------ Learn how Oracle Real Application Clusters (RAC) One Node allows customers to consolidate database storage, standardize their database environment, and, should the need arise, upgrade to a full multi-node Oracle RAC database without downtime or disruption http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users