2017-06-05 10 views
-2

MatPlotLibを使用してグループバープロットを描画しようとしましたが、バーの位置が間違っています。プロット内のグループバーの位置が正しくない

だから、私はデータを持っている:

groups = [ 
    np.array([ group1.count(0), group1.count(1) ]), 
    np.array([ group2.count(0), group2.count(1) ]), 
] 

group[[1, 3], [0, 5]]あり、それは各グループが2つの色を有することを意味します。最初のグループでは1人だけが最初の色を選択し、他の3人は2番目の色を選択します。私はそれを描画しようとしていますが、バーの位置が間違っています:3最初のグループから2番目のグループに移動したように。

どこに私のミスで、なぜそれが起こりますか?

データを描画するコード:

import matplotlib.pyplot as plt 
import pandas as pd 
import numpy as np 

def draw(groups): 
    group_labels = ['G1', 'G2'] 
    num_items = len(group_labels) 
    ind = np.arange(num_items) 
    margin = 0.05 
    width = (1.-2.*margin)/num_items 
    colors = ['#f5abb5', '#2fc2ef'] 

    s = plt.subplot(1,1,1) 
    for num, vals in enumerate(groups): 
     xdata = ind+margin+(num*width) 
     plt.bar(xdata, vals, width, color=colors[num]) 
    s.set_xticks(ind+0.5) 
    s.set_xticklabels(group_labels) 


draw(groups) 

答えて

1

あなたは、入力配列

groups = numpy.array([[1, 3], [0, 5]]).T 

enter image description here

+0

はそんなにありがとう転置て! – rel1x

関連する問題