<p><code>decimate()</code>的缺点是它会对数据点进行下采样。<br/>
<strong>我认为这里需要<code>datashader()</code>,但是datashader不喜欢<code>ID</code>是一个分类变量而不是一个数值<br/>
<br/>
因此,<strong>一个解决方案是将分类变量转换为数字代码。</strong><br/>
<br/>
<strong>有关<a href="https://hvplot.holoviz.org/" rel="nofollow noreferrer">hvPlot</a>(我更喜欢)和<a href="http://holoviews.org/" rel="nofollow noreferrer">HoloViews</a>,请参见下面的代码示例:<br/></p>
<pre><code>import io
import pandas as pd
import hvplot.pandas
import holoviews as hv
# dynspread is for making point sizes larger when using datashade
from holoviews.operation.datashader import datashade, dynspread
# sample data
text = """
Event Time ID Venue
Javeline 11:25:21:012345 JVL Dome
Shot pot 11:25:22:778929 SPT Dome
4x4 11:25:21:993831 FOR Track
4x4 11:25:22:874293 FOR Track
Shot pot 11:25:21:087822 SPT Dome
Javeline 11:25:23:878792 JVL Dome
Long Jump 11:25:21:892902 LJP Aquatic
Long Jump 11:25:22:799422 LJP Aquatic
"""
# create dataframe and parse time
df = pd.read_csv(io.StringIO(text), sep='\s{2,}', engine='python')
df['Time'] = pd.to_datetime(df['Time'], format='%H:%M:%S:%f')
df = df.set_index('Time').sort_index()
# get a column that converts categorical id's to numerical id's
df['ID'] = pd.Categorical(df['ID'])
df['ID_code'] = df['ID'].cat.codes
# use this to overwrite numerical yticks with categorical yticks
yticks=[(0, 'FOR'), (1, 'JVL'), (2, 'LJP'), (3, 'SPT')]
# this is the hvplot solution: set datashader=True
df.hvplot.scatter(
x='Time',
y='ID_code',
datashade=True,
dynspread=True,
padding=0.05,
).opts(yticks=yticks)
# this is the holoviews solution
scatter = hv.Scatter(df, kdims=['Time'], vdims=['ID_code'])
dynspread(datashade(scatter)).opts(yticks=yticks, padding=0.05)
</code></pre>
<p><br/>
<strong>有关数据隐藏和抽取的更多信息:<br/></strong>
<a href="http://holoviews.org/user_guide/Large_Data.html" rel="nofollow noreferrer">http://holoviews.org/user_guide/Large_Data.html</a><br/>
<br/></p>
<p><strong>结果图:</strong><br/>
<br/>
<a href="https://i.stack.imgur.com/WS7Fv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WS7Fv.png" alt="using datashader for large data"/></a></p>