2017-02-15 66 views
0

使用顏色表範圍,我在一個循環中繪製的代碼塊:單行情節

fig=plt.figure(figsize=(15,10)) 
ax1=fig.add_subplot(111) 
ax1.plot(item['time'][:-1],item[headerss].iloc[:-1],marker='o') 
ax1.legend(headerss,loc='center left', bbox_to_anchor=(1.0, 0.5)) 
ax1.set_xlabel('time') 
ax1.set_ylabel('concentration (ppb)') 
title=item['date'][0]+' '+item['list'][0]  
ax1.set_title(title) 
fig.savefig(title,bbox_inches='tight') 

項目是一個數據幀。我有超過20 item['concentrations'],我想要在ax1.plot行上創建多個不同的顏色而不創建循環。

我可以使用一組現有的顏色,如Python顏色映射嗎?

乾杯

回答

1

根據定義,matplotlib圖具有單一顏色。如果你不想循環點並逐一繪製它們,你可以使用scatter plot

ax1.scatter(item['time'][:-1],item[headerss].iloc[:-1],c=range(len(item[headerss].iloc[:-1])),marker='o', cmap="jet") 
0

你可以得到一個顏色表,如plt.afmhot,並在imshow使用它。你可以看到different colormaps here

fig=plt.figure(figsize=(15,10)) 
ax1=fig.add_subplot(111) 
ax1.imshow(item['time'][:-1],item[headerss].iloc[:-1], interpolation='nearest', cmap=plt.afmhot) 
ax1.legend(headerss,loc='center left', bbox_to_anchor=(1.0, 0.5)) 
ax1.set_xlabel('time') 
ax1.set_ylabel('concentration (ppb)') 
title=item['date'][0]+' '+item['list'][0]  
ax1.set_title(title) 
fig.savefig(title,bbox_inches='tight') 
+0

錯誤啪啪說模塊「matplotlib.pyplot」有沒有屬性「afmhot」,如果我嘗試CMAP =「普布」比如,我收到imshow()有多個值參數「CMAP」。此外,imshow彈出此消息:'DataFrame'對象是可變的,因此它們不能被散列 – Sylvain