|
From: Andreas H. <li...@hi...> - 2012-02-28 15:22:26
|
> On Tuesday, February 28, 2012, Andreas H. wrote:
>
>> Good morning,
>>
>> I'm creating the attached plot using pcolormesh(). What I would like to
>> do now is draw contour lines at +/- 2.5%, which follow the grid edges.
>>
>> The problem is that when I use contour(), the lines drawn do not follow
>> the grid edges but seem to be interpolated somehow.
>>
>> Do you have an idea how to draw the contour lines following the grid
>> edges?
>>
>> Your insight is very much appreciated :)
>>
>> Cheers,
>> Andreas.
>>
>
> This is because of a subtle difference in how pcolor-like functions and
> contour-like functions work. I always forget which is which, but one
> assumes that the z value lies on the vertices of the grid while the other
> assumes that it lies in the middle of each grid point. This is why you
> see
> them slightly offset from each other.
Thanks, Ben!
To `pcolormesh`, I pass the *edges* of the grid:
xbin = linspace(0, 12, nxbin + 1)
ybin = np.linspace(-90, 90, nybin + 1)
pl = spl.pcolormesh(xbin, ybin, pdata.T, cmap=cmap, edgecolors='None',
vmin=-5, vmax=20)
`contour`, however, wants the coordinates themselves. So I do
spl.contour((xbin[:-1]+xbin[1:])/2., (ybin[:-1]+ybin[1:])/2, pdata.T,
[-2.5, 2.5])
Still, the outcome is, well, unexpected to me. Actually, no matter if
contour wants centres or edges, the actual behaviour seems strange. There
is some interpolation going on, apparently. The input `pdata` has shape
(12, 72) (or 72,12), and I definitely wouldn't expect this sub-grid
movement in the x-direction.
Any ideas?
Cheers,
Andreas. |