Why is subplot much faster than digit?

I am building a data analysis platform in MATLAB. One of the system functions is to create many graphs. Only one chart is available at any given time and the user can jump to the next / previous one on request (the emphasis here is that there is no need to open multiple windows).

Initially, I used the command figure

every time a new graph was shown, but I noticed that when the user navigated to the next graph, this command took a little longer than I wanted. Deterioration in usability. So I tried using subplot

this instead and it worked much faster.

After seeing this behavior, I did a little experiment, timing. It figure

takes about 0.3 seconds for the first start and subplot

0.1 seconds. The average running time figure

is 0.06 seconds with a standard deviation of 0.05, while it subplot

only accepts 0.002 with a standard deviation of 0.001. It seems like subplot

an order of magnitude faster.

The question arises: in a situation where only one window is available at any given time, is there a reason to use a number?

Is there any value lost when using `subplot 'in general?

(This consideration can be done even if you can only do it once).

+1


source to share


2 answers


The call does nothing more than create a new one with some handy positioning options wrapped around. subplot

axes

Axis objects are always children of shape objects , so if the window is figure

not open, subplot

will open it. This action takes a little time. So instead of opening a new shape window for each new plot, it's faster to simply create a new axes object using subplot

what you defined correctly. To save some memory, you can clear the previous graph as suggested by Daniel . clf

As I understand it, you don't want to create axes at tiled positions, you just want to create one axis object. Thus, it would be even faster to use the command directly. actually overkill. axes

subplot



If all of your plots have the same axis constraints and labels, not even needed. Use (clear axes) to delete the previous plot, but keep the labels, limits, and grid. clf

cla

Example:

%// plot #1
plot( x1, y2 );
xlim( [0,100] ); ylim( [0,100] );
xlabel( 'x' );
ylabel( 'y' );

%// clear plot #1, keep all settings of axes

%// plot #2
plot( x2, y2 );

...

      

+3


source


Use figure

once to create the shape and clf

to clear the content before repainting.



0


source







All Articles