Color Time-series Based On Column Values In Pandas
I have a time-series in a pandas DataFrame (df.data in the example) and want to color the plot based on the values of another column (df.colorsin the example; values are 0, 1, and
Solution 1:
One way to achieve this would be to use DF.replace
and create a nested dictionary
to specify the color values for the int/float
values to be mapped against.
plt.style.use('seaborn-white')
df.replace({'colors':{0:'red',1:'orange',2:'green'}}, inplace=True)
You could then perform DF.groupby
on it to keep the colors same for each subgroup of the groupby
object on every iteration step.
for index, groupin df.groupby('colors'):
group['data'].plot(style=".", x_compat=True, ms=10, color=index, grid=True)
Post a Comment for "Color Time-series Based On Column Values In Pandas"