Black Lives Matter. Please consider donating to Black Girls Code today.

Plotly.Py very slow on displaying plots? [Python]

Hello there,

I am trying to plot OHLC data on a plot, with the rangeslider with Plotly which worked, however it is very slow displaying the plots. I can imagne this is on my PC not being able to load the plots, perhaps, but on Google Colab the same problem occurs with slow/lagging plotting. I am plotting a ca 180k of OHLC datapoints. I tried splitting up the dataset into 4, which is what the code below does, hower this is still not working good. The plotting works and if you wait long enough (20-30mins) then the plot appears, but we are not speaking touching the rangeslider yet… I tried HTML, because i still want to use the rangeslider. Are there any known methods to make your plotting go faster or is it really just my PC? I don’t think it’s “that” bad…

import plotly.graph_objects as go
import plotly
import pandas as pd
import plotly.offline
import time

<Data Creation Stuff>

fig1 = go.Figure(data=[go.Candlestick(x=Frame1['Date'],
                open=Frame1['O'],
                high=Frame1['H'],
                low=Frame1['L'],
                close=Frame1['C'])])

fig2 = go.Figure(data=[go.Candlestick(x=Frame2['Date'],
                open=Frame2['O'],
                high=Frame2['H'],
                low=Frame2['L'],
                close=Frame2['C'])])

fig3 = go.Figure(data=[go.Candlestick(x=Frame3['Date'],
                open=Frame3['O'],
                high=Frame3['H'],
                low=Frame3['L'],
                close=Frame3['C'])])

fig4 = go.Figure(data=[go.Candlestick(x=Frame4['Date'],
                open=Frame4['O'],
                high=Frame4['H'],
                low=Frame4['L'],
                close=Frame4['C'])])

plotly.offline.plot(fig1, filename='test1.html')
plotly.offline.plot(fig2, filename='test2.html')
plotly.offline.plot(fig3, filename='test3.html')
plotly.offline.plot(fig4, filename='test4.html')

Thanks for your time in advance,
Jan

Hi @JanForThan 180 000 points is a lot! If you really need them all, you can use the Scattergl trace which uses the webGL library for a fast rendering of a large number of points and is compatible with a range slider. See https://plotly.com/python/compare-webgl-svg/ for more info about Scattergl. However, you won’t have a GL-equivalent of the OHLC trace, only for scatter points and lines.

Your other option is to use level-of-detail methods, where you represent more points when you zoom more. See for example the Dash demo https://dash-gallery.plotly.host/dash-datashader/ for this (the source code is https://github.com/plotly/dash-sample-apps/tree/master/apps/dash-datashader).