[-- -- 50 -- -- 52 49 51 -- 52 49 55 51]
你可以策划
[50 52 49 51 52 49 55 51]
mask
它本身
ax.plot(x_values[~y2_values.mask], y2_values[~y2_values.mask])
完整示例:
import numpy as np
import matplotlib.pyplot as plt
y_values = [92,94,100,97,98,102,99,101,97,102,99,105,101]
y_values = np.ma.array(y_values)
threshold = 99
y2_values = np.ma.masked_where(y_values < threshold, [v-50 for v in y_values])
y3_values = np.ma.masked_where(~(y_values < threshold), [v-80 for v in y_values])
x_values = np.array([0,1,2,3,4,5,6,7,8,9,10,11,12])
fig, ax = plt.subplots(3, sharex=True, facecolor='w')
fig.subplots_adjust(hspace=0.25)
ax[0].plot(x_values, y_values, marker="o")
ax[0].set_title('All values')
ax[1].plot(x_values[~y2_values.mask], y2_values[~y2_values.mask], marker="o")
ax[1].set_title('y2-values')
ax[2].plot(x_values[~y3_values.mask], y3_values[~y3_values.mask], marker="o")
ax[2].set_title('y3-values')
plt.show()