简体   繁体   English

从 Pandas 到 Seaborn 绘制多条线图

[英]Plot multiple line graph from Pandas into Seaborn

I'm trying to plot a multi line-graph plot from a pandas dataframe using seaborn.我正在尝试使用 seaborn 从 Pandas 数据框中绘制多线图。 Below is a .csv of the of the data and the desired plot.下面是数据和所需图的 .csv。 In excel I simply selected the whole dataset and swapped the axis.在excel中,我只是选择了整个数据集并交换了轴。 Technically there are 110 lines (rows) on this, but many aren't visible because they only contain 0's.从技术上讲,这里有 110 行(行),但很多是不可见的,因为它们只包含 0。

具有 16 个 bin 的多线图

This is my code:这是我的代码:

individual_burst_data = {'nb001':nb001, 'nb002':nb002, 'nb003':nb003, 'nb004':nb004, 'nb005':nb005, 'nb006':nb006, 'nb007':nb007, 'nb008':nb008, 'nb009':nb009, 'nb010':nb010, 'nb011':nb011, 'nb012':nb012, 'nb013':nb013, 'nb015':nb015, 'nb016':nb016 }
ibd_panda_conv = pd.DataFrame(individual_burst_data)

sns.lineplot(data = ibd_panda_conv, x = individual_burst_data, y =ibd_panda_conv)

Other sources seem to only extract one column, whereas I need all the columns.其他来源似乎只提取一列,而我需要所有列。

I tried to create an index for the y-axis我试图为 y 轴创建一个索引

index_data = list(range(0,len(individual_burst_data)))

but this didn't work either.但这也不起作用。

The seaborn lineplot() documentation says: seaborn lineplot()文档说:

Passing the entire wide-form dataset to data plots a separate line for each column将整个宽格式数据集传递给data为每列绘制一条单独的线

Since you want a line for each row instead, you need to transpose your dataframe, so try this:由于您希望每一行都有一行,因此您需要转置数据框,因此请尝试以下操作:

sns.lineplot(data=ibd_panda_conv.T, dashes=False)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM