Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import annotations
- from pathlib import Path
- import matplotlib.pyplot as plt
- import numpy as np
- def build_curves() -> tuple[np.ndarray, dict[str, np.ndarray]]:
- T_over_Q = 2.0
- Q_over_T = 1.0 / T_over_Q
- l0 = 2.0
- a = 2.0
- D = 2.0
- beta = 1.0 / (1.0 + Q_over_T)
- gamma = T_over_Q * (D - 1.0)
- x = np.logspace(np.log10(5.0), np.log10(500.0), 500)
- curves = {
- "Дебаївська експонента": np.exp(-x),
- "Закон Колерауша": np.exp(-(x ** beta)),
- r"$\exp\!\left(-\left[(T/Q)\ln x\right]^{1/a}\right)$": np.exp(-((T_over_Q * np.log(x)) ** (1.0 / a))),
- r"$[(T/Q)\ln x]^{-1/l_0}$": (T_over_Q * np.log(x)) ** (-1.0 / l0),
- r"$x^{-\gamma}$": x ** (-gamma),
- r"$[(T/Q)\ln x]^{-D/a}$": (T_over_Q * np.log(x)) ** (-D / a),
- r"$[\ln((T/Q)\ln x)]^{-D}$": np.log(T_over_Q * np.log(x)) ** (-D),
- }
- return x, curves
- def make_plot(output_path: str | Path = "pr4_asymptotics_from_python.png", show: bool = True) -> Path:
- x, curves = build_curves()
- output_path = Path(output_path)
- plt.figure(figsize=(8.4, 5.2))
- for label, y in curves.items():
- plt.plot(x, y, label=label)
- plt.xscale("log")
- plt.xlabel(r"$x=t/\tau_0$")
- plt.ylabel("S(x)")
- plt.title("Порівняння часових асимптотик структурного фактора")
- plt.grid(True, which="both", alpha=0.25)
- plt.legend()
- plt.tight_layout()
- plt.savefig(output_path, dpi=200)
- if show:
- plt.show()
- else:
- plt.close()
- return output_path
- if __name__ == "__main__":
- saved_to = make_plot()
- print(f"Графік збережено у файл: {saved_to.resolve()}")
Advertisement
Add Comment
Please, Sign In to add comment