Closed remrama closed 1 year ago
Hi @remrama!
Thanks for the super detailed PR, loved it! Let's go with plt.stairs
, it is indeed much better than the current plt.step
. I think plt.hlines
gets messy with longer hypnograms. I like the fill
parameter too, definitely would like to add this as a customization parameter.
hypno_str = np.tile(["W", "W", "N1", "N2", "N2", "N2", "N3", "N3", "N2", "R", "R"], 10)
I'm somewhat confused about how hypnograms are represented with
yasa.plot_hypnogram
, and even somewhat suspicious that the plotted hypnogram is shifted (left) by 1 epoch. I suppose there are multiple ways to view a graph like this, especially how much interpretation you might put on vertical lines. I think the hypnogram includes stages that represent a chunk of time (e.g., epoch 1 with standard 1/30 sf represents the window between 0-30 seconds), whereas the current plotting withplt.step
doesn't handle that well.Examples below, but first I'll jump ahead to my conclusion: Maybe a combined use of
ax.hlines
(for the lines) andax.stairs
(for the fill) would make for a better and more accurate visualization?Examples
Using some super-short simple hypnograms...
5-min hypnograms aren't 5 minutes
This example shows plots of 2 different hypnograms that should be 5 minutes long. They only differ by whether it takes 30 or 60 seconds to fall asleep. Note the difference in the first Wake epoch(s) between the two graphs. In the first graph, it should be 60 seconds long but it's 30. In the second graph, it should be 30 seconds long but it's... 0?
Zoom in on 1-min: flat line despite 2 stages
This time using YASA to make sure my code wasn't different from the underlying function.
Alternatives
I like the use of
plt.stairs()
because of the explicit passing of bin edges. Also thefill
option is nice, though you can see that in a case where a hypnogram ends on non-wake, it will automatically jump up to 0. This can be changed with parameters! Just pointing it out as something to be careful about with defaults. I actually likeplt.hlines()
because it avoids the whole vertical line thing.YASA's function
Again just showing that my code is providing the same output as YASA. This should match the first panel of previous image, where there should be 60 seconds of Wake to start, but there's 30.