From e808a08b4ad9c8b35f14bed321863ff85b624ad8 Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Sat, 13 Jul 2024 22:58:07 +0200 Subject: [PATCH] =?UTF-8?q?N=C3=A5gra=20exempel=20p=C3=A5=202D-grafer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- graphs/graph_2d.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 graphs/graph_2d.py diff --git a/graphs/graph_2d.py b/graphs/graph_2d.py new file mode 100644 index 0000000..eb3d5ec --- /dev/null +++ b/graphs/graph_2d.py @@ -0,0 +1,30 @@ +import matplotlib.pyplot as plt +import numpy as np + +# Create data for plotting +x = np.linspace(0.1, 5) +y = x**2 + +fig, axs = plt.subplots(3, 1, figsize=(6, 8)) + +axs[0].plot(x, y) +axs[0].set_title('Linear graph for y = x^2') +# Enable grid lines for the linear graph +axs[0].grid(which='major', linestyle='-', linewidth=0.2, color='gray') +axs[0].grid(which='minor', linestyle='-', linewidth=0.2, color='gray') + + +axs[1].semilogx(x, y) +axs[1].set_title('Linlog graph for y = x^2') +# Enable grid lines for the linlog graph +axs[1].grid(which='major', linestyle='-', linewidth=0.2, color='gray') +axs[1].grid(which='minor', linestyle='-', linewidth=0.2, color='gray') + +axs[2].loglog(x, y) +axs[2].set_title('Loglog graph for y = x^2') +# Enable grid lines for the loglog graph +axs[2].grid(which='major', linestyle='-', linewidth=0.2, color='gray') +axs[2].grid(which='minor', linestyle='-', linewidth=0.2, color='gray') + +plt.tight_layout() +plt.show()