0

I'm totally new to pythons graph visualization tools and I'm trying to show a scatter plot. The problem is that I can't seem to be able to obtain colors for my points different from grayscale values. This is my code:

cmap = cm.get_cmap('Spectral')
cat_length_1 = len(categories[cat1])
cat_length_2 = len(categories[cat2])
fig = plt.figure()
ax = fig.add_subplot(111)
col = [0.123, 2598.35, 32.66, 669.3]
df.plot(cat1, cat2, kind='scatter', ax=ax, s=65, c =df[cat1] , linewidth=0, colormap=cmap)
plt.xticks(np.arange(cat_length_1 + 1), categories[cat1])
plt.yticks(np.arange(cat_length_2 + 1), categories[cat2])

if label_list != None:
    for k, v in df.iterrows():
        if k in label_list:
            ax.annotate(k, (v[cat1], v[cat2]), xytext=(rnd.randint(-30, 30), rnd.randint(-30, 30)), textcoords='offset points',
                    family='sans-serif', fontsize=12, color='darkslategrey',
                    arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))

plt.tight_layout()
plt.show()

which provides this result: enter image description here

I would like to color my points with all different colors based on the x axis value (but even random colors are ok).

Thanks.

ClonedOne
  • 107
  • 2
  • 10

1 Answers1

0

The colormaps take certain input values (e.g. 0-255 in RGB), so the DataFrame column that you are using to assign the colors needs to correspond to these input values, ie. you need to map your categories to any of the accepted color values. See here and here for more implementation detail.

Community
  • 1
  • 1
Stefan
  • 41,759
  • 13
  • 76
  • 81