matplotlib填充离散点之间

时间:2014-09-26 16:57:45

标签: python matplotlib fill

我有以下几个数据点(没有方程式来解决y1和y2)。

问:我如何用不同的颜色填充点之间的区域?谢谢!

import matplotlib.pyplot as plt
from matplotlib.figure import Figure

X=[-10,-15,-20,-25,-100,-200,-300,-400,-500,-600]
Y=[35,20,10,8,6,12,15,20,25,30]

fig = plt.figure()

ax= fig.add_subplot ( 111 )

ax.plot(Y,X,'ro-')

ax.text(20, -200, 'HOW TO FILL HERE?', fontsize=30)

plt.show()

enter image description here

1 个答案:

答案 0 :(得分:2)

请做:

plt.fill_betweenx(X, Y, 35) #or max(X) or whatever cut-off you may want.

enter image description here