Benjamin Root <ben.root-GrrYUJ3DTa8@...1455...> writes:
I'm having a weird problem with a contour plot. Consider the following
import cPickle as pickle
import matplotlib.pyplot as plt
(Theta, Phi, Bnormal) = pickle.load(open('trouble.pickle', 'rb'))
for i in [0, 300]:
plt.plot(Theta, Bnormal[:, i], label='Bnormal at Phi=%.3g' % Phi[i])
plt.contourf(Phi, Theta, Bnormal)
The 'trouble.pickle' file is available on
http://www.rath.org/trouble.pickle. At Phi=0 the contour plot agrees
with the crossection (both show an n=7 oscillation), but at Phi=1.68 the
contour plot shows a uniform value while the crossection shows a phase
shifted version of oscillation at Phi=0.
It seems to me that this is a blatant contradiction.
Am I missing something, or is this a bug?
$ python --version
$ python -c 'import matplotlib; print matplotlib.__version__'
What might be happening is that the Theta variable isn't monotonic. It
first goes from zero to pi, then from -pi to 0. This also explains the odd
lines that appear in the line plots at the top and bottom. Try reforming
your arrays so that the domain is monotonic (note that you will have to
adjust the Phi and the Bnormal arrays as well because they were arranged
assuming a certain domain from Theta.
Indeed, this was the problem. Thank you very much!
However, it seems to me that this is quite a serious bug. The contour
does not mention this requirement, and obviously the contour method
itself does not even bother to check if its arguments are monotonically
increasing. Instead, it just *silently* produces garbage that in some
cases even looks like plausible data(!).
Am I missing something here? Otherwise I'll report this on the bug
tracker. I think this should be documented and contour() should check
its input and raise a ValueError if it's not monotonic.
On Thu, Oct 28, 2010 at 3:31 PM, Nikolaus Rath <Nikolaus-BTH8mxji4b0@...1836...455...> wrote:
»Time flies like an arrow, fruit flies like a Banana.«
PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C