For a set of points generated,
- How do I plot a circle with different colour at each point?
- How do I show the center point of the circle even when circle is filled?
Purpose: I have a set of GPS points and I want to plot the line through these points and for each point, draw a circle of some radius with that point as the center. The colour differentiation is to distinguish the various points and circles that are plotted.
At the moment, I'm only able to plot the points and plot circles at each point with 1 particular colour. (I read other posts about using colour maps and RGB's but unfortunately, I was not able to implement it)
Image below shows the expected plot of circles with different colours (Any colour can be used) for each plot point with the point on the circles representing the center of each circle (At each plot point basically).
import matplotlib.pyplot as plt
import numpy as np
xx = np.linspace(0,10,5)
yy = np.linspace(30,60,5)
zz = np.vstack((xx,yy)).T
fig = plt.figure(1, figsize=(12, 5))
ax = fig.add_subplot(111, aspect='equal')
plt.plot(xx,yy,zorder=2)
plt.scatter(xx,yy,zorder=1)
for i in range(0,len(xx)):
circle1 = plt.Circle(zz[i], 4, color='g', fill=True)
plt.gca().add_patch(circle1)
plt.autoscale()
plt.show()
UPDATE
As @busybear suggested, we can use the Patch Collection to plot the circles of different colours. This implementation works perfectly for the defined set of points. However, this was only done for 5 test data points. For more data points, we repeat the colours defined or there are no circles plotted.
Is there a way to also define a suitable colour spectrum/ colour table (Maybe with hex values or an rgb table with varying intensity) so we have varying colours for the circles?
xx = np.linspace(0,10,10)
yy = np.linspace(30,60,10)
zz = np.vstack((xx,yy)).T
fig = plt.figure(1, figsize=(12, 5))
ax = fig.add_subplot(111, aspect='equal')
plt.plot(xx,yy,zorder=2)
plt.scatter(xx,yy,zorder=1)
circles = []
for i, c in zip(range(0,len(xx)), 'rgbmkrgbmk'):
circles.append(plt.Circle(zz[i], 3, color=c, fill=True))
coll = PatchCollection(circles, match_original=True, zorder=0)
ax.add_collection(coll)
plt.autoscale()
plt.show()
New output (With Scatterplot method):