2016-04-30 9 views
0

Ich versuche, ein Bokeh Balkendiagramm Uding Python zu erstellen. Die Daten 2 sind die WerteBokeh Bar Grundstück |

from bokeh.plotting import figure, output_file, show,hplot 
from bokeh.charts import Bar 

data2=[65.75, 48.400000000000006, 58.183333333333337, 14.516666666666666] 


bar = Bar(values=data2,xlabel="beef,pork,fowl,fish",ylabel="Avg consumtion", width=400) 

show(bar) 

Fehler

TypeError: Bar() takes at least 1 argument (1 given) 

Was ich hier falsch mache?

Antwort

1

Sie könnten alle Ihre Daten in einen Datenrahmen einfügen.

Um direkt darzustellen, was Sie wollen, ohne das zu tun, müssen Sie das Schlüsselwort "values" entfernen.

bar = Bar(data2,xlabel="beef,pork,fowl,fish",ylabel="Avg consumtion", width=400) 

Dies wird jedoch nicht Ihre x-Etiketten hinzufügen. Um dies zu tun, können Sie Folgendes tun:

from bokeh.plotting import figure, output_file, show,hplot 
from bokeh.charts import Bar 
from pandas import DataFrame as df 
data2=[65.75, 48.400000000000006, 58.183333333333337, 14.516666666666666] 

myDF = df(
    dict(
    data=data2, 
    label=["beef", "pork", "fowl", "fish"], 
    )) 

bar = Bar(myDF, values="data",label="label",ylabel="Avg consumption", width=400) 

show(bar)