Problem with scatter plot over pcolor

6 次查看(过去 30 天)
Hello, I'm trying to plot gridded ocean model data and then overlay a scatter plot of irregular points (observation stations). For some reason I get errors and no plots at all whenever I try the code below, but of course the pcolor on its own works fine.
subplot(2, 1, 1)
pcolor(grid.lon, grid.lat, squeeze(data(i, :, :)))
hold on
scatter(points(:,1), points(:,2))
And this is the error I get (the number of which is equal to the number of points I am trying to scatter):
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
Warning: Patch FaceVertexCData length (0) must equal Vertices length (1) for flat EdgeColor
There must be some kind of work around to make this work.

采纳的回答

Alexander
Alexander 2011-4-22
Actually, It turns out that it was a problem with when I was calling the 'shading' handle. It needed to be before the scatter plot.

更多回答(2 个)

Jim Hokanson
Jim Hokanson 2013-6-21
编辑:Jim Hokanson 2013-6-21
Actually I think this is a bug. I am by no means a patch expert but it appears that scatter is implemented as a hggroup with a set of child patches that are the individual scatter points. What's really confusing to me is that Matlab seems to use two methods of coloring patches, one based on x,y,z data points and cData, and another based on vertices, faces, and FaceVertexCData. When switching from faceted to flat shading, it appears that Matlab switches to using vertex information (from xyz data), which given the description of the shading flat algorithm makes sense.
Now for the bug:
Scatter can be called with a [1 x 3], a [1 x m], a [m x 1], or a [m x 3] matrix (or a color string), oops, and the default which is also a single color (your case). If you use a single color, then then the hggroup has sufficient CData (I'm guessing) that Matlab doesn't bother to set CData or FaceVertexCData although the vertices are set. When you set shading to flat, then you have a non-empty vertices property and an empty FaceVertexCData property and then no one is happy.
In general the following code will reproduce this result:
N = 10 %For fun times make N even larger!
scatter(1:N,1:N);
shading flat
  3 个评论
Jim Hokanson
Jim Hokanson 2013-6-21
Ha! Yeah, I am in the middle of submitting a bug report on the topic. The first reply wasn't that helpful (actually just flat out wrong). I just get a kick out of your reply because I am also in the process of switching over to Python. The process has not been nearly as smooth as I had hoped (in my week or so of doing this) but I think it will get better.
Kelly Kearney
Kelly Kearney 2013-6-21
While I don't have an easy-to-replicate example at my figertips right now, I'll add that I've seen something similar to this when using the patchm function. Supposedly, patchm should allow the same cdata input as the patch function, but I've found it often fails to interpret scaled input properly; instead I have to manually set the ('facecolor', 'flat', 'cdata', cval) after the patch has been created. I haven't looked too closely at the cause, but it may have something to do with the fact that map axis surface objects assume shading flat by default.

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2011-4-22
One of your variables is empty, it appears.

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by