3
我試圖繪製我的Raspberry Pi的溫度並在網頁上顯示該圖。這工作相當好。然而,我試圖根據感知的風險對不同區域的情節着色(我不確定它們是否對我的Pi構成風險,但在90°C下運行時我感覺不舒服)。試圖繪製溫度
我使用這個代碼來創建情節:
fig = plt.figure()
# color regions
plt.fill([0, 0, len(temps)-1, len(temps)-1], [80, 100, 100, 80], 'r', alpha=0.2, linestyle=None)
plt.fill([0, 0, len(temps)-1, len(temps)-1], [60, 80, 80, 60], 'y', alpha=0.2, linestyle=None)
plt.fill([0, 0, len(temps)-1, len(temps)-1], [0, 60, 60, 0], 'g', alpha=0.2, linestyle=None)
# modify axis
plt.axis([0, len(temps)-1, 0, 100])
plt.xticks([])
# plot and safe
plt.plot(temps, color='k')
plt.savefig(buf, format='png')
plt.close(fig)
我不喜歡地區的「硬邊」,但我似乎無法找到讓他們「流動」到彼此的方式。有誰知道如何解決這個問題,或者可以將我指向正確的方向?
您是不是要找'線寬= 0'? – Artyer
您是否想將漸變應用於背景? http://matplotlib.org/examples/pylab_examples/gradient_bar.html –
@Artyer這是一個很好的開始,但它仍然是綠色的,然後突然全黃了。我寧願平穩過渡。 –