Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 更改matplotlib中面积图的颜色时出现问题_Python_Matplotlib - Fatal编程技术网

Python 更改matplotlib中面积图的颜色时出现问题

Python 更改matplotlib中面积图的颜色时出现问题,python,matplotlib,Python,Matplotlib,我在matplotlib中有以下面积图代码 #Case Study: Cost minimization import pandas as pd from matplotlib import pyplot as plt %matplotlib inline columns = ['Conventional control', 'Optimized control'] power_values = [[120.000, 12.000] ,[120.000, 116.3211908] ,[120.

我在matplotlib中有以下面积图代码

#Case Study: Cost minimization
import pandas as pd
from matplotlib import pyplot as plt
%matplotlib inline

columns = ['Conventional control', 'Optimized control']
power_values = [[120.000, 12.000]
,[120.000, 116.3211908]
,[120.000, 118.1130328]
,[120.000, 114.600]
,[93.000, 107.3539204]
,[93.000, 107.5878386]
,[12.000, 117.1042044]
,[12.000, 118.2644594]
,[12.000, 117.9452063]
,[12.000, 119.6035571]
,[12.000, 114.5331649]
,[12.000, 115.57216]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.83806104]
,[12.000, 12.08309783]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 12.000]
,[12.000, 89.78661005]
,[12.000, 77.8819384]
,[12.000, 92.68210154]
,[12.000, 87.80953293]
,[12.000, 86.96755995]
,[12.000, 66.165492]
,[12.000, 70.7452192]
,[14.700, 65.9191703]
,[14.700, 60.10536791]
,[14.700, 71.16380286]
,[14.700, 41.35914048]
,[17.400, 86.8684165]
,[17.400, 17.36906999]
,[22.800, 24.85258464]
,[28.200, 32.3620731]
,[30.900, 26.3773125]
,[39.000, 31.77385124]
,[39.000, 43.3147621]
,[39.000, 48.46708134]
,[39.000, 61.81472004]
,[39.000, 47.41845997]
,[41.700, 58.04810651]
,[47.100, 50.91068421]
,[47.100, 88.94926413]
,[47.100, 46.39797818]
,[55.200, 54.80575834]
,[57.900, 40.66724158]
,[63.300, 72.12598178]
,[66.000, 62.62780501]
,[66.000, 60.91918474]
,[66.000, 59.63061079]
,[74.100, 67.26335234]
,[74.100, 56.49624679]
,[79.500, 69.74510363]
,[82.200, 87.3788584]
,[84.900, 95.94232954]
,[87.600, 12.000]
,[87.600, 12.17649049]
,[95.700, 48.30076603]
,[95.700, 83.07030318]
,[95.700, 100.6549642]
,[103.800, 105.354238]
,[106.500, 110.4129039]
,[109.200, 105.8197575]
,[106.500, 92.97219054]
,[106.500, 94.56084184]
,[106.500, 120.000]
,[111.900, 117.9859067]
,[109.200, 12.000]
,[111.900, 12.000]
,[114.600, 12.000]
,[106.500, 12.000]
,[101.100, 12.000]
,[98.400, 12.000]
,[93.000, 12.000]
,[93.000, 13.74658733]
,[93.000, 12.000]
,[93.000, 12.000]
,[93.000, 12.000]
,[93.000, 12.000]
,[87.600, 12.000]
,[87.600, 12.000]
,[84.900, 12.000]
,[82.200, 12.000]
,[76.800, 12.000]
,[71.400, 12.000]
,[68.700, 12.000]
,[68.700, 12.000]
,[68.700, 12.000]
,[66.000, 12.000]
,[63.300, 12.000]
,[60.600, 12.000]
,[60.600, 42.24372896]
,[57.900, 54.52761265]
,[52.500, 70.35899518]
,[49.800, 78.87243535]
,[47.100, 94.23028391]
,[49.800, 105.183383]
,[52.500, 111.1661544]
,[49.800, 111.9372309]
,[49.800, 115.2862033]
,[49.800, 117.300]
,[49.800, 119.5542029]
,[44.400, 119.9169913]
,[47.100, 120.000]
,[44.400, 120.000]
,[44.400, 120.000]
,[44.400, 120.000]
,[44.400, 120.000]
,[47.100, 120.000]
,[49.800, 120.000]
,[49.800, 120.000]
,[47.100, 120.000]
,[47.100, 120.000]
,[47.100, 120.000]
,[55.200, 120.000]
,[57.900, 12.000]
,[57.900, 12.000]
,[55.200, 12.000]
,[55.200, 12.000]
,[55.200, 12.000]
,[60.600, 12.000]
,[55.200, 12.000]
,[49.800, 12.000]
,[52.500, 12.000]
,[55.200, 15.96201285]
,[52.500, 23.21924871]
,[60.600, 33.69820201]
,[60.600, 119.9302521]
,[63.300, 120.000]
,[60.600, 119.7098892]
,[63.300, 119.6219221]
,[66.000, 120.000]
,[66.000, 117.300]
,[71.400, 120.000]
,[68.700, 120.000]
,[71.400, 119.8361707]
,[60.600, 117.300]
,[57.900, 119.5370779]
,[60.600, 120.000]
,[63.300, 12.000]
,[60.600, 12.000]
,[55.200, 12.000]
,[57.900, 12.000]
,[55.200, 12.000]
,[52.500, 18.66370438]
,[47.100, 28.43757919]
,[41.700, 70.17149386]
,[39.000, 100.1695002]
,[39.000, 114.4295489]
,[39.000, 112.1661558]
,[39.000, 120.000]
,[36.300, 12.000]
,[30.900, 12.000]
,[30.900, 12.000]
,[28.200, 12.000]
,[30.900, 12.000]
,[30.900, 12.000]
,[28.200, 12.000]
,[25.500, 12.83581588]
,[28.200, 35.71864701]
,[33.600, 97.07589193]
,[36.300, 111.813347]
,[39.000, 117.2764379]
,[41.700, 12.000]
,[44.400, 12.000]
,[44.400, 12.000]
,[44.400, 12.000]
,[47.100, 12.000]
,[44.400, 12.000]
,[44.400, 12.000]
,[47.100, 12.000]
,[44.400, 12.000]
,[47.100, 12.000]
,[47.100, 12.000]
,[49.800, 12.000]
,[47.100, 12.000]
,[57.900, 12.000]
,[57.900, 12.000]
,[57.900, 12.000]
,[63.300, 12.000]
,[63.300, 12.000]
,[63.300, 12.000]
,[63.300, 12.000]
,[66.000, 12.000]
,[63.300, 12.000]
,[68.700, 12.000]
,[68.700, 12.000]
,[74.100, 12.000]
,[79.500, 12.000]
,[79.500, 12.000]
,[84.900, 12.000]
,[84.900, 12.000]
,[82.200, 12.000]
,[82.200, 12.000]
,[82.200, 12.000]
,[76.800, 12.000]
,[79.500, 12.000]
,[82.200, 12.000]
,[82.200, 12.000]
,[84.900, 12.000]
,[87.600, 12.000]
,[87.600, 12.000]
,[79.500, 12.000]
,[71.400, 12.000]
,[71.400, 12.000]
,[71.400, 12.000]
,[71.400, 12.000]
,[63.300, 12.000]
,[66.000, 12.000]
,[63.300, 12.000]
,[60.600, 12.000]
,[60.600, 12.000]
,[63.300, 12.000]
,[63.300, 12.000]
,[63.300, 12.15435357]
,[66.000, 12.53675926]
,[66.000, 12.90398697]
,[55.200, 13.05331214]
,[55.200, 13.54266462]
,[55.200, 13.65002032]
,[52.500, 14.11216008]
,[41.700, 14.0443751]
,[41.700, 14.06156448]
,[44.400, 50.55592643]
,[41.700, 67.28526901]
,[41.700, 29.5042061]
,[39.000, 23.82530113]
,[33.600, 29.77446277]
,[33.600, 79.60237682]
,[30.900, 41.15124172]
,[30.900, 65.12804827]
,[30.900, 19.49852188]
,[33.600, 30.63110012]
,[33.600, 18.00739888]
,[36.300, 12.000]
,[33.600, 114.6927977]
,[30.900, 49.52207339]
,[33.600, 93.95358247]
,[36.300, 74.26944322]
,[36.300, 52.00601276]
,[30.900, 12.000]
,[36.300, 12.000]
,[36.300, 12.000]
,[36.300, 12.000]
,[33.600, 12.000]
,[33.600, 12.000]
,[36.300, 12.000]
,[36.300, 85.10538741]
,[36.300, 30.55582867]
,[36.300, 66.04011056]
,[39.000, 45.22485527]
,[36.300, 28.13672986]
,[36.300, 12.18679167]
,[33.600, 12.000]
,[33.600, 12.000]
,[30.900, 12.000]
,[25.500, 12.000]
,[25.500, 12.000]
,[25.500, 12.000]
,[28.200, 76.83266527]
,[28.200, 43.60902258]
,[28.200, 67.0227672]
,[25.500, 73.92553359]
,[25.500, 53.04944227]
,[20.100, 53.800767]
,[20.100, 48.24078759]
,[20.100, 38.75582412]
,[20.100, 55.76030678]
,[20.100, 60.44488024]
,[20.100, 59.7398675]
,[20.100, 47.36530315]
,[17.400, 47.36530315]]

wind_data = pd.DataFrame(power_values, index=range(0, 289), columns=columns)
fig = plt.figure(linewidth=1, figsize=(7, 5))
ax = wind_data.plot.area(ax=plt.gca(), color="green, red", stacked=False  )
ax.set_facecolor("white")
ax.set_xlabel("Time of day", fontsize = 14, labelpad=8)
ax.set_ylabel("Power in kW", fontsize = 14,labelpad=8)
ax.set_xlim(0, 288)
ax.set_ylim(0, 150)



plt.xticks(wind_data.index, labels=[f'{h:02d}:00' for h in wind_data.index], rotation=90)
plt.grid(axis='y', alpha=.4)
plt.tight_layout()
xticks = ['00:00', '01:00', '02:00' , '03:00', '04:00' , '05:00' , '06:00' , '07:00' , '08:00' , 
          '09:00' , '10:00' , '11:00' , '12:00' , '13:00' , '14:00' , '15:00' , '16:00' 
          , '17:00', '18:00', '19:00' , '20:00' , '21:00', '22:00' , '23:00' , '24:00'  ]
xvals = [0, 1*12, 2*12, 3*12, 4*12, 5*12, 6*12, 7*12, 8*12, 9*12, 10*12, 11*12, 12*12, 13*12, 14*12, 15*12, 16*12
        , 17*12, 18*12, 19*12, 20*12, 21*12, 22*12, 23*12, 24*12] 
ax.set(xticks=xvals, xticklabels=xticks)
ax.tick_params(axis='both', which='major', labelsize=14)
ax.legend(loc='center left', bbox_to_anchor=(0.03, 1.15), fontsize = 14, ncol=3)
plt.savefig('CS_Cost_Load.png', edgecolor='black', dpi=400, bbox_inches='tight')
plt.show()
问题出在我设置两条曲线颜色的那一行:

ax = wind_data.plot.area(ax=plt.gca(), color="green, red", stacked=False  )
奇怪的是,当选择这两种颜色时,一切都正常。但如果我使用例如:

ax = wind_data.plot.area(ax=plt.gca(), color="blue, red", stacked=False  )
我收到错误消息:“ValueError:无效的RGBA参数:'l'” 例如,如果我使用

ax = wind_data.plot.area(ax=plt.gca(), color="green, blue", stacked=False  )

我没有收到错误消息,但这两个图的颜色是之前的绿色和红色。这对我来说非常奇怪。有人知道为什么会这样吗

如果不检查此项,听起来它只是拾取绿色的前两个字母,因此
gr
。例如,你能试试
color=“br”
吗?谢谢你对tomjn的评论。我尝试了下面的“ax=wind\u data.plot.area(ax=plt.gca(),color=“br,gr”,stacked=False)”,结果非常奇怪。我有一个红色和一个紫色的图案,听起来像蓝色。您也可以使用
color=[“蓝色”、“红色”]
。试试看,或者
color=[“blue”,“magenta”]
(或者
color=“bm”
)看看不同之处,谢谢你的回答。基本上你的建议颜色=[“蓝色”,“红色”]效果很好:-)