matplotlib-users

 [Matplotlib-users] int to matplotlib.colormaps value From: AlsCdz - 2008-12-16 02:23:19 ```Hello, i need you help! I want to draw a plot with circles, which are coloured according to size. So let's say we have a list=[1,3,5,7] that would give me four circles, first very small, second bigger and so on. Now i need a way to "convert" integers to color value which would match matplotlib.cm.spectral values. I hope you understand what i want to do, something like: ( http://zoonek2.free.fr/UNIX/48_R/g208.png http://zoonek2.free.fr/UNIX/48_R/g208.png ) I posted only the "important" bits of code: listData = [[2,5,1],[2,4,15],[13,2,1],[1,10,2]] cmap = mpl.cm.spectral norm = mpl.colors.Normalize(vmin=1, vmax=15) listA = ([i for i in range(len(listData))]) for a in range(len(listData)): listB = ([a for i in range(len(listData[0]))]) area = ([listData[a][i]*100 for i in range(len(listData[a]))]) color = ([listData[a][i]*100 for i in range(len(listData[a]))]) plt.scatter(listA,listB,s=area, cmap=cmap, c=??what to put here???) cb1 = mpl.colorbar.ColorbarBase(ax1, cmap=cmap, norm=norm, orientation='vertical') I hope someone could help me! thank you very much ales -- View this message in context: http://www.nabble.com/int-to-matplotlib.colormaps-value-tp21026017p21026017.html Sent from the matplotlib - users mailing list archive at Nabble.com. ```
 Re: [Matplotlib-users] int to matplotlib.colormaps value From: Eric Firing - 2008-12-16 18:22:06 ```AlsCdz wrote: > Hello, i need you help! > I want to draw a plot with circles, which are coloured according to size. So > let's say we have a list=[1,3,5,7] that would give me four circles, first > very small, second bigger and so on. > Now i need a way to "convert" integers to color value which would match > matplotlib.cm.spectral > values. > > I hope you understand what i want to do, something like: ( > http://zoonek2.free.fr/UNIX/48_R/g208.png > http://zoonek2.free.fr/UNIX/48_R/g208.png ) > > I posted only the "important" bits of code: > > > listData = [[2,5,1],[2,4,15],[13,2,1],[1,10,2]] > cmap = mpl.cm.spectral > norm = mpl.colors.Normalize(vmin=1, vmax=15) > > listA = ([i for i in range(len(listData))]) > for a in range(len(listData)): > listB = ([a for i in range(len(listData[0]))]) > area = ([listData[a][i]*100 for i in range(len(listData[a]))]) > color = ([listData[a][i]*100 for i in range(len(listData[a]))]) > plt.scatter(listA,listB,s=area, cmap=cmap, c=??what to put here???) > > cb1 = mpl.colorbar.ColorbarBase(ax1, cmap=cmap, norm=norm, > orientation='vertical') > > > > I hope someone could help me! > > thank you very much > ales radius = np.arange(10) area = np.pi*radius**2 x = np.random.rand(10) y = np.random.rand(10) cmap = plt.get_cmap('spectral') plt.scatter(x, y, s=area, c=radius, cmap=cmap) plt.colorbar() I think the above illustrates what you need. Eric ```
 Re: [Matplotlib-users] int to matplotlib.colormaps value From: Eric Firing - 2008-12-17 06:11:41 ```Aleš Čadež wrote: > First of all, thanks for helping me. What you wrote is not exactly what > i need. Let me show you an example: > > > > > > Now here are different size circles (biggest grey is »size=8«, other two > are »size=4«, and blue circles are size 2 and 1). I would like to color > them according to colorbar (size=1 = blue, size=4 = green, size = 8 = red) > > > > In your example there is random color to the circle size, i want the > size to match the color. I think my randomizing of the position is throwing you off. Here is a version that I think makes it more clear that the size (radius) is matching the color: radius = np.arange(10) area = np.pi*radius**2 x = radius y = area cmap = plt.get_cmap('spectral') plt.scatter(x, y, s=area, c=radius, cmap=cmap) plt.colorbar() Eric ```