matplotlib 中fill_between
#有換行,黏貼的文本 plt.fill_between(x,x>0,c,c>0.5,color="green") c,s兩個三角函數 到底怎么填充的啊 我覺得如圖才對
#下面是代碼
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import numpy as np
import matplotlib.pyplot as plt
plt.title("biao嗯ti")
x=np.linspace(-np.pi,np.pi,256,endpoint=True)
c,s=np.cos(x),np.sin(x)
plt.figure(1)
plt.plot(x,c,label="cos")
plt.plot(x,s,label="sin")
ax=plt.gca()
ax.spines["right"].set_color("none")
ax.spines["top"].set_color("none")
ax.spines["left"].set_position(("data",0))
ax.spines["bottom"].set_position(("data",0))
plt.yticks([1,0.5,0,-0.5,-1])
#plt.xticks([-np.pi,-np.pi/2,0,np.pi/2,np.pi],
# ? ? ? ? ? ["-π","π/2","0","π/2","π"])
plt.legend(loc="upper left")
ax.xaxis.set_ticks_position("bottom")
plt.fill_between(x,x>0,c,c>0.5,color="green")
plt.show()
2018-07-08
plt.fill_between(x,x>0,c,c>0.5,color="green")
#代碼中,x>0是邏輯語言,即在x>0時為真,從橫坐標為1的地方開始填充,x<=0時為假,從橫坐標為0的地方開始填充,其中c為縱坐標約束縱向上的填充范圍(詳細說明見附圖中的黑框范圍和紅色箭頭)。