Saturday, July 28, 2018

Published July 28, 2018 by with 1 comment

How Do I Make Plotly Faster?

Plotly is a really nice plotting library, but it can be quite slow. Is there any way to speed it up?

Basic test

To compare techniques for making plotly faster, I'm benchmarking a scatter plot with 8 traces that each have 1250 random points with y values between 0 and 10. Each plot is using markers instead of lines.

My baseline result is ~1 fps. (code). Note that I included many other performance tips at the very end.

First improvement - use scattergl

Once you get into the 10's of thousands of points and you are generating a scatter plot with markers, setting the trace type to 'scattergl' instead of 'scatter' can lead to large performance improvements. Doing it here takes the frame rate up to ~6 fps. (code)

Second improvement - use Plotly.react

Using Plotly.newPlot is slow. Using Plotly.react is better. Switching to that here takes the frame rate up to ~23 fps. (code)

Third improvement - fix axes

Letting plotly autorange means it needs to do relayouts often and requires it to calculate the range each time. Specifying the range can speed it up. Doing that here takes the frame rate up to ~24 fps. (code)

Fourth improvement - remove legends

Drawing the legends is surprisingly expensive. If you have legends that are changing often and have a large number of traces, simply hiding the legends can be a huge performance boost. Doing that here takes the framerate up to ~33 fps. (code)

And that's it. Making simple tweaks here showed steady improvements and got it from ~1 fps to ~33 fps. Being able to fix axes and hide legends will obviously depend on your application, but something like using Plotly.react is a pretty general-purpose solution. Here's a plot summarizing the gains:

make plotly fast


These gains are specific to this situation. Changing # of points, # of traces, plot type, etc. will give you different benefits, but playing around with these ideas should help in general.

Final situation - huge data

What if you have a huge amount of data? If instead of each trace having 1250 points, it has 125,000 points, can you still make it fast? With where we left off, I'm getting ~0.5 fps. Plotly has a type for this situation called 'pointcloud'. Switching to it gives me ~6 fps. (code)

It does have its drawbacks in terms of styling and events, but being able to get 1M points plotted reasonably quickly is nice for certain situations so it's a cool thing to have available.

More plotly performance tips

Plotly is slow with a lot of traces. I found a workaround for some situations.

Plotly can be slow with colored markers. Here is a workaround for some situations.

When using many plots, loading in a specific order can be helpful. Here's how.

When plotting a huge amount of data, decimation can help. Here's an example.


      edit

1 comment:

  1. 🔥 มาลุ้นโบนัสก่อนโตได้แล้วที่นี่ที่เดียว
    🎮สล็อต บาคาร่า ยิงปลา ไพ่ (ace card) มีจบครบที่เดียว
    ⚽️ คอฟุตบอล ต้องที่ IPRO356 เท่านั้น เคลียร์บิลรวดเร็วทันใจ จ่ายเลยทันที
    💎 สมัครสมาชิก ฟรี ไม่มีค่าบริการ
    📱รองรับระบบมือถือทุกรุ่นทั้ง android และ ios
    ⚖️ ฝาก-ถอน ไม่มีขั้นต่ำ ไม่ต้องทำเทิร์นเลยนะคะ
    💸 มีสูตรแจกให้ฟรีพร้อมกลุ่มนำเล่น

    ReplyDelete