<jupyter_start><jupyter_text>Title  Spikes Element  Dependencies Bokeh  Backends Bokeh Matplotlib<jupyter_code>import numpy as np
import holoviews as hv
hv.extension('bokeh')<jupyter_output><empty_output><jupyter_text>Spikes represent any number of horizontal or vertical line segments with fixed or variable heights. There are a number of different uses for this type.  First of all, they may be used as a rugplot to give an overview of a one-dimensional distribution. They may also be useful in more domain-specific cases, such as visualizing spike trains for neurophysiology or spectrograms in physics and chemistry applications.In the simplest case, a Spikes object represents coordinates in a 1D distribution:<jupyter_code>%%opts Spikes (line_alpha=0.4) [spike_length=0.1]
xs = np.random.rand(50)
hv.Spikes(xs)<jupyter_output><empty_output><jupyter_text>We can overlay ``Spikes`` on top of other ``Chart`` elements (such as ``Points`` or ``Curve``) if we want to draw attention to where samples are along the x-axis:<jupyter_code>%%opts Points (color='red')
ys = np.random.rand(50)
hv.Points((xs, ys)) * hv.Spikes(xs)<jupyter_output><empty_output><jupyter_text>When supplying a second dimension to the ``Spikes`` element as a value dimension, these additional values will be mapped onto the line height. Optionally, you may also supply a colormap ``cmap`` and ``color_index`` to map the value dimensions to a suitable set of colors. This way we can, for example, plot a [mass spectrogram](https://en.wikipedia.org/wiki/Mass_spectrometry):<jupyter_code>%%opts Spikes (cmap='Reds')
hv.Spikes(np.random.rand(20, 2), kdims=['Mass'], vdims=['Intensity'])<jupyter_output><empty_output><jupyter_text>Another possibility is to draw a number of spike trains representing the firing of neurons, of the sort that are commonly encountered in neuroscience. Here we generate 10 separate random spike trains and distribute them evenly across the space by setting their ``position``. By declaring some ``yticks``, each spike train can be labeled individually:<jupyter_code>%%opts Spikes [spike_length=0.1] NdOverlay [show_legend=False]
hv.NdOverlay({i: hv.Spikes(np.random.randint(0, 100, 10), kdims=['Time']).opts(plot=dict(position=0.1*i))
              for i in range(10)}).opts(plot=dict(yticks=[((i+1)*0.1-0.05, i) for i in range(10)]))<jupyter_output><empty_output><jupyter_text>Finally, we may use ``Spikes`` to visualize marginal distributions as adjoined plots using the ``<<`` adjoin operator:<jupyter_code>%%opts Spikes (line_alpha=0.2)
points = hv.Points(np.random.randn(500, 2))
points << hv.Spikes(points['y']) << hv.Spikes(points['x'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11315099288122893, 'fraction_numerical': 0.014986886474334956, 'mean_word_length': 6.4581005586592175, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 25, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '189135', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 873, 'n_tokens_neox': 831, 'n_words': 286, 'path': 'examples/reference/elements/bokeh/Spikes.ipynb', 'repo_name': 'stonebig/holoviews', 'size': '2669'}