Very slow adding datatips to datetime plots

6 次查看(过去 30 天)
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?

回答(1 个)

Divyank
Divyank 2023-3-16
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.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by