I have dataframe with points which include x, y and z coordinate of the point and "count", which is number between 1 and 187 for each data point. I would like to associate "count" with color gradient, with 1 being for instance color green, and 187 color red, and then to make scatter plot of data points with x, y and z coordinate, where color of every data point is coded information for the "count". I find code for color gradients very confusing, can you please help me?
EDIT: zelusp completely answered my question, thank you.
EDIT1: I wondered if I should write separate question, but as it's about the same piece of code maybe I could reach for answer just editing previous question. Recently I changed my laptop, and installed Ubuntu 18.04 on my new machine. This piece of code worked perfectly on Ubuntu 16.04, but doesn't work on my new machine. My code is:
cmap = plt.cm.rainbow
norm = mpl.colors.Normalize(vmin=np.min(df3.h_count), vmax=np.max(df3.h_count))
fig=plt.figure()
ax1=fig.add_subplot(111, projection='3d')
ax1.scatter(df3.zm_bin, df3.sfr_bin, 12.+np.log10(df3.medijana), s=10, c=cmap(norm(df3.h_count)), marker='o')
ax1.set_xlim(8,12.5)
ax1.set_xlabel('Log(Mz)')
ax1.set_ylabel('LogSFR') #treba invertovati
ax1.set_zlabel('12+log(Z)')
ax1.invert_yaxis()
sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)
sm.set_array([])
fig.colorbar(sm)
The error I'm getting is this:
Traceback (most recent call last):
File "load_subhalos.py", line 233, in <module>
ax1.scatter(df3.zm_bin, df3.sfr_bin, 12.+np.log10(df3.medijana), s=10, c=cmap(norm(df3.h_count)), marker='o')
File "/usr/local/lib/python2.7/dist-packages/matplotlib/colors.py", line 938, in __call__
result, is_scalar = self.process_value(value)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/colors.py", line 924, in process_value
result = np.ma.array(data, mask=mask, dtype=dtype, copy=True)
File "/usr/local/lib/python2.7/dist-packages/numpy/ma/core.py", line 6358, in array
ndmin=ndmin, shrink=shrink, order=order)
File "/usr/local/lib/python2.7/dist-packages/numpy/ma/core.py", line 2784, in __new__
order=order, subok=True, ndmin=ndmin)
TypeError: float() argument must be a string or a number
I didn't change anything in the code, the only change is new machine and OS. Do you know why I'm having this problem?