Issue
import pandas as pd
import matplotlib.pyplot as plt
alist = [110,120,130]
blist = [150,170,190]
df1 = pd.Series(alist)
df2 = pd.Series(blist)
frames = [df1, df2]
result = pd.concat(frames)
df3 = result.reset_index(drop=False)
df3.plot(y=0)
plt.show()
Is there any way I can plot this line but have "df1" in the color blue and "df2" in the color green and still keep them as the same line? My current plot looks like this: Plot
Solution
You can draw ranges. But it may need [2:]
instead of [3:]
df3.iloc[:3].plot(color='blue')
df3.iloc[2:].plot(color='green')
Result:
If you use [3:]
then you get gap between lines:
Full working code:
import pandas as pd
import matplotlib.pyplot as plt
alist = [110,120,130]
blist = [150,170,190]
df1 = pd.Series(alist)
df2 = pd.Series(blist)
df3 = pd.concat([df1, df2]).reset_index(drop=True)
df3.iloc[:3].plot(color='blue')
df3.iloc[2:].plot(color='green')
#df3.iloc[3:].plot(color='green') # with gap
plt.show()
Answered By - furas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.