不完整的散景图

时间:2019-02-22 08:55:54

标签: python pandas dataframe bokeh

我有一个10列的pandas数据框,并尝试使用Bokeh获取条形图。 当我使用plot_width = 10000时,HTML文件具有完整的图。 但是,当我将绘图宽度(以便在x轴值之间留有间隔)增加到30000时,绘图不会在2010年以后填充。这是完整的代码。请提出前进的方向。

from bokeh.palettes import Viridis6 as palette
from bokeh.transform import factor_cmap
from bokeh.models import ColumnDataSource,FactorRange,HoverTool
from bokeh.palettes import Spectral6
from flask import Flask, request, render_template, session, redirect,send_file
import numpy as np
import pandas as pd
from bokeh.plotting import figure, show, output_file,save
from bokeh.embed import components,file_html
from bokeh.resources import CDN
from bokeh.layouts import row,column
from bokeh.core.properties import value


dates = pd.date_range('20050101', periods=3900)

df = pd.DataFrame(np.random.randn(3900, 10), index=dates, columns=list('ABCDEFGHIJ'))






s = df.resample('M').mean().stack()
s.index = [s.index.get_level_values(0).strftime('%Y-%m-%d'),s.index.get_level_values(1)]

x = s.index.values

l1=list(s.index.levels[1])


counts = s.values

source = ColumnDataSource(data=dict(x=x, counts=counts))

p = figure(x_range=FactorRange(*x), plot_height=250,plot_width=30000, title='Plotting data',
   toolbar_location=None, tools="")


p.vbar(x='x', top='counts', width=1, source=source, line_color="white")

p.y_range.start = s.values.min()
p.y_range.end = s.values.max()
p.x_range.range_padding = 0.01
p.y_range.range_padding = 0.01
p.xaxis.major_label_orientation = 1
p.xgrid.grid_line_color = None

output_file('test_plot.html')

save([p])

show(p)

1 个答案:

答案 0 :(得分:0)

对于Bokeh 1.0.4和OSX / Safari,这对我来说效果很好。我怀疑这是您使用的任何浏览器中的基本HTML Canvas实现的局限性/问题,在这种情况下,我们无能为力。我只能提出的建议是将地块分成较小的子图,或使用其他浏览器(或同一浏览器的不同版本)