I'm trying to plot a set of polygons with a colormap. I set up a ScalarMappable object and generate polygon colors from that ScalarMappable, but when I try to add a colorbar, I get the error:
TypeError: You must first set_array for mappable
The documentation for "set_array" doesn't really say anything, so I'm not at all clear what it is doing, whether I need to give it values, and if I do, what they will be doing.
Can anyone please explain what set_array does, and how I should deal with this?
plt.clf()
fig, ax = plt.subplots(1,1)
# Set color mappable
range_min = df.col1.min()
range_max = df.col1.max()
cmap = matplotlib.cm.ScalarMappable(
norm = mcolors.Normalize(range_min, range_max),
cmap = plt.get_cmap('binary'))
for i in polygonDict.keys():
ax.add_patch(ds.PolygonPatch(polygonDict[i], fc = cmap.to_rgba(df.col1.loc[i])))
fig.colorbar(cmap, ax = ax)