I am attempting to plot a color bar to represent color-coded scatterplot dots based on conditional statements to which ranges of values within a pandas dataframe column are assigned specific colors. I am able to successfully create the plot, but I have not been able to get the color bar to show up on the plot. Below is some context of what I am doing to show where the issue arises.
ws = []
for i in ws_max['max_ws']:
if i < 34:
color = 'lightblue'
elif i >= 34 and i < 64:
color = 'green'
elif i >= 64 and i < 83:
color = 'yellow'
elif i >= 83 and i < 135:
color = 'orange'
else:
color = 'r'
ws.append(color)
winds = plt.scatter(lon_mean['mean_lon'],lat_mean['mean_lat'],s=200,color=ws,edgecolors='k',zorder=3)
plt.colorbar(winds)
When I run the code above I get this traceback: TypeError: You must first set_array for mappable
, which I attempted to address using this link Scatter plot colorbar - Matplotlib but I was unsuccessful.