[英]how can I plot with multiple colors based on values on x-axis
Hey guys let's say I have a pandas DataFrame嘿伙计们,假设我有一个 Pandas DataFrame
Year Delta_T
0 2000 23
1 2001 25
2 2002 22
2 2002 22
4 2004 30
5 2005 21
and I want to plot delta_T in function of time but I want to plot one color for the dates from 2000 to 2003 and another color from 2004 to 2005 Can someone please tell me how I can do it?我想根据时间绘制 delta_T 但我想为 2000 年到 2003 年的日期绘制一种颜色,从 2004 年到 2005 年绘制另一种颜色有人可以告诉我我该怎么做吗?
I have tried this我试过这个
plt.figure()
plt.scatter(delta_T_all.iloc[:,0].pd.Timestamp('2010-04-17'),
pd.Timestamp('2016-01-01'),delta_T_all.iloc[:,1], label= '220-250m'),
plt.scatter(delta_T_all.iloc[:,0].pd.Timestamp('2016-01-01'),
pd.Timestamp('2019-09-14'),delta_T_all.iloc[:,1], label= '220-250m')
plt.xlabel('Time')
plt.setp(plt.gca().get_xticklabels(), rotation=60, ha="right")
plt.ylabel('Delta_T')
plt.legend()
plt.title('Delta_T in function of time')
This is the answer这就是答案
plt.figure()
plt.scatter(delta_T_all.iloc[0:2,0],delta_T_all.iloc[0:2,1],color='r')
plt.scatter(delta_T_all.iloc[2:5,0],delta_T_all.iloc[2:5,1],color='b')
plt.xlabel('Time')
plt.ylabel('Delta_T')
plt.legend()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.