简体   繁体   English

如何根据 x 轴上的值绘制多种颜色

[英]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.

相关问题 Matplotlib基于x轴上的值的多种颜色的绘图 - Matplotlib plot with multiple colors based on values on x-axis 如何指定要在x轴上绘制的离散值(matplotlib,boxplot)? - How can I specify the discrete values that I want to plot on the x-axis (matplotlib, boxplot)? 我怎样才能更好地格式化 plot 的 x 轴 - How can I better format the x-axis of a plot 如何将 x 轴设置为散景图上的日期时间? - How can I set the x-axis as datetimes on a bokeh plot? 在同一图上用不同的x轴值绘制多个直方图 - Plotting multiple histograms on the same plot with different x-axis values 如何使用分类 x 轴绘制 matplotlib 散点图,允许我根据第三个变量指定标记和颜色? - How can I do a matplotlib scatter plot with a categorical x-axis, that allows me to specify the marker and color based on a third variable? 如何在 python 中以像素数为 x 轴,灰度颜色为 y 轴 plot 图形? - How can I plot the figure with the number of pixel as a x-axis and the grayscale color as a y-axis in python? 如何使plot的x轴原点和y轴原点在matplotlib中重叠? - How can I make the origin of the x-axis and the origin of the y-axis of a plot overlap in matplotlib? 如何用光谱 colors 填充 x 轴和曲线之间的空间? - How can I fill the space between the x-axis and the curve with the spectral colors? 如何在Matplotlib图中有条件地对X轴值进行排序? - How to conditionally sort X-axis values in Matplotlib plot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM