0

My starting point is How to modify 2d Scatterplot to display color based off third array in csv file?

I have a dataset

x y time 1 2 10:24:30 2 1 15:30:12

So the idea is at the point of time 10:24:30 the object is at location (1,2).

I want to display a scatter plot with the color of points as time info (right now, hour is enough, i.e. there will be 24 colors according to 24 hours per day).

How could I do that, and also display a legend to explain what color corresponds to what time?

Minimal example:

fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(111)
ax.set_title("X vs Y AVG",fontsize=14)
ax.set_xlabel("XAVG",fontsize=12)
ax.set_ylabel("YAVG",fontsize=12)
ax.grid(True,linestyle='-',color='0.75')
x = np.random.random(30)
y = np.random.random(30)
z = np.random.random(30) * 24

# scatter with colormap mapping to z value
ax.scatter(x,y,s=20,c=z, marker = 'o', cmap = cm.jet );

plt.show()

The color

mommomonthewind
  • 4,390
  • 11
  • 46
  • 74
  • Provide some [mcve]. Using the `Normalize` function with a categorical color map would do the job. – tupui Sep 14 '17 at 06:06
  • What exactly is the problem? Your script does that. Do you need to extract the values out of the time string? `15:30:12` ? – Joe Sep 14 '17 at 07:02
  • But it is rather difficult to get a categorical / qualitative colormap with 24 different colors. up to 12 here: http://colorbrewer2.org/#type=qualitative&scheme=Accent&n=3 these are the default ones: http://matplotlib.org/users/colormaps.html#qualitative – Joe Sep 14 '17 at 07:06
  • Hi, the problem is display the legend that explains the color map. – mommomonthewind Sep 14 '17 at 08:42

0 Answers0