首页 > 解决方案 > 不完整的散景图

问题描述

我有一个 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)

标签: pythonpandasdataframebokeh

解决方案


这对我来说适用于 Bokeh 1.0.4 和 OSX/Safari。我怀疑这是您使用的任何浏览器中底层 HTML Canvas 实现的限制/问题,在这种情况下,我们无能为力。我能提出的唯一建议是将绘图拆分为较小的子图,或使用不同的浏览器(或者可能是同一浏览器的不同版本)


推荐阅读