How do I guage plotting speed when using the plot function?

I'm using the plot function to produce an XY plot of altitude versus time. The total number of data points is 21,834. Using the tic and toc commands, it is taking 227 seconds to plot all of these points. This seems a bit excessive. However, in reading the MATLAB documentation, as well as several other questions regarding this topic, I'm a bit confused as to what a reasonable expectation of plot time would actually be.
Is this a reasonable amount of time given the number of data points.

 采纳的回答

Measuring graphics performance is kind of a rich topic. There are a couple of different variables which are important to consider. I've been writing introductions to some of these on the MATLAB Graphics blog:
Perhaps one of those posts would be a good starting point for you.

3 个评论

Mike, thank you for the references. I think I found the issue. calling the plot function repeatedly seems to be sucking down a lot of time. I may have to come up with an alternate plotting ConOps.
Then that's probably the case I talked about in Number of graphics objects. There are a number of possible workarounds in there. Be sure to check out the first comment on that post by Yair Altman for more good suggestions.
It is similar and I'm looking to come up with a similar approach. Thanks again!!

请先登录,再进行评论。

更多回答(1 个)

Below is a simple test to show that plotting 21 thousand observations does not take long. The below plot is done in 0.005 seconds.
x=1:21834;
y=rand(1,21834);
plot(x,y)
Are you calling the plot function repeatedly? If you show some of your code, you may get help speeding up plot performance.

5 个评论

Kirby, here is a sample of the code (not all 21,834 data points - just 10), where the Measured_Data is altitude. Yes, you are correct when you ask if I call the plot function repeatedly. This is done to ensure altitudes from various sources are always hard color coded where applicable. Looks like I may have to come up with another plotting approach.
% Variables for plotting
To_Time = 58560;
Time_Tag = [58568.4; 58571.8; 58573.4; 58574.4; 58577.4; 58579.8; 58582.4; 58584.1; 58587.6; 58589];
ID = [10; 2; 3; 4; 10; 6; 7; 2; 10; 2];
Measured_Data = [1.25; 2.31; 3.3; 4.9; 5.7; 6.7; 7.1; 8.6; 9.1; 10];
% Calculate TALO times for all IDs
TALO_Time = Time_Tag - To_Time;
% Preallocate
LegCol = cell(1, size(ID, 1));
color = cell(1, size(ID, 1));
% Setup cases for auto legend generation
for idx = 1:size(ID, 1)
switch ID(idx)
case 1
LegCol{idx} = 'Data-1';
color{idx} = [1 0 0]; % red
case 2
LegCol{idx} = 'Data-2';
color{idx} = [0 1 0]; % green
case 3
LegCol{idx} = 'Data-3';
color{idx} = [0 0 1]; % blue
case 4
LegCol{idx} = 'Data-4';
color{idx} = [1 0.55 0]; % orange
case 5
LegCol{idx} = 'Data-5';
color{idx} = [1 0 1]; % magenta
case 6
LegCol{idx} = 'Data-6';
color{idx} = [0 1 1]; % cyan
case 7
LegCol{idx} = 'Data-7';
color{idx} = [0 0 0]; % black
case 8
LegCol{idx} = 'Data-8';
color{idx} = [1 1 0]; % yellow
case 9
LegCol{idx} = 'Data-9';
color{idx} = [0.58 0 0.83]; % violet
case 10
LegCol{idx} = 'Data-10';
color{idx} = [0.72 0.53 0.04]; % gold
end % Transpode LegCol and color data for legend use
Legend_Nomenclature = transpose(LegCol);
New_Colors = transpose(color); % Setup the TALO Plot
h = plot(TALO_Time(idx), Measured_Data(idx), 'o', 'Color', New_Colors{idx}, 'MarkerSize', 14);
set(h, 'MarkerFaceColor', New_Colors{idx});
hold all;
end
So how many IDs do you have in the real code? If you're only calling plot 10 times, it shouldn't be that slow. The modifications below allow you to call plot N times if there are N unique ID values.
% Variables for plotting
To_Time = 58560;
Time_Tag = [58568.4; 58571.8; 58573.4; 58574.4; 58577.4; 58579.8; 58582.4; 58584.1; 58587.6; 58589];
ID = [10; 2; 3; 4; 10; 6; 7; 2; 10; 2];
Measured_Data = [1.25; 2.31; 3.3; 4.9; 5.7; 6.7; 7.1; 8.6; 9.1; 10];
% Calculate TALO times for all IDs
TALO_Time = Time_Tag - To_Time;
% LegCol labels
LegCol = arrayfun(@(d)['Data-',num2str(d)],1:10,'UniformOutput',false)';
% colors: red,green,blue,orange,magenta,cyan,black,yellow,violet,gold
color = {[1 0 0], [0 1 0], [0 0 1], [1 0.55 0], [1 0 1], [0 1 1], ...
[0 0 0], [1 1 0], [0.58 0 0.83], [0.72 0.53 0.04]}';
% Setup cases for auto legend generation
activeID=unique(ID');
for idx = activeID,
plotidx=(ID==idx);
h = plot(TALO_Time(plotidx), Measured_Data(plotidx), 'o', 'Color', color{idx}, 'MarkerSize', 14);
set(h, 'MarkerFaceColor', color{idx});
hold all;
end
You could possibly combine this into a single plot call if you set the color order and specify your ID-wise Xn and Yn pairs with the syntax
plot(X1,Y1,LineSpec,...,Xn,Yn,LineSpec);
You can modify the color order of your axes as discussed in the link below. You already have the RGB codes you need. http://www.mathworks.com/help/matlab/graphics_transition/why-are-plot-lines-different-colors.html
Kirby, I agree with your approach. However, the files I process can contain between 1 and 34 unique IDs (many of which are repeated 100s of times) - all of which need to have a specific color code. I may still get this approach to work, though. Will take a bit more thinking, but it could work. Thanks for the push.
Try calling SCATTER instead of PLOT multiple times. You can specify the colors of the points to be displayed as a vector, which is used to map to the colormap, or as a matrix of RGB triplets.
rgbTriplets = dec2bin(0:7, 3) == '1';
colorIndices = randi([1 size(rgbTriplets, 1)], 10, 1);
colorOfEachPoint = rgbTriplets(colorIndices, :);
This generates 10 random point "categories" and creates a matrix with the corresponding color for each point's category in that point's row. All the points with index 1 should be black [0 0 0], 2 should be blue [0 0 1], etc.
[colorIndices, colorOfEachPoint]
Now use colorOfEachPoint as the C input to SCATTER.
Steve, thank you. This approach works great!

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Data Distribution Plots 的更多信息

产品

标签

Community Treasure Hunt

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

Start Hunting!

Translated by