kennlinie.py 613 B

12345678910111213141516171819202122232425
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. # Parameter der Gerade
  4. m = 2 # Steigung
  5. b = 1 # y-Achsenabschnitt
  6. # Erstelle Werte für x
  7. x = np.linspace(-10, 10, 400) # Werte von x von -10 bis 10
  8. # Berechne y-Werte basierend auf der Geradengleichung
  9. y = m * x + b # Vektorfuntkion
  10. # Erstelle das Plot
  11. plt.plot(x, y, label=f'Gerade: y = {m}x + {b}')
  12. plt.title("Verlauf einer Geraden")
  13. plt.xlabel("x")
  14. plt.ylabel("y")
  15. plt.axhline(0, color='black',linewidth=1) # x-Achse
  16. plt.axvline(0, color='black',linewidth=1) # y-Achse
  17. plt.grid(True)
  18. plt.legend()
  19. # Zeige das Plot
  20. plt.show()