2016-04-28 63 views
1

我想在iPython筆記本中並排繪製圖像和熊貓條圖。這是一個函數的一部分,以便包含條形圖值的數據框可以根據列數而變化。用imshow繪製具有不同列數的熊貓數據框

的庫

import numpy as np 
import pandas as pd 
import matplotlib.pyplot as plt 
import matplotlib.image as mpimg 
%matplotlib inline 

數據幀

faces = pd.Dataframe(...) # return values for 8 characteristics 

這將返回條形圖我在尋找,並適用於不同數量的列。

faces.plot(kind='bar').set_xticklabels(result[0]['scores'].keys()) 

但我沒有找到一種方法來繪製它也包含圖像的pyplot圖。這是我試過的:

fig, (ax_l, ax_r) = plt.subplots(nrows=1, ncols=2, figsize=(15, 5)) 
ax_l.imshow(img) 
ax_r=faces.plot(kind='bar').set_xticklabels(result[0]['scores'].keys()) 

我得到的輸出是左邊的圖像和下面有正確繪圖的空白繪圖區。有

ax_r.bar(...) 

但我找不到一個方法來定義要繪製的列。

回答

1

您只需在您的DataFrame.plot調用中指定您的軸對象。

換句話說:faces.plot(kind='bar', ax=ax_r)