您的问题不是很清楚,但我认为您需要一种方法在情节中绘制vlines。
这可能会有所帮助。
import numpy as np
import matplotlib.pyplot as plt
# Some example data to display
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
fig, ax = plt.subplots()
ax.plot(x, y,'b--')
ax.vlines(x =[1,2,3,4,5,6], ymin=-1.085, ymax=1.085, colors='k', linestyles='--')
ax.grid()
或者可能是这样的:
import numpy as np
import matplotlib.pyplot as plt
x = [1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1]
t = np.arange(0,len(x))
code_1 = (1,0,1,0,1,0)
code_0 = (0,1,0,1,0,1)
x1 = [1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0]
x2 = np.logical_xor(x1, x)
g, (ax0, ax1, ax2) = plt.subplots(3, sharex=True, sharey=True, figsize=(12,8))
ax0.step(t,x,'b', lw=3, label = "Data Signal");ax0.legend(loc='center left', bbox_to_anchor=(1, 0.5),fontsize=16);ax0.vlines(x =[np.arange(0,len(x))], ymin=-0.1, ymax=1.085, colors='k', linestyles='--');ax0.axes.xaxis.set_visible(False);ax0.axes.yaxis.set_visible(False);plt.grid(True)
arrow_kwargs = {'arrowprops':dict(arrowstyle="<->",lw=2.5)}
ax0.annotate(xytext=(5,1.1), xy=(11,1.1), s='', **arrow_kwargs); ax0.text(8, 1.2, '$T_{b} $', va='bottom', ha='center',fontsize=20)
ax1.vlines(x =[np.arange(0,len(x))], ymin=-0.1, ymax=1.1, colors='k', linestyles='--');ax1.step(t,x1, 'm', lw=3, label = "Pseudo-random\ncode",alpha = 0.6);ax1.legend(loc='center left', bbox_to_anchor=(1, 0.5),fontsize=16);ax1.axes.xaxis.set_visible(False);ax1.axes.yaxis.set_visible(False);ax1.grid()
ax2.step(t,x2, 'orange', lw=3, label = "Transmitted signal\nData XOR PN code",alpha = 0.6);ax2.legend(loc='center left', bbox_to_anchor=(1, 0.5),fontsize=16);ax2.axes.xaxis.set_visible(False);ax2.axes.yaxis.set_visible(False);ax2.grid()
ax2.vlines(x =[np.arange(0,len(x))], ymin=-0.1, ymax=1.1, colors='k', linestyles='--')
ax2.annotate(xytext=(8,0.1), xy=(9,0.1), s='', **arrow_kwargs); ax2.text(8.5, 0.15, '$T_{c}$', va='bottom', ha='center',fontsize=20)
g.subplots_adjust(hspace=0.1);