Matplotlib cmap values must be between 0-1
Question: I am having trouble with the code below:

    
    
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    import numpy as np
    from pylab import *
    import sys
    
    
    s = (('408b2e00', '24.21'), ('408b2e0c', '22.51'), ('4089e04a', '23.44'), ('4089e04d', '24.10'))
    
    temp = [x[1] for x in s]
    print temp
    
    figure(figsize=(15, 8))
    
    pts = [(886.38864047695108, 349.78744809964849), (1271.1506973277974, 187.65500904929195), (1237.272277227723, 860.38363675077176), (910.58751197700428, 816.82566805067597)]
    
    x = map(lambda x: x[0],pts) # Extract the values from pts
    y = map(lambda x: x[1],pts) 
    t = temp
    
    result = zip(x,y,t)
    
    img = mpimg.imread('floor.png')
    imgplot = plt.imshow(img, cmap=cm.hot)
    scatter(x, y, marker='h', c=t, s=150, vmin=-20, vmax=40)
    print t
    
    # Add cmap
    colorbar()
    show()
    

Given the temperature in s - I am trying to set the values of the cmap so I
can use temperatures between -10 and 30 instead of having to used values
between 1 and 0. I have set the vmin and vmax values but it still gives me the
error below:

    
    
    ValueError: to_rgba: Invalid rgba arg "23.44" to_rgb: Invalid rgb arg "23.44" gray (string) must be in range 0-1
    

I have use earlier code to simplify the problem and have been successful. This
example below works and shows what I am trying to (hopefully) do:

    
    
    import matplotlib.pyplot as plt
    import matplotlib.image as mpimg
    import numpy as np
    from pylab import *
    
    figure(figsize=(15, 8))
    # use ginput to select markers for the sensors
    matplotlib.pyplot.hot()
    
    markers = [(269, 792, -5), (1661, 800, 20), (1017, 457, 30)]
    x,y,t = zip(*markers)
    
    img = mpimg.imread('floor.png')
    imgplot = plt.imshow(img, cmap=cm.hot)
    scatter(x, y, marker='h', c=t, s=150, vmin=-10, vmax=30)
    
    colorbar()
    show()
    

Any ideas why only the second solution works? I am working with dynamic values
i.e inputs from mysql and user selected points and so the first solution would
be much easier to get working later on (the rest of that code is in this
question: [Full program
code](http://stackoverflow.com/questions/15888693/python-matplotlib-and-mysql-
and-ginput) )

Any help would be great. Thanks!


Answer: You are handing in strings instead of floats, change this line:

    
    
    temp = [float(x[1]) for x in s]
    

`matplotlib` tries to be good about guessing what you mean and lets you define
gray as a string of a float between [0, 1] which is what it is trying to do
with your string values (and complaining because it is not in than range).

