-1

I have a created a circle using the matplotlib library. Now in an infinite loop on every user input of x and y, I want to plot the point on the graph. How can I do this withour replotting everything again on user input?

This is what I have tried but this is not working

import numpy as np 
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['toolbar'] = 'None'

fig = plt.figure()
angle = np.linspace( 0 , 2 * np.pi , 1500 ) 
 
radius = 5
 
figure, axes = plt.subplots( 1 ) 

plt.title( 'Ring' )  
plt.box(False)
plt.axis('off')

while True:
    x = radius * np.cos( angle ) 
    y = radius * np.sin( angle ) 
    axes.plot( x, y ) 
    axes.set_aspect( 1 ) 
    # this is the part which I need to update without actually replotting my plot again
    i_line = input("Enter the points ").split()
    i_x, i_y = int(i_line[0]), int(i_line[1])
    plt.scatter(i_x, i_y, color='red')
    plt.show()
GBDGBDA
  • 636
  • 1
  • 6
  • 20
  • The first four lines of that `while` loop should be outside the loop. – ddejohn May 21 '22 at 16:57
  • You can also directly unpack your input: `x, y = map(int, input().split())` -- although I'd suggest wrapping that in a `try`/`except` – ddejohn May 21 '22 at 16:58
  • Your usage of `plt.show()` is blocking, so your loop will only run once. First try to use `plt.show(block=False)`. This is a good starting point. Then you definitely want to use `threading.Thread`. – Thyebri May 21 '22 at 17:04
  • How exactly can I use threading to update my graph in real time on user input – GBDGBDA May 21 '22 at 17:10
  • You may want to check this thread: https://stackoverflow.com/questions/11874767/ – ddejohn May 21 '22 at 17:36

0 Answers0