numpy - plotting multiple plots but whith offset ranges python -
i plot function of e , nu e eccentricity , nu true anomaly. looking @ elliptical orbits 0<e<1
. however, when try plot them against each other, have shape error.
valueerror: operands not broadcast shapes (10) (5000)
i know because want 10 spaces eccentricity there way around this?
import numpy np e = np.arange(0, 1, 0.1) vvals = [[] in range(len(e))] nu = np.linspace(0, 2 * np.pi, 5000) in e: j in nu: = float(i) j = float(j) v = np.sqrt(e ** 2 + 2 * e * np.cos(nu) + 1) = int(i) vvals[i].append(v) in e: pylab.plot(nu, vvals[i]) pylab.show()
i think trying do:
import numpy np e = np.arange(0, 1, 0.1) vvals = [] nu = np.linspace(0, 2 * np.pi, 5000) in e: v = np.sqrt(i ** 2 + 2 * * np.cos(nu) + 1) vvals.append(v) v in vvals: pylab.plot(nu, v) pylab.show()
numpy
broadcasting friend ;)
if want fancy:
import numpy np e = np.arange(0, 1, 0.1).reshape(-1, 1) nu = np.linspace(0, 2 * np.pi, 5000).reshape(1, -1) vvals = np.sqrt((e ** 2) * np.ones(nu.shape) + 2 * e * np.cos(nu) + 1) v, _e in zip(vvals, e.ravel()): pylab.plot(nu.ravel(), v, label=str(_e)) pylab.legend() pylab.show()
Comments
Post a Comment