Very slow adding datatips to datetime plots

4 views (last 30 days)
David K
David K on 13 Feb 2023
Answered: Divyank on 16 Mar 2023
I have a custom plotting tool that allows me to plot my data in many different formats. I've found that when my time variables are plotted as a datetime rather than as a simple number, the plotting is much much slower. I'm plotting dozens of objects in the same plot, so it adds up over time. I ran the profiler and found that the majority of the slowdown is happening when I assign custom datatips to my plots.
hPlot(end).DataTipTemplate.DataTipRows = customDataTips;
where hPlot is a Line or Scatter object and customDataTips is an array of DataTipTextRow objects. The data tips are the same for both ways I plot, except that the datatip for XData points to a datetime instead of a number.
Why is this so much slower, and is there a way to speed up the process?

Answers (1)

Divyank
Divyank on 16 Mar 2023
Hello @David K, the reason why plotting datetime variables is slower than plotting numerical values is that datetime values are more complex and require additional processing. When a datetime variable is plotted, it needs to be converted to a numerical format that the plotting tool can understand. This conversion process can be time-consuming, especially if you have a large dataset.
In addition, assigning custom datatips can also slow down the plotting process, especially if you are assigning them to many objects in the same plot. This is because each datatip needs to be rendered separately, which can add up to a significant amount of time.
One way to speed up the process is to pre-compute the custom datatips and store them in an array before plotting. This way, you can avoid the overhead of assigning them to each object individually. You could also consider reducing the number of data points being plotted or using a lower resolution datetime format, such as hourly or daily instead of minute-by-minute, depending on your use case. This will reduce the overall amount of data that needs to be processed and plotted, and can significantly speed up the plotting process.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!