Hello. I have a task to connect the dots, but no matter how I try, nothing comes out of either a point or an empty graph.

How can you connect the points so that a network is formed?

And the question is not the topic, why the grid is not specified on the second graph? It is set only if it is explicit in a cycle to write.

Schedule

import matplotlib.pyplot as plt import numpy as np def polar(n,m,L=(0,0),scale=1): #n - кол-во кругов, m - кол-во точек, L - центр, scale - масштаб dr=1/n#Расстояние df=(2*np.pi)/m#Поворот for i in range(n+1): for k in range(m+1): z=i*dr*np.cos(k*df)+1j*i*dr*np.sin(k*df) w=(z-1)**2 plt.subplot(122) plt.plot(w.real*scale,w.imag*scale,'r.') circle=i*dr*np.cos(k*df)+1j*i*dr*np.sin(k*df) plt.subplot(121) plt.plot(circle.real*scale,circle.imag*scale,'r.') plt.axis('equal') plt.ylabel('Imaginary') plt.xlabel('Real') plt.grid(True) plt.show() polar(25,25) 
  • You want to connect the points in such a way that concentric circles are obtained on the first graph - did I understand you correctly? - MaxU
  • @MaxU Thank you very much, the question arose, why do not the points in the nested loop join into the grid? - Screliz Kotovskiy
  • one
    Because in the nested loop, at each step you draw only one point (on each graph), which you have nothing to connect. plot() can connect dots if there are more than one ... - MaxU
  • one
    @MaxU Thank you again for speed and clarification :) - Screliz Kotovskiy 4:34 pm

1 answer 1

If the task is to connect points belonging to concentric circles, then you can do this:

 def polar(n,m,L=(0,0),scale=1): #n - кол-во кругов, m - кол-во точек, L - центр, scale - масштаб dr=1/n#Расстояние df=(2*np.pi)/m#Поворот ax1 = plt.subplot(122) ax2 = plt.subplot(121) ax1.grid(True) ax2.grid(True) k = np.arange(m+1) for i in range(n+1): z=i*dr*np.cos(k*df)+1j*i*dr*np.sin(k*df) w=(z-1)**2 ax1.plot(w.real*scale,w.imag*scale,'.r-') circle=i*dr*np.cos(k*df)+1j*i*dr*np.sin(k*df) ax2.plot(circle.real*scale,circle.imag*scale,'.r-') plt.axis('equal') plt.ylabel('Imaginary') plt.xlabel('Real') plt.show() polar(25, 25) 

enter image description here

PS I got rid of the inner loop for two reasons:

  • for the convenience of connecting the points of one circle
  • to read the coordinates faster with " vectorized " NumPy methods