簡體   English   中英

Matplotlib雙條形圖:條形繪制不正確

[英]Matplotlib double bar chart: Bars not properly drawn

我正在嘗試將每個數據集的幀的兩個不同數據列(“ n”和“ m”)繪制為彼此相鄰的兩個不同顏色的條。

def graphPlot(data, size=None):
    pos = arange(len(data))+.5    # the bar centers on the y axis
    figure(figsize=size)
    xscale("log")
    barh(pos, data["n"], align='center', height=0.25, color="darkgrey")    
    barh(pos - 0.25, data["m"], align='center', height=0.25, color="lightblue")    
    yticks(pos, data["graph"])
    xlabel("")
    grid(True)

但是結果是這樣的:

在此處輸入圖片說明

為什么沒有正確繪制條形圖? 我的位置值有誤嗎?

是導致問題的xscale("log")調用。 您需要對圖進行縮放,以便將log=True傳遞給barh調用:

def graphPlot(data, size=None):
    pos = arange(len(data))+.5    # the bar centers on the y axis
    figure(figsize=size)
    #xscale("log")
    barh(pos, data["n"], align='center', height=0.25, color="darkgrey", log=True)    
    barh(pos - 0.25, data["m"], align='center', height=0.25, color="lightblue", log=True)    
    yticks(pos, data["graph"])
    xlabel("")
    grid(True)

另一種方法是使用熊貓數據框保存數據,然后簡單地調用df[['ser1', 'ser2']].plot(kind='barh', logx=True)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM