uhurulol
uhurulol

Reputation: 345

Python plot won't run: 'x and y must have same first dimension'

I'm absolutely certain I'm doing something simple wrong with my function definition, but I'm completely drained right now and can't figure it out. If someone can help, I'd love them forever.

import matplotlib.pyplot as plt
import scipy as sp

lamb = sp.array([1100, 1650, 2200, 2750, 3300, 3850, 4400, 4950, 5500, 6050, 6600])
fno = sp.array([3.779, 2.443, 1.788, 1.361, 1.049, 0.831, 0.689, 0.590, 0.524, 0.486, 0.463])
fla = sp.array([0.743, 0.622, 0.555, 0.507, 0.468, 0.434, 0.401, 0.371, 0.348, 0.336, 0.320])
ebv = .1433

fig = plt.figure()
ax = fig.add_subplot(111)

def alam(fno, fla):
    return (2.5*sp.log(fno/fla))

def rlam(lamb):
    return (alam/ebv)

plt.plot(lamb, rlam,'k-')

plt.show()

I'm probably an idiot, so feel free to call me an idiot. Thanks!

Upvotes: 1

Views: 70

Answers (1)

Gopi Vinod Avvari
Gopi Vinod Avvari

Reputation: 294

You can clearly see there is an issue. You have to give two arrays for the plt.plot(x,y). In your case, you gave an array and rlam which is a function name. So obviously, there is an error.

Try to learn more about the python function usage. I added a small code snippet which shows the plot usage and python function usage with an input argument.

import matplotlib.pyplot as plt
import scipy as sp

lamb = sp.array([1100, 1650, 2200, 2750, 3300, 3850, 4400, 4950, 5500, 6050, 6600])
ebv = .1433

fig = plt.figure()
ax = fig.add_subplot(111)

def test_func(lamb):
    return lamb/ebv

plt.plot(lamb, test_func(lamb),'k-')
plt.show()

Upvotes: 1

Related Questions