I have two time series:
- First row is prediction
- second row is ground truth
I want remove this red area, where it should be flexible.
I mean there is no distance between them like this picture, without removing x-axis and y-axis
Here is my code, how do I do that?
#@title Animate Define
# Display Parameter
start = 0
end = 1024
Xt = X_unseen[start:end]
yp = y_pred[start:end]
yt = y_true[start:end]
# Get mask of every class for prediction
bl_pred = yp == 0
p_pred = yp == 1
qrs_pred = yp == 2
t_pred = yp == 3
# get mask of every class for ground truth
bl_true = yt == 0
p_true = yt == 1
qrs_true = yt == 2
t_true = yt == 3
# create figure with two rows and one column
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(20, 8))
# Plotting for prediction
prev_class = None
start_idx = start
for i in range(start, end):
current_class = None
if bl_pred[i]:
current_class = 'grey'
elif p_pred[i]:
current_class = 'orange'
elif qrs_pred[i]:
current_class = 'green'
elif t_pred[i]:
current_class = 'purple'
if current_class != prev_class:
if prev_class is not None:
ax1.axvspan(start_idx, i, color=prev_class, alpha=0.5)
start_idx = i
prev_class = current_class
# Fill the last region
if prev_class is not None:
ax1.axvspan(start_idx, end, color=prev_class, alpha=0.5)
# Plotting for ground truth
prev_class = None
start_idx = start
for i in range(start, end):
current_class = None
if bl_true[i]:
current_class = 'grey'
elif p_true[i]:
current_class = 'orange'
elif qrs_true[i]:
current_class = 'green'
elif t_true[i]:
current_class = 'purple'
if current_class != prev_class:
if prev_class is not None:
ax2.axvspan(start_idx, i, color=prev_class, alpha=0.5)
start_idx = i
prev_class = current_class
# Fill the last region
if prev_class is not None:
ax2.axvspan(start_idx, end, color=prev_class, alpha=0.5)
# first row for prediction (X_unseen, y_pred)
ax1.plot(Xt, color='blue')
ax1.set_title('Prediction')
# second row for ground truth (X_unseen, y_true)
ax2.plot(Xt, color='blue')
ax2.set_title('Ground Truth')
# plot
plt.show()
Basically, this code is plotting in same figure where first row is prediction and second row is ground truth. I want remove distance of blank area (white) between them.