Clear Filters
Clear Filters

Displaying all plots in long code

2 views (last 30 days)
I have written a long code, with multiple plots that are generated. The plots all work individually, but when they are inside the long code, Matlab seems to only display two of them (out of the six). I can't upload my code as it is part of an assignment, but I was wondering if there was any way to fix this?

Accepted Answer

Walter Roberson
Walter Roberson on 22 Oct 2022
Generally speaking:
  • in most cases, if you have more than one plotting command on the same axes, such as plot() or scatter() or contour(), then unless you take extra steps, the later commands will clear the axes first, removing anything that had been drawn in the axes. This does not apply to commands such as title() or xlabel(). Also, there are internal calls and some forms or function calls that do not clear the axes first. The primary way of permitting multiple graphics on the same axes, is to call "hold on" for the axes after the first graphic is drawn; use "hold off" after the last graphic is drawn
  • if you use subplot() and the calculated position of the axes would overlap any other axes without being exactly the same position as the original axes, then subplot() will delete the axes that is underneath. If you have reason to adjust positions of subplots, then you should consider using the newer tiledlayout()
  • if imshow() detects that the axes is in the default position for the axes, and that hold is not turned on for the axes, then imshow() will delete the axes and create a new one. It does not just clear the axes -- clearing axes would retain some properties and would retain identity. imshow() is often convenient, but it is a meanace for setting up careful interfaces
  • there are some graphics functions, especially in Control Systems Toolbox, that turn out to create interactive plots. Because that involves attaching behaviour to the graphics window, those plots cannot be created inside a subplot, and will delete the entire content of the figure. bode and frequency response plots are examples of these. In such a situation, you may wish to create a new figure() to put the plot inside.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!