Hey,

can somebody help me. I have to do a programm from school. I a complete newbie in python.
Can somebody tell me why my programm doesn't work and what i can do. thanks

here it is:

import matplotlib 
import numpy
import pylab



lam = pylab.linspace(0.1,100,1000)*10**-6

pylab.xlabel('Wellenlaenge (mM)')
pylab.ylabel('Temperatur (T)')
pylab.title('Mac Plank')




c1  = 0.374*10**-15
c2  = 1.439*10**-2


p= lamda x,t : (c1/(x**5))*(1/(2.7183**(c2/x*t))-1)

pylab.plot (lam*1e6,p(lam,300))

for t in (300,400,600,800,1000): pylab.plot(lam*1e6, p(lam,t)

Recommended Answers

All 4 Replies

Hey,

import matplotlib 
import numpy
import pylab



lam = pylab.linspace(0.1,100,1000)*10**-6

pylab.xlabel('Wellenlaenge (mM)')
pylab.ylabel('Temperatur (T)')
pylab.title('Mac Plank')




c1  = 0.374*10**-15
c2  = 1.439*10**-2


p= lamda x,t : (c1/(x**5))*(1/(2.7183**(c2/x*t))-1)

pylab.plot (lam*1e6,p(lam,300))

for t in (300,400,600,800,1000): pylab.plot(lam*1e6, p(lam,t)

end quote.

You have unterminated parenthesis in the last line at least. I am not using pylab myself (yet).

Do you see how much nicer the code looks if you first click the (CODE) before pasting your code?

Tony

Can somebody tell me why my programm doesn't work and what i can do

Not without more info. Please include the traceback message at a minimum, with a simple explanation of what isn't working.

It now looks like this.My Problem is that it does't work and i don't know why.
At the end, a window should open and show me the graph.
the the window is empty with no graph.but why.what do i have to change that it works?

import numpy as np
import pylab as plt
from math import exp, e
from matplotlib.pyplot import legend, xlim, ylim, show



lam = np.linspace (0.1,100,1000)*10**-6
c1=0.374e-15
c2=1.439e-2   




  
def lamda(x):
   
   return ((c1/(x**5))*(1/(exp(c2/x*300))-1))
   
   
plt.plot(lam,lamda(lam))


legend()

xlim(0, 10)
ylim(0, 14000)

plt.xlabel('Wellenlaenge(muekrometer)')
plt.ylabel('Spektrale Energieflussdichte(W/m^2muekrometer)')
plt.title('Planck')


show()

A line is more than a single point if you are trying to code a line. I don't know. You didn't say. But if you want a bar graph for example then you have to code for a bar, see this example from the matplotlib docs http://matplotlib.sourceforge.net/examples/pylab_examples/barchart_demo.html Take a look at Ene's example here as well http://www.daniweb.com/code/snippet216915.html I'm outta here. Your descriptions are too vague and I'm sorry, but don't have the time to try and intuit what it is you are trying to do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.