Advertisement
Dominusv2

Zadanie nr. 6 Python

Dec 9th, 2019
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. import matplotlib.pyplot as plot
  2. from mpl_toolkits.mplot3d import Axes3D
  3. import numpy as np
  4. from matplotlib.animation import FuncAnimation
  5. LiczbaLinii = []
  6. Ax = []
  7. Ay = []
  8. Az = []
  9. with open("wynik.txt", "r") as dane:
  10.     wiersze = dane.readlines()  # przykladowa linijka: 12,-4.3483453,1.213123,12342.123123
  11.     for wiersz in wiersze:  # rozdzelenie tekstu do poszczegolnych list
  12.         lista = wiersz.split(',')
  13.         LiczbaLinii.append(lista[0])
  14.         Ax.append(lista[1])
  15.         Ay.append(lista[2])
  16.         lista[3] = lista[3].strip("\n")
  17.         Az.append((lista[3]))
  18.  
  19.  
  20. def danedowykresu(num):  # metoda utworzona bo szlag by trafił inaczej moje animacje
  21.     wektor_x = Ax[num]
  22.     wektor_y = Ay[num]
  23.     wektor_z = Az[num]
  24.     ax.cla()  # Wyczyszczenie poprzedniego wykresu
  25.  
  26.     ax.quiver(0, 0, 0, wektor_x, 0, 0, color="green")
  27.     ax.quiver(0, 0, 0, 0, wektor_y, 0, color="pink")
  28.     ax.quiver(0, 0, 0, 0, 0, wektor_z, color="purple")
  29.     ax.quiver(0, 0, 0, wektor_x, wektor_y, wektor_z)  # polozenie koncowych punkow wektora, wektor a wypadk.
  30.     ax.set_xlim(-12, 12)  # zakresy na osi X
  31.     ax.set_ylim(-12, 12)
  32.     ax.set_zlim(-12, 12)
  33.     ax.set_xlabel('Wartość skladowej X [m/s^2]')
  34.     ax.set_ylabel('Wartość skladowej Y [m/s^2]')
  35.     ax.set_zlabel('Wartość skladowej Z [m/s^2]')
  36.  
  37.  
  38. figura = plot.figure()  # musi byc poza bo inaczej animacja nie dziala
  39. ax = figura.add_subplot(111, projection='3d')
  40.  
  41. Animacja = FuncAnimation(figura, danedowykresu, len(LiczbaLinii))  # Animacja poklatkowa pokazujaca wektory
  42. plot.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement