Can anyone help me on why the contour plaot is messed?

1 view (last 30 days)
Hello All, Attached it the contour plot of my code:
I have it in the GUI.

Accepted Answer

Walter Roberson
Walter Roberson on 15 Jul 2016
You appear to be using R2014a or earlier. In those releases, uicontrol always appeared on top of any other content, so when you positioned your plot axes on top of your uicontrol('style','push'), the uicontrol showed up on top instead of your plot covering up your pushbutton (which would have made it difficult to click the push button.)
Your basic problem is that you have not taken enough care to be sure that your pushbutton and your plot axes do not overlap.
You appear to have given a very small area for your plot axes.
My speculation is that you are probably using contour() expecting that the current axes is the correct axes to draw in, but that your current axes has become something different than what you expect. There are a number of reasons that a current axes might not be what you expect, including that you might be in debugging mode and when you clicked on a graph to move it out of the way so you could see the command window (or variable browser or the like), that click would change the current axes.
It is safer to assume that the current axes could change at any time, and so always pass the axes to all plotting routines. For example,
ax = handles.axes17; %an axes you defined in GUIDE
contour(ax, X, Y, Z, levels)
hold(ax, 'on')
title(ax, 'Cool little contour plot')
plot(ax, 1:10, rand(1,10), 'r')
colorbar(ax)
set(ax, 'xgrid', 'on')
Notice how this code never uses gca itself and never assumes that the "current axes" is the one to draw into.

More Answers (0)

Categories

Find more on Contour Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!