+60k Lines on one plot - Too slow
Mostrar comentarios más antiguos
Dear all,
I need to plot more than 60k lines. I'm doing it in a for loop. It takes too much time, about 170 seconds with the rest of the code. Is there any quicker way?
And also saveas(fig ... command takes too much time as well. About 60 seconds. I would like to save my plot as a png. file.
What are your suggestions to reduce time cost.
Best Regards,
4 comentarios
Ömer Yaman
el 25 de Jun. de 2022
Editada: Ömer Yaman
el 25 de Jun. de 2022
It's hard to imagine how 60k lines would be useful in a visualization and we may be able to suggest alternative approaches, or, perhaps, it will make instance sense to us why 60k lines is useful.
If your plotting inputs are vectors, it looks like you could compute all of the y values (slopes+energy+slopes) and store the results in a matrix and the plot it all at once using the template line below. However, that will still produce 60k line objects while will be painfully slow.
h = plot(1:5, rand(10,5))
Ömer Yaman
el 25 de Jun. de 2022
Respuesta aceptada
Más respuestas (2)
This is way too much data to plot on single figure realistically, of course it's going to take time.
But, the use of a loop and plot is the slowest way possible -- you're computing/drawing every single line individually instead of using the power of MATLAB in being vectorized...
y=[slopes(:,1)*energy+slopes(i,2)].'; % generate y(i,j) by column
hL=plot(energy,y); % plot the result
Here on a not terribly upscale system,
>> tic,y=m*e;toc
Elapsed time is 0.001305 seconds.
>> tic,hL=plot(e,y);toc
Elapsed time is 15.350194 seconds.
>> delete(hL)
>> close
although it took the renderer quite some additional time to actually draw and display the figure -- and at least as long to delete 60K graphics handles.
Since there are only some 1-2K pixels on a monitor anyway, 60K points is some 60X the possible density to be able to display; I would strongly suggest decimating the y array by at least a factor of 10 and likely you'll be unable to see any difference in the result at factors approaching 100X.
1 comentario
Ömer Yaman
el 25 de Jun. de 2022
Image Analyst
el 25 de Jun. de 2022
0 votos
Plot just a subsample of the curves. You'll never be able to see all 60k lines anyway, so just pick, say 1000 of them at random and plot those. You'll probably still get the general idea of what all the data would look like if you could have plotted them.
1 comentario
Ömer Yaman
el 27 de Jun. de 2022
Categorías
Más información sobre Spline Postprocessing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



