How do I guage plotting speed when using the plot function?
Afficher commentaires plus anciens
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.
Réponse acceptée
Plus de réponses (1)
Kirby Fears
le 16 Sep 2015
Modifié(e) : Kirby Fears
le 16 Sep 2015
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 commentaires
Brad
le 16 Sep 2015
Kirby Fears
le 16 Sep 2015
Modifié(e) : Kirby Fears
le 16 Sep 2015
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
Steven Lord
le 17 Sep 2015
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.
Brad
le 23 Sep 2015
Catégories
En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!