Python 3.x 如何使用df.plot为一条线在一个绘图中设置不同的颜色?
我需要绘制具有不同颜色的线条图。我创建特殊的df列“颜色”,其中包含每个点的适当颜色 我已经在这里找到了解决方案: 并采取上述问题的方法。首先,当我使用索引时,它是有效的,但现在我需要将它与其他列进行对比,我无法正确处理颜色。它总是只使用一种颜色 我使用这段代码来设置颜色,但它使用“颜色”列中最后一种颜色来设置颜色行。还创建了一个我不知道如何从绘图中删除的图例Python 3.x 如何使用df.plot为一条线在一个绘图中设置不同的颜色?,python-3.x,matplotlib,plot,colors,Python 3.x,Matplotlib,Plot,Colors,我需要绘制具有不同颜色的线条图。我创建特殊的df列“颜色”,其中包含每个点的适当颜色 我已经在这里找到了解决方案: 并采取上述问题的方法。首先,当我使用索引时,它是有效的,但现在我需要将它与其他列进行对比,我无法正确处理颜色。它总是只使用一种颜色 我使用这段代码来设置颜色,但它使用“颜色”列中最后一种颜色来设置颜色行。还创建了一个我不知道如何从绘图中删除的图例 for color2, start, end in gen_repeating(df2['color']): print(st
for color2, start, end in gen_repeating(df2['color']):
print(start, end)
if start > 0: # make sure lines connect
start -= 1
idx = df2.index[start:end+1]
x2 = idx
y2 = df2.loc[idx, 'age_gps_data'].tolist()
df2.plot(x='river_km', y='age_gps_data', color=color2, ax=ax[1])
ax[1].xaxis.set_major_locator(plt.MaxNLocator(5))
plt.setp(ax[1].get_xticklabels())
我将感谢任何帮助。
如何设置这些颜色以在一行中实现不同的颜色?并且在绘图上没有图例。使用该线程(以及其中链接的示例)中所示的
LineCollection
。使用该线程(以及其中链接的示例)中所示的LineCollection
。
for color2, start, end in gen_repeating(df2['color']):
print(start, end)
if start > 0: # make sure lines connect
start -= 1
idx = df2.index[start:end+1]
x2 = idx
y2 = df2.loc[idx, 'age_gps_data'].tolist()
df2.plot(x='river_km', y='age_gps_data', color=color2, ax=ax[1])
ax[1].xaxis.set_major_locator(plt.MaxNLocator(5))
plt.setp(ax[1].get_xticklabels())