數據行的樣子:背景虛化線圖從Postgres的DB
date name val
2017-02-05 a 600.0
2017-02-05 b 345.0
2017-02-05 c 679.0
2017-02-05 d 0.0
2017-02-05 e 66.0
2017-02-05 f 0.0
2017-02-05 g 156.0
2017-03-05 a 634.0
2017-03-05 b 0.0
2017-03-05 c 2679.0
2017-03-05 d 0.0
2017-03-05 e 9266.0
2017-03-05 f 0.0
2017-03-05 g 56.0
我想產生與數據標記折線圖。 x會是日期,y會是val,圖例顏色會被分組爲「name」似乎有什麼問題。我也不確定如何添加數據標記。從互聯網搜索,似乎應該合併一個折線圖和一個圓形圖表,以完成它。
有人可以幫助解決這個錯誤,並告訴我如何做到這一點?
from bokeh.charts import Line, show, output_file, TimeSeries,Scatter
from bokeh.plotting import figure
from bokeh.models import HoverTool
import sqlalchemy as sa
import pandas as pd
# database credentials
usr = 'test'
pswd = 'test'
db = 'test'
# create the connection to the database
engine = sa.create_engine(
'postgresql://{0}:{2}@localhost:3552/{1}' \
.format(usr,db,pswd)
)
query = "select date::text,name,round(size/1024/1024/1024) as val from test order by 1,2"
# extract the data
df = pd.read_sql_query(query, engine)
output_file("example_chart.html")
# create a line chart where each column of measures receives a unique color and dash style
plot = figure(title="Example of a line chart", x_axis_label='Date', y_axis_label='size in GB')
plot.line(x=df['date'], y=df['val'], color=df['name'])
show (plot)
嗨巴勃羅,仍然是空白圖表。 – fairybetty
這將幫助我,並可能你自己之前:http://stackoverflow.com/help/mcve –
嗨,帕布洛,我用您建議的「multi_line」函數替換原始線「plot.line」。 python文件可以在沒有錯誤發生的情況下執行。但是,打開的html頁面是空白的。它有圖表的標題和一個灰色框,裏面應該有折線圖,但它是空的。 – fairybetty