2
設置背景色說,我有一個圖像由4個個子地塊,像這樣:的插曲
進口matplotlib.pyplot如PLT 進口numpy的爲NP
# Simple data to display in various forms
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
# Four axes, returned as a 2-d array
f, axarr = plt.subplots(2, 2)
axarr[0, 0].plot(x, y)
axarr[0, 0].set_title('Axis [0,0]')
axarr[0, 1].scatter(x, y)
axarr[0, 1].set_title('Axis [0,1]')
axarr[1, 0].plot(x, y ** 2)
axarr[1, 0].set_title('Axis [1,0]')
axarr[1, 1].scatter(x, y ** 2)
axarr[1, 1].set_title('Axis [1,1]')
# Fine-tune figure; hide x ticks for top plots and y ticks for right plots
plt.setp([a.get_xticklabels() for a in axarr[0, :]], visible=False)
plt.setp([a.get_yticklabels() for a in axarr[:, 1]], visible=False)
plt.show()
返回此:
我想添加一個灰色的背景到這個地塊之一,比如左下角的地方,因爲我喜歡R
會顯示一些圖像(例如,請參見here)。我還沒有找到一個簡單的方法來與matplotlib
這樣做,我錯過了什麼?
優秀的答案,也很簡單,非常感謝你! – Gabriel