disable axes screen updating in gui

4 次查看(过去 30 天)
Drew
Drew 2012-11-13
I have an axes in a gui where i do the following
  1. Draw 3 time series in the axes using plotyy
  2. use datetick on the x axis.
  3. convert the numbers on the y axes from scientific notation to decimals.
  4. change the font size of the axes.
  5. change the line width.
The user can select which time series to plot from a popup. My issue is that when the user selects a time series, the chart doesn't update very quickly. You can actually see it doing steps 2, 3, 4, and 5 in sequence. Is there any way to disable the axes's screen updating until it's actually finished with steps 2 and 3?

回答(3 个)

Jan
Jan 2012-11-13
编辑:Jan 2012-11-13
Screen updates must be triggered by drawnow or pause. Do you have these commands in your code?
Actually the job does not look time-consuming. I expect "not very quickly" means someting below 0.1 seconds?! Or do you display millions of points?

Arthur
Arthur 2012-11-13
编辑:Arthur 2012-11-13
How are you updating the plot? Are you calling plotyy every time? It is usually much faster to update XData and YData of an existing plot, instead of replotting it with plotyy.
Post the code here,that makes it easier to see what the problem might be.

Drew
Drew 2012-11-13
Thanks for looking at this! Code is below. The plot takes maybe 0.1 seconds to update.
structOut = handles.timeSeriesData;
[axis, y1, y2] = plotyy(handles.ModelGraph, [datenum(structOut.WkStartDt), datenum(structOut.WkStartDt)], [structOut.Value, structOut.ModeledValue], ...
datenum(structOut.WkStartDt), structOut.(tsName));
datetick(axis(1), 'x', 'mm/yy');
datetick(axis(2), 'x', 'mm/yy');
set(axis(1), 'FontSize', 8);
set(axis(2), 'FontSize', 8);
set(y1, 'LineWidth', 2);
set(y2, 'LineWidth', 2);
set(y2, 'LineStyle', ':');
n = get(gca,'Ytick');
set(gca,'yticklabel',sprintf('%d |',n'));
legend('ScanVol', 'Modeled Value', strrep(tsName, '_', ' '));
  1 个评论
Arthur
Arthur 2012-11-14
You can probably speed this up by updating existing objects instead of creating new objects every time. Especially recreating a legend can be very slow... Also, you're repeating the same lines repeatedly on the plot(datetick, linewidth etc), which is not neccesary. Try if this works:
structOut = handles.timeSeriesData;
if isfield(handles,{'y1','y2'}) && ishandle(handles.y1) && ishandle(handles.y2)
%update existing plot
set(handles.y1,'XData',[Y1 XDATA],'Ydata',[Y1 YDATA]) %update data of y1
set(handles.y2,'XData',[Y2 XDATA],'Ydata',[Y2 YDATA]) %update data of y2
%update existing legend:
if isfield(handles,'legend') && ishandle(handles.legend)
legend(handles.legend,'ScanVol', 'Modeled Value', strrep(tsName, '_', ' '))
end
else
%create new plot
[handles.axis, handles.y1, handles.y2] = plotyy(handles.ModelGraph, [datenum(structOut.WkStartDt), datenum(structOut.WkStartDt)], [structOut.Value, structOut.ModeledValue], ...
datenum(structOut.WkStartDt), structOut.(tsName));
datetick(handles.axis(1), 'x', 'mm/yy');
datetick(handles.axis(2), 'x', 'mm/yy');
set(handles.axis(1), 'FontSize', 8);
set(handles.axis(2), 'FontSize', 8);
set(handles.y1, 'LineWidth', 2);
set(handles.y2, 'LineWidth', 2);
set(handles.y2, 'LineStyle', ':');
%create legend:
handles.legend('ScanVol', 'Modeled Value', strrep(tsName, '_', ' '));
end
%Update Yticks:
n = get(gca,'Ytick');
set(gca,'yticklabel',sprintf('%d |',n'));
%update handles structure
guidata(gcbo,handles)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Two y-axis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by