Skip to content

docs: describe solution in FAQ for slow datetime arrays #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/sphinx/FAQ.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,42 @@ Furthermore combined with holoviews, datashader can also be employed in an inter
.. image:: _static/datashader.png


.. raw:: html

</div>
</details>
<br>
<details>
<summary>
<a><b>Pandas or numpy datetime works much slower than unix epoch timestamps?</b></a>
</summary>
<div style="margin-left:1em">

This stems from the plotly scatter(gl) constructor being much slower for non-numeric data. Plotly performs a different serialization for datetime arrays (which are interpreted as object arrays).
However, plotly-resampler should not be limited by this - to avoid this issue, add your datetime data as `hf_x` to your plotly-resampler ``FigureResampler.add_trace`` (or ``FigureWidgetResampler.add_trace``) method.
This avoids adding (& serializing) *all* the data to the scatter object, since plotly-resampler will pass the aggregated data to the scatter object.

Some illustration:

.. code:: python

import plotly.graph_objects as go
import pandas as pd
import numpy as np
from plotly_resampler import FigureResampler

# Create the dummy dataframe
y = np.arange(1_000_000)
x = pd.date_range(start="2020-01-01", periods=len(y), freq="1s")

# Create the plotly-resampler figure
fig = FigureResampler()
# fig.add_trace(go.Scatter(x=x, y=y)) # This is slow
fig.add_trace(go.Scatter(), hf_x=x, hf_y=y) # This is fast

# ... (add more traces, etc.)


.. raw:: html

</div>
Expand Down