user2134116
user2134116

Reputation: 27

Can I have random points as well as Circles on a plot in python?

as an example

import matplotlib.pyplot as plt
import random
pointx = random.random()
pointy = random.random()
plt.scatter(pointx , pointy)

circle = plt.Circle((.5,.55) , .07,color='b')
fig = plt.gcf()
fig.gca().add_artist(circle)

plt.show()

I only get the random xy point when I do this but when I remove the random xy point I get the circle. What can I do so I have both on one plot?

Upvotes: 0

Views: 984

Answers (1)

Octopus
Octopus

Reputation: 8325

I think your circle is being plotted on top of your point try reversing it.

import matplotlib.pyplot as plt
import random

circle = plt.Circle((.5,.55) , .07,color='b')
fig = plt.gcf()
fig.gca().add_artist(circle)

pointx = random.random()
pointy = random.random()
plt.scatter(pointx , pointy)

plt.show()

Upvotes: 1

Related Questions