Skip to content

Commit

Permalink
better colormap
Browse files Browse the repository at this point in the history
  • Loading branch information
zhensydow committed Jun 23, 2015
1 parent 3f31404 commit 776dc15
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions python/pyplot_colordot.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
"""Test with colormaps"""
#-------------------------------------------------------------------------------
import numpy as np
import matplotlib.pyplot as plt


#-------------------------------------------------------------------------------
N = 100
# create random points from [0..1]
#x = np.random.rand( N )
x = np.linspace( 0, 10, num=N )
y = np.random.rand( N )

# create random areas from 0 to 10
area = np.pi * (10 * np.random.rand(N))**2

def test( colormap ):
# create a colormap from [0..1] with colormap
# colormap can be 'hot, 'gray', 'winter', 'Oranges', 'Greens', 'brg' ...
# http://matplotlib.org/examples/color/colormaps_reference.html
cmap = plt.get_cmap( colormap )
scalar = plt.cm.ScalarMappable( cmap=cmap )
color = scalar.to_rgba( y )

plt.scatter( x, y, s=area, c=color, alpha=0.5 )
def test(size, colormap):
"""Create a colormap from [0..1] with colormap
colormap can be 'hot, 'gray', 'winter', 'Oranges', 'Greens', 'brg' ...
http://matplotlib.org/examples/color/colormaps_reference.html
"""

# create random points from [0..1]
#x = np.random.rand(N)
xvals = np.linspace(0, 10, num=size)
yvals = np.random.rand(size)

# create random areas from 0 to 10
areas = np.pi * (10 * np.random.rand(size))**2

cmap = plt.get_cmap(colormap)
scalar = plt.cm.ScalarMappable(cmap=cmap)
colors = scalar.to_rgba(yvals)

plt.scatter(xvals, yvals, s=areas, c=colors, alpha=0.5)
plt.show()

#-------------------------------------------------------------------------------
if __name__=="__main__":
test( 'hot' )
if __name__ == "__main__":
test(100, 'hot')

#-------------------------------------------------------------------------------

0 comments on commit 776dc15

Please sign in to comment.