Hi All,

    I am trying to create a contour map with matplotlib. I have
modified the source code for the contour sample which comes with the
matplotlib 0.98.3 online documentation: I am using the "contour(X, Y,
Z, V)" API call and, as the docs say:

"""
contour(X,Y,Z,V)
draw contour lines at the values specified in sequence V
"""

I have specified a 20-elements vector in V, buit I still only see 6
contours being drawn, namely the ones at the values:

[-1.0, -0.5, 0.0, 0.5, 1.0, 1.5]


I attach my small sample to the message. Am I doing something worng in
my call to contour? Why I am unable to see the 20 contour I specified
in my vector V?

Another related problem is with contourf: if I modify the attached
sample to use contourf and clabel, I get this error:

Traceback (most recent call last):
  File "E:\MyProjects\prova143.py", line 24, in <module>
    plt.clabel(CS, fontsize=9, inline=1)
  File "C:\Python25\lib\site-packages\matplotlib\pyplot.py", line
1736, in clabel
    ret =  gca().clabel(*args, **kwargs)
  File "C:\Python25\lib\site-packages\matplotlib\axes.py", line 6027, in clabel
    return CS.clabel(*args, **kwargs)
  File "C:\Python25\lib\site-packages\matplotlib\contour.py", line
161, in clabel
    self.labelCValueList = np.take(self.cvalues, self.labelIndiceList)
  File "C:\Python25\lib\site-packages\numpy\core\fromnumeric.py", line
85, in take
    return take(indices, axis, out, mode)
IndexError: index out of range for array


This is in Windows XP, Python 2.5.2, matplotlib 0.98.3, numpy 1.2.0.

Thank you for your suggestions.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/


# CODE START

#!/usr/bin/env python

import matplotlib
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt

delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * (Z2 - Z1)

V = np.linspace(np.min(np.min(Z)), np.max(np.max(Z)), 20)

print V

# And you can manually specify the colors of the contour
plt.figure()
CS = plt.contourf(X, Y, Z, V=V)
plt.clabel(CS, fontsize=9, inline=1)

plt.show()

# CODE END

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to