我在这个代码块的循环中绘图:
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色彩图吗?
干杯
答案 0 :(得分:1)
根据定义,matplotlib图具有单一颜色。如果您不想循环遍历点并逐个绘制它们,则可以使用scatter plot。
ax1.scatter(item['time'][:-1],item[headerss].iloc[:-1],c=range(len(item[headerss].iloc[:-1])),marker='o', cmap="jet")
答案 1 :(得分:0)
您可以获得色彩映射,例如imshow
,并在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')
中使用它。您可以看到different colormaps here。
Environment.getExternalStoragePublicDirectory(Environment.MEDIA_MOUNTED)
returns:-------> /storage/sdcard0/mounted
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
returns:-------> /storage/sdcard0/DCIM
Environment.getExternalStoragePublicDirectory(Environment.MEDIA_SHARED)
returns:-------> /storage/sdcard0/shared
Environment.MEDIA_MOUNTED
returns:-------> mounted
Environment.getExternalStorageDirectory()
returned:-------> /storage/sdcard0