python неправильная точка привязки линии графика - PullRequest
0 голосов
/ 08 июля 2020

Как вы можете видеть, matplotlib связывает несколько неправильных точек с помощью plt.plot. файл данных Как я могу улучшить свою кривую? Могу ли я дать ему минимальный интервал между двумя точками? Поможет ли сортировка моих баллов получить хорошую кривую? Я могу отсортировать точки оси X, но ось Y кажется более сложной.

Спасибо.

import numpy as np
from matplotlib import pyplot as plt

File = "crown" + str(0) + str(0.01)
data = np.loadtxt(File)
data = data.reshape((len(data),3))
print(data)
R0 = 10.

theta = np.arctan2(data[:,1],data[:,0]) #calcul of theta
print(theta)
Radius = np.sqrt(data[:,1]**2 + data[:,0]**2)

Mradius = Radius - np.mean(Radius)
Mradius = Mradius/R0
n = len(theta) # length
Radiushat = np.fft.fft(Mradius,n) #fft of the Radius
PSD = Radiushat * np.conj(Radiushat)/n #Power spectral density
delta = 0.0001

k = (1/(delta*n)) * np.arange(n) #wavenumber
indice = np.where(PSD==np.max(PSD)) #find position indice max PSD array
#print(k[indice][0]) #k_{max}
L = np.arange(1,np.floor(n/2), dtype='int')

# filtered the signal
"""
indices = PSD > np.max(PSD)/3. 
PDSclean = PSD * indices
Radiushatclean = indices * Radiushat
ffilt = np.fft.ifft(Radiushatclean)"""

fig,axs = plt.subplots(2,1)
plt.sca(axs[0])
plt.plot(theta,Radius,label="Crown")
ticks = [-np.pi, -np.pi/2., 0, np.pi/2., np.pi]
ticks_labels = ['-π', '-π/2', '0', 'π/2', 'π']
plt.xticks(ticks, ticks_labels)
"""plt.plot(theta,ffilt, label="Filtered")"""
plt.xlabel("theta")
plt.ylabel("R/R(t=0)")
plt.legend()
plt.title('k_{max}=%.2f' % (k[indice][0]))

plt.sca(axs[1])
plt.plot(k[L],PSD[L]/np.max(PSD))
plt.xlim(0,k[L[-1]])
plt.xlabel("k")
plt.ylabel("PSD")

fig.tight_layout()
plt.show()

введите описание изображения здесь

...