0
爲了繪製不同於彼此的整體加載曲線,函數plot_loads準備在fill_between處生成隨機顏色。不按預期以不同顏色結果。無法發現錯誤?請幫助。matplotlib facecolor多種顏色全部結果爲黑色
def plot_loads(ti, tf, loads, max_y):
"""
plot load curves
\param ti : init t
\param tf : final t
\param loads : list of load curve lists
loads = [[ load1], [load2], ...]
\param max_y : vertical limit."""
#imports
from matplotlib import pyplot as plt
import numpy as np
import random
ys_array = []
for item in loads:
ys_array.append(item)
y = np.row_stack(ys_array)
x = np.arange(ti, tf)
y_stack = np.cumsum(y, axis=0)
fig = plt.figure(random.randint(1,1000))
#plot frame positioning
ax1 = fig.add_subplot(211)
#plot maximum load
ax1.fill_between(x, 0, max_y, alpha=0.1, facecolor = 'black')
#
for i, item in enumerate(loads):
if i == 0:
ax1.fill_between(x, 0, y_stack[0,:], facecolor = random.choice(['g', 'r', 'c', 'm', 'y', 'k']))
else:
ax1.fill_between(x, y_stack[i-1,:], y_stack[i,:], facecolor =random.choice(['g', 'r', 'c', 'm', 'y', 'k']))
plt.show()
它確實情節不同的顏色對我來說沒有問題。你能擴展錯誤實際上是什麼? – Greg
它的確如此。你能告訴我你是如何運行這個功能的嗎?在情節運行返回全黑給我。 – Jack
類似於:loads = [np.linspace(0,20,10),np.linspace(0,10,10),np.linspace(0,10,10)]'然後調用 'plot_loads(0 ,10,loads,40)'產生[this](http://imgur.com/YJsUxHM)。 – Greg