Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

plt.eventplot refuses lineoffsets

This should be quite easy to reproduce:

plt.eventplot(positions=[1, 2, 3], lineoffsets=[1, 2, 3])

raises

ValueError: lineoffsets and positions are unequal sized sequences

For reasons I can't figure out, because they clearly aren't.

like image 544
Martino Avatar asked Aug 31 '25 01:08

Martino


1 Answers

If I understand correctly you want to plot 3 lines, at different starting heights (offsets). The way this works with plt.eventplot is as follows:

import numpy as np
import matplotlib.pyplot as plt

positions = np.array([1, 2, 3])[:,np.newaxis]   # or np.array([[1], [2], [3]])
offsets = [1,2,3]

plt.eventplot(positions, lineoffsets=offsets)
plt.show()

You have to set the offset for each group of data you want to plot. In your case, you have to divide the list into a 3D array (shape (m,n) with m the number of datasets, and n number of data points per set). This way plt.eventplot knows it has to use the different offsets for each group of data. Also see this example.

like image 193
rinkert Avatar answered Sep 02 '25 15:09

rinkert