Scatter plot prevents update of contour plot. Any ideas why?
조회 수: 3 (최근 30일)
이전 댓글 표시
I have made a GUI in GUIDE to plot a scatter plot above a contour plot. Next to these plots I have two edit boxes for x-axis min and x-axis max, and an "update plots" button to update the plots with the new x min and max values. Unfortunately, if I have a scatter plot, the contour plot will take a long time to update when certain x-axis values are used. For example, if I change x min = 500, the plots will update in ~ 1 second; however, if I use x min = 700 the plots take over 15 minutes to update. If I take out the scatter plot the problem goes away. Any ideas why this happens?
I have included a simplified code and sample data (attached) as an example of the issue. This code only updates the contour plot, but you can still see the problem. This problem is reproducible on two computers. I have also included a screenshot of the simplified GUI.
Thanks in advance for your help!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145140/image.png)
댓글 수: 0
채택된 답변
Geoff Hayes
2014년 8월 19일
Kyle - I was able to reproduce the same behaviour with R2014a on OS X 10.8.5. Reducing the number of points that were being displayed by scatter to about 1000 at any one time (from the 26000) the software to update on each call to Update Plots. Why this matters, I don't know.
Like Adam, I don't know why increasing the minimum of x to 700 should cause it to be slower. Though it does seem to work the other way too: if you decrease the maximum to 4000, the same slow behaviour is observed. It could have something to do with the smaller range in the data and so contourf has to work harder (?). Reducing the number of contour levels from 50 to 25 does seem to allow the software to continue without any noticeable lag in performance
contourf(handles.contourplot,X,Y,Z',25,'LineStyle','none');
Though this doesn't really explain why if scatter is never called, then there is no performance lag with contourf. I wondered about the graphics created by scatter so called cla(handles.scatterplot,'reset') to reset the scatter plot axes, but this didn't have the desired (positive) effect.
I replaced the call to scatter with
plot(handles.scatterplot,limtime(:,1),limyvalue(:,1),'b.');
and this did work. So the same amount of data is being drawn on the axes, but it is being drawn differently.
So I think you have a couple of workarounds. And this may be a good example to bring to the attention of The MathWorks to get a better understanding of what is going on behind the scatter function.
추가 답변 (1개)
Adam
2014년 8월 19일
I'm not sure why changing x min to 700 would cause it to be slower than 500 (when I plot the raw data without the GUI part it doesn't), but as a general comment that is a lot of data for a scatter plot. When I plotted it the rendering struggled at full x range though I am on a laptop.
If you are limiting the x range so that you can actually see the individual points though it should generally get faster, not slower. If you can't see the individual points then a scatter plot is probably not a good choice as it will be very slow rendering a lot of points you can't even distinguish.
댓글 수: 3
Adam
2014년 8월 20일
You could also consider just scatter plotting a representative sample of the data if performance is an issue still with it. If the data were sorted you might be able to plot just every 10th point or fewer and still get the rough shape of the overall data.
참고 항목
카테고리
Help Center 및 File Exchange에서 Scatter Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!