From: Benjamin R. <ben...@ou...> - 2010-10-28 21:07:20
|
On Thu, Oct 28, 2010 at 3:31 PM, Nikolaus Rath <Nik...@ra...> wrote: > Hello, > > I'm having a weird problem with a contour plot. Consider the following > plots: > > import cPickle as pickle > import matplotlib.pyplot as plt > (Theta, Phi, Bnormal) = pickle.load(open('trouble.pickle', 'rb')) > plt.figure(0) > for i in [0, 300]: > plt.plot(Theta, Bnormal[:, i], label='Bnormal at Phi=%.3g' % Phi[i]) > > plt.ylabel('Theta') > plt.legend() > plt.savefig('figure0.png') > plt.figure(1) > plt.contourf(Phi, Theta, Bnormal) > plt.xlabel('Phi') > plt.ylabel('Theta') > plt.colorbar() > plt.savefig('figure1.png') > > 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. > > > I have also uploaded the two figures at http://www.rath.org/figure1.png > and http://www.rath.org/figure0.png. > > > Am I missing something, or is this a bug? > > $ python --version > Python 2.6.5 > $ python -c 'import matplotlib; print matplotlib.__version__' > 1.0.0 > > > Thanks, > > -Nikolaus > > Nikolaus, 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. Ben Root |