[英]Is there a way to create either stacked plots in one or lines in one plot with stacked Y-axes with matplot/seaborn?
I am new in the visualizations of dataframes and I am exploring the methods, but I do not seem able to find a way to create a very specific plot I need.我是数据帧可视化的新手,我正在探索这些方法,但我似乎无法找到一种方法来创建我需要的非常具体的 plot。
I have a dataframe like the one below where I have datetime as index and 4 profiles (whereas there could be more columns uninterested in plotting):我有一个 dataframe 像下面这样我有日期时间作为索引和 4 个配置文件(而可能有更多列对绘图不感兴趣):
datetime
2019-06-11 00:00:00 28.97 38.47 NaN 41.47
2019-06-11 01:00:00 28.83 38.42 NaN 41.48
2019-06-11 02:00:00 28.72 38.38 NaN 41.49
2019-06-11 03:00:00 28.56 38.33 NaN 41.49
2019-06-11 04:00:00 28.36 38.22 NaN 41.51
My aim is to create a plot with the described specifications:我的目标是创建具有所述规格的 plot:
Lineplots, one for each profile, but all in one plot .线图,每个配置文件一个,但都在一个 plot 中。
The lines should not intercept, so the profiles should be stacked one above the other, preferably with profile 1 being at the very top.线条不应相交,因此轮廓应堆叠在另一个之上,最好将轮廓 1 放在最顶部。
The values should not change, thus the Y-axes should probably be stacked.这些值不应改变,因此 Y 轴可能应该堆叠。
The legend should be one for the whole plot of the 4 profiles.图例应该是 4 个配置文件的整个 plot 之一。
The plot or line of a profile with NaN values should not appear.不应出现 plot 或具有 NaN 值的配置文件行。
I 'd appreciate it if you could suggest something or guide me through the solution?如果您能提出建议或指导我完成解决方案,我将不胜感激?
Additionally, is there a brief structured guide with examples that you would recommend me in order to gain some good fundamentals in the visualizations?此外,是否有一个简短的结构化指南,其中包含您会推荐给我的示例,以便在可视化中获得一些良好的基础知识? I prefer something I can print out or read via a tablet while commuting.
我更喜欢通勤时可以通过平板电脑打印或阅读的东西。
Thank you for your input:-)谢谢您的意见:-)
May bi it would be helpful for you:可能会对您有所帮助:
df[3] = pd.to_numeric(df[3], errors = 'coerce').fillna(0)
df = df.rename(columns = {1:'A',2:'B',3:'C',4:'D'})
df = df.set_index(0)
df
Out[1]:
A B C D
0
2019-06-11 00:00:00 28.97 38.47 0.0 41.47
2019-06-11 01:00:00 28.83 38.42 0.0 41.48
2019-06-11 02:00:00 28.72 38.38 0.0 41.49
2019-06-11 03:00:00 28.56 38.33 0.0 41.49
2019-06-11 04:00:00 28.36 38.22 0.0 41.51
import matplotlib.dates as mdates
ax = [None]*4
fig = plt.figure()
f, (ax[0], ax[1], ax[2], ax[3]) = plt.subplots(4, 1, sharex=True)
ax[3].set_xlabel('Hours')
color = ['r','g','b','y']
for i in range(4):
col = df.columns[i]
_ = ax[i].plot(df.index,df[col], label = col, c = color[i])
xfmt = mdates.DateFormatter('%H:%M')
ax[3].xaxis.set_major_formatter(xfmt)
ax[3].xaxis.set_major_locator(mdates.HourLocator(byhour=range(24)))
_ = f.legend()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.