SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Wayne W. <sie...@sb...> - 2009年11月30日 03:09:18
I have a fairly large program that uses pylab and company. I want to use 
the matplot histogram function. Here are the declarations at the start. 
I added import matplotlib as mpl
---------------------start
from Tkinter import *
from numpy import *
import numpy
import pylab
import Image
import ImageChops
import ImageTk
import time
import binascii
import tkMessageBox
import tkSimpleDialog
from pylab import plot, xlabel, ylabel, title, show, xticks, bar
import matplotlib as mpl <<<<---------- added
from tkFileDialog import asksaveasfilename
from tkFileDialog import askopenfilename
import MakeQTE
import socket
... 500 lines of code
 I've added the follow code in a function
 print "pltx_bins: ", pltx_bins
 print "Off to pylab: ", plt_bins[0:nplt_bins]
 fig = mpl.figure()
 v = array(plt_bins)
 print "v is: ",v
 print "edges --", linspace(0,256,nplt_bins+1)
 mpl.histogram(v, bins=linspace(0,256,nplt_bins+1), normed=1)# 
matplotlib version (plot)
 mpl.show()
 print "end of histogram output"
 # end of function
-------------------------end
The program dies at fig = figure() with:
Exception in Tkinter callback
Traceback (most recent call last):
 File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
 return self.func(*args)
 File 
"C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", 
line 504, in ShowHistogram
 fig = mpl.figure()
TypeError: 'module' object is not callable
What's the problem here?
-- 
 Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
 Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet 
 
 350 350 350 350 350 350 350 350 350 350
 Make the number famous. See 350.org
 The major event has passed, but keep the number alive.
 
 Web Page: <www.speckledwithstars.net/>
From: Eric F. <ef...@ha...> - 2009年11月30日 05:01:04
Wayne Watson wrote:
> I have a fairly large program that uses pylab and company. I want to use 
> the matplot histogram function. Here are the declarations at the start. 
> I added import matplotlib as mpl
> ---------------------start
> from Tkinter import *
> from numpy import *
> import numpy
> import pylab
> import Image
> import ImageChops
> import ImageTk
> import time
> import binascii
> import tkMessageBox
> import tkSimpleDialog
> from pylab import plot, xlabel, ylabel, title, show, xticks, bar
> import matplotlib as mpl <<<<---------- added
> 
> from tkFileDialog import asksaveasfilename
> from tkFileDialog import askopenfilename
> 
> import MakeQTE
> 
> import socket
> 
> ... 500 lines of code
> 
> I've added the follow code in a function
> print "pltx_bins: ", pltx_bins
> print "Off to pylab: ", plt_bins[0:nplt_bins]
> fig = mpl.figure()
> v = array(plt_bins)
> print "v is: ",v
> print "edges --", linspace(0,256,nplt_bins+1)
> mpl.histogram(v, bins=linspace(0,256,nplt_bins+1), normed=1)# 
> matplotlib version (plot)
> mpl.show()
> print "end of histogram output"
> # end of function
> -------------------------end
> The program dies at fig = figure() with:
> Exception in Tkinter callback
> Traceback (most recent call last):
> File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
> return self.func(*args)
> File 
> "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", 
> line 504, in ShowHistogram
> fig = mpl.figure()
> TypeError: 'module' object is not callable
> 
> What's the problem here?
> 
> 
figure(), show(), etc. are pylab (or matplotlib.pyplot) functions, not 
matplotlib functions.
Especially for a long program, it is strongly recommended that you not 
use "from numpy import *". The recommended form is
import numpy as np
import matplotlib.pyplot as plt
It will help you keep a clear picture of where various types of 
functionality are coming from. See also 
http://matplotlib.sourceforge.net/faq/usage_faq.html
and note that a primarily object-oriented approach is recommended for 
use in other than quick scripts and interactive plotting.
Eric
From: Wayne W. <sie...@sb...> - 2009年11月30日 05:42:53
Eric Firing wrote:
> Wayne Watson wrote:
>> I have a fairly large program that uses pylab and company. I want to 
>> use the matplot histogram function. Here are the declarations at the 
>> start. I added import matplotlib as mpl
>> ---------------------start
>> from Tkinter import *
>> from numpy import *
>> import numpy
>> import pylab
>> import Image
>> import ImageChops
>> import ImageTk
>> import time
>> import binascii
>> import tkMessageBox
>> import tkSimpleDialog
>> from pylab import plot, xlabel, ylabel, title, show, xticks, bar
>> import matplotlib as mpl <<<<---------- added
>>
>> from tkFileDialog import asksaveasfilename
>> from tkFileDialog import askopenfilename
>>
>> import MakeQTE
>>
>> import socket
>>
>> ... 500 lines of code
>>
>> I've added the follow code in a function
>> print "pltx_bins: ", pltx_bins
>> print "Off to pylab: ", plt_bins[0:nplt_bins]
>> fig = mpl.figure()
>> v = array(plt_bins)
>> print "v is: ",v
>> print "edges --", linspace(0,256,nplt_bins+1)
>> mpl.histogram(v, bins=linspace(0,256,nplt_bins+1), normed=1)# 
>> matplotlib version (plot)
>> mpl.show()
>> print "end of histogram output"
>> # end of function
>> -------------------------end
>> The program dies at fig = figure() with:
>> Exception in Tkinter callback
>> Traceback (most recent call last):
>> File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
>> return self.func(*args)
>> File 
>> "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", 
>> line 504, in ShowHistogram
>> fig = mpl.figure()
>> TypeError: 'module' object is not callable
>>
>> What's the problem here?
>>
>>
>
> figure(), show(), etc. are pylab (or matplotlib.pyplot) functions, not 
> matplotlib functions.
>
> Especially for a long program, it is strongly recommended that you not 
> use "from numpy import *". The recommended form is
>
> import numpy as np
> import matplotlib.pyplot as plt
>
> It will help you keep a clear picture of where various types of 
> functionality are coming from. See also 
> http://matplotlib.sourceforge.net/faq/usage_faq.html
> and note that a primarily object-oriented approach is recommended for 
> use in other than quick scripts and interactive plotting.
>
> Eric
>
Thanks. Well, that explains a lot! functions in the wrong place.
I'm pretty new to this stuff, so what belongs where is sometimes 
unclear. I'll check out the sourceforge tip. I didn't write the program. 
I'm just trying to add some features. Changing the import for matplotlib 
got the graphics window up.
 import matplotlib.pyplot as plt
When I ran it, it was followed by this traceback:
------------start
Exception in Tkinter callback
Traceback (most recent call last):
 File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
 return self.func(*args)
 File 
"C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", 
line 508, in ShowHistogram
 plt.histogram(v, bins=linspace(0,256,nplt_bins+1), normed=1)# 
matplotlib version (plot)
AttributeError: 'module' object has no attribute 'histogram'
---------------end
508 line is the histogram. Who's complaining? ShowHistogram? I don't 
believe I should be using hist here instead of histogram.
Off to sourceforge.
-- 
 Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
 Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet 
 
 The popular press and many authorities believe the number
 of pedifiles that prowl the web is 50,00. There are no
 figures that support this. The number of children below
 18 years of age kidnapped by strangers is 1 in 600,00,
 or 115 per year. -- The Science of Fear by D. Gardner
 
 Web Page: <www.speckledwithstars.net/>
From: Eric F. <ef...@ha...> - 2009年11月30日 06:04:56
Wayne Watson wrote:
> 
> Eric Firing wrote:
>> Wayne Watson wrote:
>>> I have a fairly large program that uses pylab and company. I want to 
>>> use the matplot histogram function. Here are the declarations at the 
>>> start. I added import matplotlib as mpl
>>> ---------------------start
>>> from Tkinter import *
>>> from numpy import *
>>> import numpy
>>> import pylab
>>> import Image
>>> import ImageChops
>>> import ImageTk
>>> import time
>>> import binascii
>>> import tkMessageBox
>>> import tkSimpleDialog
>>> from pylab import plot, xlabel, ylabel, title, show, xticks, bar
>>> import matplotlib as mpl <<<<---------- added
>>>
>>> from tkFileDialog import asksaveasfilename
>>> from tkFileDialog import askopenfilename
>>>
>>> import MakeQTE
>>>
>>> import socket
>>>
>>> ... 500 lines of code
>>>
>>> I've added the follow code in a function
>>> print "pltx_bins: ", pltx_bins
>>> print "Off to pylab: ", plt_bins[0:nplt_bins]
>>> fig = mpl.figure()
>>> v = array(plt_bins)
>>> print "v is: ",v
>>> print "edges --", linspace(0,256,nplt_bins+1)
>>> mpl.histogram(v, bins=linspace(0,256,nplt_bins+1), normed=1)# 
>>> matplotlib version (plot)
>>> mpl.show()
>>> print "end of histogram output"
>>> # end of function
>>> -------------------------end
>>> The program dies at fig = figure() with:
>>> Exception in Tkinter callback
>>> Traceback (most recent call last):
>>> File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
>>> return self.func(*args)
>>> File 
>>> "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", 
>>> line 504, in ShowHistogram
>>> fig = mpl.figure()
>>> TypeError: 'module' object is not callable
>>>
>>> What's the problem here?
>>>
>>>
>> figure(), show(), etc. are pylab (or matplotlib.pyplot) functions, not 
>> matplotlib functions.
>>
>> Especially for a long program, it is strongly recommended that you not 
>> use "from numpy import *". The recommended form is
>>
>> import numpy as np
>> import matplotlib.pyplot as plt
>>
>> It will help you keep a clear picture of where various types of 
>> functionality are coming from. See also 
>> http://matplotlib.sourceforge.net/faq/usage_faq.html
>> and note that a primarily object-oriented approach is recommended for 
>> use in other than quick scripts and interactive plotting.
>>
>> Eric
>>
> Thanks. Well, that explains a lot! functions in the wrong place.
> 
> I'm pretty new to this stuff, so what belongs where is sometimes 
> unclear. I'll check out the sourceforge tip. I didn't write the program. 
> I'm just trying to add some features. Changing the import for matplotlib 
> got the graphics window up.
> import matplotlib.pyplot as plt
> 
> When I ran it, it was followed by this traceback:
> ------------start
> Exception in Tkinter callback
> Traceback (most recent call last):
> File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
> return self.func(*args)
> File 
> "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", 
> line 508, in ShowHistogram
> plt.histogram(v, bins=linspace(0,256,nplt_bins+1), normed=1)# 
> matplotlib version (plot)
> AttributeError: 'module' object has no attribute 'histogram'
> ---------------end
> 508 line is the histogram. Who's complaining? ShowHistogram? I don't 
> believe I should be using hist here instead of histogram.
histogram is a numpy function, not a pyplot function. Pyplot has a hist 
which uses numpy.histogram to do the calculation, and then plots it. It 
does look like plt.hist is what was intended in your code.
For tracking down such things, there is no substitute for working 
interactively with ipython. If you are not already familiar with it, 
taking a little time to get it running and learn the basics (like tab 
completion and appending ? or ?? to function names to get docstrings + 
origins, and source code, respectively) will pay big dividends.
Eric
> 
> Off to sourceforge.
> 
From: Wayne W. <sie...@sb...> - 2009年11月30日 06:23:35
Eric Firing wrote:
>>
>> I'm pretty new to this stuff, so what belongs where is sometimes 
>> unclear. I'll check out the sourceforge tip. I didn't write the 
>> program. I'm just trying to add some features. Changing the import 
>> for matplotlib got the graphics window up.
>> import matplotlib.pyplot as plt
>>
>> When I ran it, it was followed by this traceback:
>> ------------start
>> Exception in Tkinter callback
>> Traceback (most recent call last):
>> File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
>> return self.func(*args)
>> File 
>> "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", 
>> line 508, in ShowHistogram
>> plt.histogram(v, bins=linspace(0,256,nplt_bins+1), normed=1)# 
>> matplotlib version (plot)
>> AttributeError: 'module' object has no attribute 'histogram'
>> ---------------end
>> 508 line is the histogram. Who's complaining? ShowHistogram? I don't 
>> believe I should be using hist here instead of histogram.
>
> histogram is a numpy function, not a pyplot function. Pyplot has a 
> hist which uses numpy.histogram to do the calculation, and then plots 
> it. It does look like plt.hist is what was intended in your code.
>
> For tracking down such things, there is no substitute for working 
> interactively with ipython. If you are not already familiar with it, 
> taking a little time to get it running and learn the basics (like tab 
> completion and appending ? or ?? to function names to get docstrings + 
> origins, and source code, respectively) will pay big dividends.
>
> Eric
These dependencies sure are tricky. I changed it to plt:hist, and that 
got me a histogram plot. I think some of my parameters need work, but 
it's close to what I expected. When I closed the graph and finally the 
program, the shell (IDLE) did not provide a >> prompt, nor did it 
produce my print of "End of Histogram" that followed plt.hist. Closing 
the shell revealed something was still running. I may have to go to the 
console for execution to see what that's about.
I've heard of ipython. It looks like I should give it a try. Examples 
for matplotlib abound, but not much about how MATLAB concepts like 
figure shows up anywhere. Is that all in pylab docs?
-- 
 Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
 Obz Site: 39° 15' 7" N, 121° 2' 32" W, 2700 feet 
 
 The popular press and many authorities believe the number
 of pedifiles that prowl the web is 50,00. There are no
 figures that support this. The number of children below
 18 years of age kidnapped by strangers is 1 in 600,00,
 or 115 per year. -- The Science of Fear by D. Gardner
 
 Web Page: <www.speckledwithstars.net/>
From: Eric F. <ef...@ha...> - 2009年11月30日 06:48:33
Wayne Watson wrote:
> Eric Firing wrote:
>>>
>>> I'm pretty new to this stuff, so what belongs where is sometimes 
>>> unclear. I'll check out the sourceforge tip. I didn't write the 
>>> program. I'm just trying to add some features. Changing the import 
>>> for matplotlib got the graphics window up.
>>> import matplotlib.pyplot as plt
>>>
>>> When I ran it, it was followed by this traceback:
>>> ------------start
>>> Exception in Tkinter callback
>>> Traceback (most recent call last):
>>> File "C:\Python25\lib\lib-tk\Tkinter.py", line 1403, in __call__
>>> return self.func(*args)
>>> File 
>>> "C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser+Utilities\sentuser\sentuser_20090103+hist.py", 
>>> line 508, in ShowHistogram
>>> plt.histogram(v, bins=linspace(0,256,nplt_bins+1), normed=1)# 
>>> matplotlib version (plot)
>>> AttributeError: 'module' object has no attribute 'histogram'
>>> ---------------end
>>> 508 line is the histogram. Who's complaining? ShowHistogram? I don't 
>>> believe I should be using hist here instead of histogram.
>>
>> histogram is a numpy function, not a pyplot function. Pyplot has a 
>> hist which uses numpy.histogram to do the calculation, and then plots 
>> it. It does look like plt.hist is what was intended in your code.
>>
>> For tracking down such things, there is no substitute for working 
>> interactively with ipython. If you are not already familiar with it, 
>> taking a little time to get it running and learn the basics (like tab 
>> completion and appending ? or ?? to function names to get docstrings + 
>> origins, and source code, respectively) will pay big dividends.
>>
>> Eric
> These dependencies sure are tricky. I changed it to plt:hist, and that 
> got me a histogram plot. I think some of my parameters need work, but 
> it's close to what I expected. When I closed the graph and finally the 
> program, the shell (IDLE) did not provide a >> prompt, nor did it 
> produce my print of "End of Histogram" that followed plt.hist. Closing 
> the shell revealed something was still running. I may have to go to the 
> console for execution to see what that's about.
That is what ipython is for (among other things): it handles interactive 
plotting, which tends to be a problem with other shells and 
environments. It also gives nice access to the pdb debugger to help you 
figure out what actually went wrong when you get an exception.
> 
> I've heard of ipython. It looks like I should give it a try. Examples 
> for matplotlib abound, but not much about how MATLAB concepts like 
> figure shows up anywhere. Is that all in pylab docs?
> 
Yes. If you are coming from Matlab, you may find this useful for the 
numeric aspects: http://www.scipy.org/NumPy_for_Matlab_Users.
Eric
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /