Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Basilius Sapientia
User
Beiträge: 46 Registriert: Freitag 5. September 2014, 22:34
Montag 23. Februar 2015, 14:12
Servus!
Ich habe diesen
http://9gag.com/gag/a0LdAVB Link gefunden. Dort steht eine Formel:
fx=x**2+(y-(x**2)**(1/3))**2=1
Ich wollte dies dann plotten. Doch ich habe Schwierigkeiten damit. Kann mir bitte jemand erklären, wie ich dies plotte? Natürlich hier mein Versuch:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(0, 100, 1)
y=np.linspace(0, 100, 1)
plot(show)
xlabel('time (s)')
ylabel('voltage (mV)')
title('About as simple as it gets, folks')
grid(True)
savefig("test.png")
show()
Vielen Dank im Voraus!
Sirius3
User
Beiträge: 18216 Registriert: Sonntag 21. Oktober 2012, 17:20
Montag 23. Februar 2015, 14:46
@Basilius Sapientia: Wo berechnest Du die Formel "fx=x**2+(y-(x**2)**(1/3))**2=1" und was meinst Du macht plot(show)?
Matplotlib hat eine große Sammlung an Beispielplots. Da findest Du sicher den für dich passenden.
MagBen
User
Beiträge: 799 Registriert: Freitag 6. Juni 2014, 05:56
Wohnort: Bremen
Kontaktdaten:
Montag 23. Februar 2015, 17:26
So geht's:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
# x-Werte
anzahl = 100
x=np.linspace(0, 1, anzahl) # linspace(von, bis, Anzahl)
# y-Werte
# Gleichung x**2+(y-(x**2)**(1/3))**2=1
# nach y aufgeloest:
y = np.sqrt(1-x**2) + x**(2./3.)
# Test:
np.testing.assert_array_almost_equal(x**2+(y-(x**2)**(1./3.))**2, np.ones((anzahl,)))
# Plotten
plt.figure()
plt.plot(x,y)
plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')
plt.title('About as simple as it gets, folks')
plt.grid(True)
plt.savefig("test.png")
plt.show()
Üpsilon
User
Beiträge: 225 Registriert: Samstag 15. September 2012, 19:23
Montag 23. Februar 2015, 18:00
@Magben das ist jez aber auch nur die halbe Wahrheit. Bei der Wurzel musste schon auch +/- machen.
PS: Die angebotene Summe ist beachtlich.
MagBen
User
Beiträge: 799 Registriert: Freitag 6. Juni 2014, 05:56
Wohnort: Bremen
Kontaktdaten:
Montag 23. Februar 2015, 18:01
Und so war's gemeint:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
# x-Werte
anzahl = 1000
# linspace(von, bis, Anzahl)
x=np.linspace(-1, 1, anzahl)
# y-Werte
# Gleichung
# x**2+(y-(x**2)**(1/3))**2=1
# nach y aufgeloest:
y1 = np.sqrt(1-x**2) + (x**2.)**(1./3.)
y2 = -np.sqrt(1-x**2) + (x**2.)**(1./3.)
# Test:
np.testing.assert_array_almost_equal(x**2+(y1-(x**2)**(1./3.))**2, np.ones((anzahl,)))
np.testing.assert_array_almost_equal(x**2+(y2-(x**2)**(1./3.))**2, np.ones((anzahl,)))
# Plotten
plt.figure()
plt.plot(x,y1, "r", linewidth=3)
plt.plot(x,y2, "r", linewidth=3)
plt.title('About as simple as it gets, folks')
plt.xlim(-1.05,1.05)
plt.ylim(-1.05,1.55)
plt.savefig("herz.png")
plt.show()