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.
> 


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to