The title might seems simple, but I don't know what is the best way to achieve my goal.
So I got data stored in list:
- T, a common time series
- Data1
- Data2
- And so on...
Which gives me this plot with X and Y shared.
As you can see, I displayed 3 periods of my signal (60 Hz). There is 4 pulse phases, and a resting phase.
- Pulse1: t = [0:2]
- Pulse2: t = [2:4]
- Pulse3: t = [4:6]
- Pulse4: t = [6:8]
- Rest: t = [8:16.67]
I would like for each phase to have a different color. Moreover, if during one phase, a channel don't have a pulse, he shall take the color of the rest state. For instance, channel 2 (from the top !) on the plot above don't have a pulse until the 4th phase. So between t = [0:6] the curve should have the same color as between t = [8:16.67].
Additionally I'm looking for a solution to fix the yticks to avoid the overlapping between +5 and -5.
Thanks for the help!
EDIT:
Sample data + code:
Time = [3000.0, 3000.0, 3000.3, 3000.3, 3000.35, 3000.35, 3001.55, 3001.55, 3002.0, 3002.0, 3002.3, 3002.3, 3002.35, 3002.35, 3003.55, 3003.55, 3004.0, 3004.0, 3004.3, 3004.3, 3004.35, 3004.35, 3005.55, 3005.55, 3006.0, 3006.0, 3006.3, 3006.3, 3006.35, 3006.35, 3007.55, 3007.55, 3008.0, 3016.67, 3016.67, 3016.97, 3016.97, 3017.02, 3017.02, 3018.22, 3018.22, 3018.67, 3018.67, 3018.97, 3018.97, 3019.02, 3019.02, 3020.22, 3020.22, 3020.67, 3020.67, 3020.97, 3020.97, 3021.02, 3021.02, 3022.22, 3022.22, 3022.67, 3022.67, 3022.97, 3022.97, 3023.02, 3023.02, 3024.22, 3024.22, 3024.67, 3033.34, 3033.34, 3033.64, 3033.64, 3033.69, 3033.69, 3034.89, 3034.89, 3035.34, 3035.34, 3035.64, 3035.64, 3035.69, 3035.69, 3036.89, 3036.89, 3037.34, 3037.34, 3037.64, 3037.64, 3037.69, 3037.69, 3038.89, 3038.89, 3039.34, 3039.34, 3039.64, 3039.64, 3039.69, 3039.69, 3040.89, 3040.89, 3041.34]
Sig1 = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 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, 0.0, -0.675, -0.675, 0.0, 0.0, 1.2, 1.2, 0.0, 0.0, -0.3, -0.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.6, 4.6, 0.0, 0.0, -1.15, -1.15, 0.0, 0.0, 2.7, 2.7, 0.0, 0.0, -0.675, -0.675, 0.0, 0.0, 1.2, 1.2, 0.0, 0.0, -0.3, -0.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.6, 4.6, 0.0, 0.0, -1.15, -1.15, 0.0, 0.0, 2.7, 2.7, 0.0, 0.0, -0.675, -0.675, 0.0, 0.0, 1.2, 1.2, 0.0, 0.0, -0.3, -0.3, 0.0, 0.0]
f, ax = plt.subplots(7, sharex=True, sharey=True, figsize=(20,10))
ax[0].set_title("My title")
f.subplots_adjust(hspace=0)
plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False)
ax[0].plot(Time, Sig1, label = "signal 1")
ax[1].plot(Time, Sig2, label = "signal 2")
ax[2].plot(Time, Sig3, label = "signal 3")
ax[3].plot(Time, Sig4, label = "signal 4")
ax[4].plot(Time, Sig5, label = "signal 5")
ax[5].plot(Time, Sig6, label = "signal 6")
ax[6].plot(Time, Sig7, label = "signal 7")
f.text(0.5, 0.04, 'Time (ms)', ha='center')
f.text(0.04, 0.5, 'my Y axes label', va='center', rotation='vertical')
plt.show()
This sample will give you the same figure that I added (with one or 2 more subplots maybe). I just changed the names, thus the stupid naming :p One more thing I like to add, each subplot should have a legend with the labbel (i.e. a color line with the name signal i written nearby); and there should be also a color legend placed on the side of the graph like that:
- color line Phase 1
- color line...
- color lineResting phase