SpaceQuester

Untitled

Nov 10th, 2025
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.22 KB | None | 0 0
  1. import os
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. # --- Настройки ---
  6. FontSize = 10
  7.  
  8. # Ищем файлы в текущей рабочей директории
  9. # (это самый надежный способ, если вы загрузили файлы в среду выполнения)
  10. current_dir = os.getcwd()
  11.  
  12. # --- Загрузка данных ---
  13. filename1 = 'results_Ca_IP3_z.txt'
  14. if not os.path.exists(filename1):
  15.     raise FileNotFoundError(f"Файл '{filename1}' не найден в директории: {current_dir}")
  16.  
  17. Data = np.loadtxt(filename1)
  18. time = Data[:, 0]
  19. Ca   = Data[:, 1]
  20. IP3  = Data[:, 2]
  21. z    = Data[:, 3]
  22. print("Data: time, Ca, IP3, z have been loaded")
  23.  
  24. filename2 = 'v_4.txt'
  25. # Замечание: в оригинальном коде v_4 загружается, но нигде не используется.
  26. # Поэтому мы проверим его наличие, но не будем рисовать, если это не нужно.
  27. if os.path.exists(filename2):
  28.     v_4 = np.loadtxt(filename2)
  29.     print("Data: v_4 has been loaded")
  30. else:
  31.     print(f"Предупреждение: файл '{filename2}' не найден. Переменная v_4 не будет использована.")
  32.  
  33. # --- Построение графиков ---
  34. fig, axs = plt.subplots(2, 2, figsize=(12, 8))
  35.  
  36. # Subplot 1: Ca(t)
  37. axs[0, 0].plot(time, Ca, 'r', linewidth=1)
  38. axs[0, 0].grid(True)
  39. axs[0, 0].set_ylim([0, 0.7])
  40. axs[0, 0].set_yticks([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7])
  41. axs[0, 0].set_xlim([0, 180])
  42. axs[0, 0].set_xticks(range(0, 181, 20))
  43. axs[0, 0].tick_params(axis='both', labelsize=FontSize)
  44. axs[0, 0].set_title(r'$Ca^{2+}(t)$', fontsize=FontSize)
  45. axs[0, 0].set_xlabel('Time, s', fontsize=FontSize)
  46. axs[0, 0].set_ylabel(r'$[Ca^{2+}], \mu M$', fontsize=FontSize)
  47.  
  48. # Subplot 2: IP3(t)
  49. axs[0, 1].plot(time, IP3, 'b', linewidth=1)
  50. axs[0, 1].grid(True)
  51. axs[0, 1].set_xlim([0, 180])
  52. axs[0, 1].set_xticks(range(0, 181, 20))
  53. axs[0, 1].tick_params(axis='both', labelsize=FontSize)
  54. axs[0, 1].set_title(r'$IP_3(t)$', fontsize=FontSize)
  55. axs[0, 1].set_xlabel('Time, s', fontsize=FontSize)
  56. axs[0, 1].set_ylabel(r'$[IP_3], \mu M$', fontsize=FontSize)
  57.  
  58. # Subplot 3: z(t)
  59. axs[1, 0].plot(time, z, 'b', linewidth=1)
  60. axs[1, 0].grid(True)
  61. axs[1, 0].set_ylim([0, 1])
  62. axs[1, 0].set_xlim([0, 180])
  63. axs[1, 0].set_xticks(range(0, 181, 20))
  64. axs[1, 0].tick_params(axis='both', labelsize=FontSize)
  65. axs[1, 0].set_title('z(t)', fontsize=FontSize)
  66. axs[1, 0].set_xlabel('Time, s', fontsize=FontSize)
  67. axs[1, 0].set_ylabel('z', fontsize=FontSize)
  68.  
  69. # Subplot 4: Phase portrait Ca(z)
  70. axs[1, 1].plot(z, Ca, 'b', linewidth=1)
  71. axs[1, 1].grid(True)
  72. axs[1, 1].set_ylim([0, 0.7])
  73. axs[1, 1].set_yticks([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7])
  74. axs[1, 1].set_xlim([0, 1])
  75. axs[1, 1].set_xticks([0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0])
  76. axs[1, 1].tick_params(axis='both', labelsize=FontSize)
  77. axs[1, 1].set_title('Phase portrait: Ca(z)', fontsize=FontSize)
  78. axs[1, 1].set_xlabel('z', fontsize=FontSize)
  79. axs[1, 1].set_ylabel(r'$Ca^{2+}, \mu M$', fontsize=FontSize)
  80.  
  81. plt.tight_layout()
  82. fig.savefig('fig_Ca_IP3_z.png', dpi=300, bbox_inches='tight')
  83. print("Plot fig_Ca_IP3_z has been saved")
Advertisement
Add Comment
Please, Sign In to add comment