October 19, 2024
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl


data = np.random.rand(100, 2)
indices = np.arange(data.shape[0])

norm = mpl.colors.Normalize(vmin=0, vmax=data.shape[0])
colors = plt.cm.viridis(norm(indices))


fig, ax = plt.subplots()
scatter = ax.scatter(data[:, 0], data[:, 1], c=colors)
cbar = plt.colorbar(scatter, ax=ax, label='Index')


ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')

fig.savefig("test.png")