How do you pause rendering of a figure until you're done setting properties?

15 views (last 30 days)
I have a script that creates a plot and then sets 9 different properties on that plot:
heat = heatmap( ... )
heat.ColorMethod = ...
heat.MissingDataColor = ...
heat.MissingDataLabel = ...
heat.YLabel = ...
heat.XLabel = ...
heat.Title = ...
heat.CellLabelColor = ...
heat.Colormap = ...
It seems that what MATLAB is doing is rendering the original plot, then setting the first property and rendering the whole thing again, then setting the second property and rendering the whole thing again, and so on until all of the properties are set.
Rendering the same figure nine times when I only need the final render seems ridiculous. Is this indeed what's happening? If so, is it possible to tell MATLAB to wait until all of the properties are set until rendering the heatmap? I saw the drawnow function in the documentation which seems to imply that there is some kind of buffering of graphics updates going on, but is there any way to control it beyond flushing the buffer with drawnow?

Accepted Answer

Steven Lord
Steven Lord on 12 Nov 2018
Specify the property names and values in the heatmap call itself as a series of name-value pair arguments. See the example in the "Name-Value Pair Arguments" section on the heatmap documentation page.
Alternately you can call the set function to set multiple properties at once. In fact, in some cases you must do this, like when you want to change the XData and YData properties of a line created by plot to different sized data.
>> h = plot(1:10, 1:10);
>> h.XData = 1:11;
Warning: Error creating or updating Line
Error in value of one or more of the following properties: XData YData
Array is wrong shape or size
>> h.YData = 1:11;
>> set(h, 'XData', 1:12, 'YData', 1:12);
The line disappears when the second line issues the warning and reappears when the condition that caused the warning is corrected on the third line. The last line changes the X and Y data simultaneously and does not issue a warning.

More Answers (1)

Stephen23 on 12 Nov 2018
Edited: Stephen23 on 12 Nov 2018
This might work:
  1. Find its parent figure (e.g. gcf) and set its 'Visible' property to 'off'
  2. Change the properties
  3. Set the figure's 'Visible' property back to 'on'




Community Treasure Hunt

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

Start Hunting!