Ah, I was a little confused by what you wrote John (I though I had to
access contour through the axes object and the meaning of R, F, dR was
a little unclear..) however using the 'levels' keyword now works. i.e.

plt.contour(x, y, z, levels=[0])

Incidentally, this keyword (levels) is not documented at
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.contour
and in fact the documentation implies that contour(kx, ky, z, [0])
should work when it does not.

Perhaps the docs could be updated to reflect this?

Brendan

On Tue, Nov 3, 2009 at 2:19 PM, Brendan Arnold <brendanarn...@gmail.com> wrote:
> Hi again,
>
> Thanks for the responses, however neither work, the error still
> persists. Here are more details...
>
> Traceback (most recent call last):
>  File "C:\Program Files\Python\2.5\lib\lib-tk\Tkinter.py", line 1403,
> in __call__
>    return self.func(*args)
>  File "C:\Program
> Files\Python\2.5\lib\site-packages\matplotlib\backends\backend_tkagg.py",
> line 212, in resize
>    self.show()
>  File "C:\Program
> Files\Python\2.5\lib\site-packages\matplotlib\backends\backend_tkagg.py",
> line 215, in draw
>    FigureCanvasAgg.draw(self)
>  File "C:\Program
> Files\Python\2.5\lib\site-packages\matplotlib\backends\backend_agg.py",
> line 314, in draw
>    self.figure.draw(self.renderer)
>  File "C:\Program
> Files\Python\2.5\lib\site-packages\matplotlib\artist.py", line 46, in
> draw_wrapper
>    draw(artist, renderer, *kl)
>  File "C:\Program
> Files\Python\2.5\lib\site-packages\matplotlib\figure.py", line 773, in
> draw
>    for a in self.axes: a.draw(renderer)
>  File "C:\Program
> Files\Python\2.5\lib\site-packages\matplotlib\artist.py", line 46, in
> draw_wrapper
>    draw(artist, renderer, *kl)
>  File "C:\Program
> Files\Python\2.5\lib\site-packages\matplotlib\axes.py", line 1735, in
> draw
>    a.draw(renderer)
>  File "C:\Program
> Files\Python\2.5\lib\site-packages\matplotlib\text.py", line 515, in
> draw
>    bbox, info = self._get_layout(renderer)
>  File "C:\Program
> Files\Python\2.5\lib\site-packages\matplotlib\text.py", line 257, in
> _get_layout
>    if key in self.cached: return self.cached[key]
> TypeError: unhashable type: 'numpy.ndarray'
>
>>>> matplotlib.__version__
> '0.99.1'
>>>> numpy.__version__
> '1.3.0'
>
> Python version 2.5
>
> the code in full is as follows,
>
> import matplotlib
> import numpy as np
> import matplotlib.cm as cm
> import matplotlib.mlab as mlab
> import matplotlib.pyplot as plt
>
> # Set some model parameters
> model_points = 10000
> t0 = 0.38
> t1 = 0.32*t0
> t2 = 0.5*t1
>
> def energy(kx, ky):
>    '''Energy function, evetually this will be provided by raw data
> from WIEN2k'''
>    return -2*t0*(np.cos(kx)+np.cos(ky)) \
>        + 4*t1*np.cos(kx)*np.cos(ky) \
>        - 2*t2*(np.cos(2*kx)+np.cos(2*ky))
>
> def shift_energy_up(energy_val, dE):
>    '''Shifts the energy according to a gap'''
>    return energy_val + np.sqrt(energy_val**2 + dE**2)
>
> def shift_energy_dn(energy_val, dE):
>    '''Shifts the energy down according to an energy'''
>    return energy_val - np.sqrt(energy_val**2 + dE**2)
>
> kx = np.arange(0, 2*np.pi, 2*np.pi/np.sqrt(model_points))
> ky = np.arange(0, 2*np.pi, 2*np.pi/np.sqrt(model_points))
> mgx, mgy = np.meshgrid(kx, ky)
> z = energy(mgx, mgy)
>
> # Set the ticks to go outwards
> matplotlib.rcParams['xtick.direction'] = 'out'
> matplotlib.rcParams['ytick.direction'] = 'out'
>
> plt.figure()
> CS = plt.contour(kx, ky, z, [0, 0])
> plt.clabel(CS, inline=1, fontsize=10)
> plt.title('Simplest default with labels')
> plt.show()
>
>
> kind regards,
>
> Brendan
>
> On Mon, Nov 2, 2009 at 9:33 PM, Pierre de Buyl <pdeb...@ulb.ac.be> wrote:
>> From memory, you just need to make a length one list
>>
>> contour(z, [i])
>>
>> Pierre
>>
>> Le 2 nov. 09 à 22:19, Brendan Arnold a écrit :
>>
>>> Hi there,
>>>
>>> I can draw a single contour line in MATLAB using
>>>
>>> contour(z, [i i])
>>>
>>> however,
>>>
>>> contour(z, [i, i])
>>>
>>> using matplotlib gives an error. In fact any plot that plots a single
>>> line (i.e. contour(z, 1)) also gives an error as follows,
>>>
>>> TypeError: unhashable type: 'numpy.ndarray'
>>>
>>> How do I draw a single contour line using matplotlib?
>>>
>>> regards,
>>>
>>> Brendan
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
>>> is the only developer event you need to attend this year. Jumpstart your
>>> developing skills, take BlackBerry mobile applications to market and stay
>>> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
>>> http://p.sf.net/sfu/devconference
>>> _______________________________________________
>>> Matplotlib-users mailing list
>>> Matplotlib-users@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>

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