front.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import streamlit as st
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. import sys
  5. import os
  6. absolute_path = os.path.abspath(__file__)
  7. # print("Full path: " + absolute_path)
  8. # print("Directory Path: " + os.path.dirname(absolute_path))
  9. # adding /backend to use functions from it here
  10. sys.path.insert(0, "/".join(os.path.dirname(absolute_path).split('/')[:-1]))
  11. from ..backend.calc import *
  12. # ../../resource/data/1_M450.MEA
  13. with open("/".join(os.path.dirname(absolute_path).split('/')[:-2]) + "/resource/data/1_M450.MEA") as f:
  14. row = f.readlines()
  15. f, r, i = [], [], []
  16. for x in row:
  17. a, b, c = (float(y) for y in x.split())
  18. f.append(a) # frequency
  19. r.append(b) # Re of something
  20. i.append(c) # Im of something
  21. # unit circle
  22. unit_circle_x = []
  23. unit_circle_y = []
  24. for x in np.arange(-1, 1, 0.01):
  25. unit_circle_x.append(x)
  26. unit_circle_y.append((1-x**2)**0.5)
  27. unit_circle_x.append(1)
  28. unit_circle_y.append(0)
  29. for x in np.arange(-1, 1, 0.01)[::-1]:
  30. unit_circle_x.append(x)
  31. unit_circle_y.append(-(1-x**2)**0.5)
  32. fig, ax = plt.subplots()
  33. ax.plot(unit_circle_x, unit_circle_y)
  34. #
  35. # data
  36. ax.plot(r, i)
  37. #
  38. ax.grid(True)
  39. ax.axis('square')
  40. ax.set_yticks(np.arange(-1, 1.2, 0.2))
  41. ax.set_yticks(np.arange(-1, 1.2, 0.2))
  42. st.pyplot(fig)