MATLAB Answers

Kyle
0

Scatter plot prevents update of contour plot. Any ideas why?

Asked by Kyle
on 19 Aug 2014
Latest activity Commented on by Kyle
on 20 Aug 2014
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!

  0 Comments

Sign in to comment.

2 Answers

Answer by Geoff Hayes
on 19 Aug 2014
 Accepted Answer

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 Comment

Thanks for running my code and troubleshooting it. I also found
plot(handles.scatterplot,limtime(:,1),limyvalue(:,1),'b.');
fixed the problem! I will also try to bring this to MathWorks attention.
Thanks again!

Sign in to comment.


Answer by Adam
on 19 Aug 2014

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 Comments

Hi Adam. Thanks for your advice. The reason why I wanted to plot the scatter plot above the contour plot is so I can check to make sure the contour plot was being made correctly. My final GUI will make the scatter plot optional.
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.
That's also a good idea. Thanks for the suggestion!

Sign in to comment.