2015-08-19 47 views
3

我有一整行矩阵。我试图去做情节阴谋。我试图找到任何例子,但我不能这样,有人能帮助我吗?在熊猫上绘制整行

In [9]:Atot1 
Out[9]: 
    T G C - A C T - A G T - A G C 
SAMPLE                   
1  97 457 178 75 718 217 193 69 184 198 777 65 100 143 477 

    - A T G C 
SAMPLE      
1  54 63 43 55 47 

回答

5

选择行:

row = df.iloc[0] 

剧情的行(一个pandas.Series):

row.plot(kind='bar') 

例如,

import pandas as pd 
import matplotlib.pyplot as plt 

d = {'columns': ['T', 'G', 'C', '-', 'A', 'C', 'T', '-', 'A', 'G', 'T', 
       '-', 'A', 'G', 'C', '-', 'A', 'T', 'G', 'C'], 
    'data': [[97, 457, 178, 75, 718, 217, 193, 69, 184, 198, 
       777, 65, 100, 143, 477, 54, 63, 43, 55, 47]], 
    'index': [1]} 
df = pd.DataFrame(d['data'], columns=d['columns'], index=d['index']) 
df.columns.names = ['SAMPLE'] 

row = df.iloc[0] 
row.plot(kind='bar') 
plt.show() 

产量

enter image description here

+0

如果你想绘制两排,以便在x轴你有类别,然后你必须为每个类别两间酒吧,你如何避免它们堆叠? – FaCoffee

+1

它可以工作,但是如何为行添加标签到图例中?你如何绘制多行? – jeromerg