0

I have a function that generates animated dots, here is the part that causes a problem :

dots = [dot() for i in range(N)] 

fig = plt.figure()  
ax = plt.axes(xlim=(0, 10), ylim=(0, 10)) 
d, = ax.plot([dot.x for dot in dots],[dot.y for dot in dots], 'ro', markersize=3)`

so, dot is the name of my class of objects et dots is the list that contains N objects. Every dot is plotted in red.

What I want to do is to plot, for example, N-1 dots in red and one dot in blue, is it possible with the command ax.plot ?

Thanks for your help

Jkev
  • 177
  • 1
  • 2
  • 8

1 Answers1

0

Yes, it is possible. You will need to segregate the points into two collections; there are a number of ways to do this; here I chose to extract one point from the list. then you must plot each collections separately on the same canvas.

import random
import matplotlib.pyplot as plt


class Dot(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y

def get_random_dot(dots):
    random.shuffle(dots)
    return dots.pop()

num_dots = 10
dots = [Dot(random.random(), random.random()) for _ in range(num_dots)] 

fig = plt.figure()  
ax = plt.axes() 

selected_dot = get_random_dot(dots)
d, = ax.plot([dot.x for dot in dots],[dot.y for dot in dots], 'r.')
f, = ax.plot(selected_dot.x, selected_dot.y, color='blue', marker='o', linewidth=3)

plt.show()

enter image description here

Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80