python - Is it possible to keep the same amount of x axis tick labels visible as the zoom level changes on a bokeh bar plot? -
i'm using django , generating bokeh bar plot using data database. i've put basic code example below. i'm generating x axis tick labels datetime variable tick @ every hour datetime formatted string. causes tick label visible time. it's fine when zoomed in not pretty when zoomed out because labels on top of each other.
is there way make bokeh automatically adjust tick labels visible zoom level changes keep constant amount of ticks labels visible ?
views.py :
# -*- coding: utf-8 -*- django.shortcuts import render bokeh.plotting import * bokeh.resources import cdn bokeh.embed import components bokeh.charts import bar bokeh.models import range1d collections import ordereddict import datetime def plot_1_bar(data, y, y_lab, title, xlab, ylab, yrange, palette): x0_list_str = [] y_list = [] # x_axis_type == "datetime": i_x = 'x1' i_y = y[0] idx, val in enumerate(data): x0_list_str.append(val[i_x].strftime("%y-%m-%d %h h")) y_list.append(val[i_y]) data_x = x0_list_str data_y = ordereddict() data_y[y_lab[0]] = y_list plot = bar(data_y, data_x, title=title, xlabel=xlab, ylabel=ylab, stacked=true, continuous_range=yrange, palette=palette, legend=true, height=400) return components(plot, cdn) def plot1(request): script_bokeh = "" div_bokeh = "" data = [] data.append({'x1': datetime.datetime(2015,1,1,8,0,0,0),'y1': 0}) data.append({'x1': datetime.datetime(2015,1,1,9,0,0,0),'y1': 0}) data.append({'x1': datetime.datetime(2015,1,1,10,0,0,0),'y1': 0}) data.append({'x1': datetime.datetime(2015,1,1,11,0,0,0),'y1': 0}) data.append({'x1': datetime.datetime(2015,1,1,12,0,0,0),'y1':8}) data.append({'x1': datetime.datetime(2015,1,1,13,0,0,0),'y1':12}) data.append({'x1': datetime.datetime(2015,1,1,14,0,0,0),'y1':0}) data.append({'x1': datetime.datetime(2015,1,1,15,0,0,0),'y1':0}) data.append({'x1': datetime.datetime(2015,1,1,16,0,0,0),'y1':0}) data.append({'x1': datetime.datetime(2015,1,1,17,0,0,0),'y1':0}) data.append({'x1': datetime.datetime(2015,1,1,18,0,0,0),'y1':2}) data.append({'x1': datetime.datetime(2015,1,1,19,0,0,0),'y1':6}) data.append({'x1': datetime.datetime(2015,1,1,20,0,0,0),'y1':4}) data.append({'x1': datetime.datetime(2015,1,1,21,0,0,0),'y1':22}) data.append({'x1': datetime.datetime(2015,1,1,22,0,0,0),'y1':36}) data.append({'x1': datetime.datetime(2015,1,1,23,0,0,0),'y1':32}) data.append({'x1': datetime.datetime(2015,1,2,0,0,0,0),'y1':21}) data.append({'x1': datetime.datetime(2015,1,2,1,0,0,0),'y1':15}) data.append({'x1': datetime.datetime(2015,1,2,2,0,0,0),'y1':4}) data.append({'x1': datetime.datetime(2015,1,2,3,0,0,0),'y1':0}) data.append({'x1': datetime.datetime(2015,1,2,4,0,0,0),'y1':0}) data.append({'x1': datetime.datetime(2015,1,2,5,0,0,0),'y1':0}) data.append({'x1': datetime.datetime(2015,1,2,6,0,0,0),'y1':45}) data.append({'x1': datetime.datetime(2015,1,2,7,0,0,0),'y1':47}) data.append({'x1': datetime.datetime(2015,1,2,8,0,0,0),'y1':52}) data.append({'x1': datetime.datetime(2015,1,2,9,0,0,0),'y1':44}) data.append({'x1': datetime.datetime(2015,1,2,10,0,0,0),'y1':0}) data.append({'x1': datetime.datetime(2015,1,2,11,0,0,0),'y1':0}) data.append({'x1': datetime.datetime(2015,1,2,12,0,0,0),'y1':0}) data.append({'x1': datetime.datetime(2015,1,2,13,0,0,0),'y1':0}) script_bokeh, div_bokeh = plot_1_bar(data, ['y1'], ['y legend label'], "", 'x label', 'y label', range1d(0, 70), ['red']) return render(request, 'tests/plot1.html', {'script_bokeh': script_bokeh, 'div_bokeh': div_bokeh})
plot1.html :
<!doctype html> <html lang="en"> <head> <title>bokeh bar plot</title> <link rel="stylesheet" type="text/css" href="/static/tests/css/bokeh-0.9.2.min.css" /> <script src="/static/tests/js/bokeh-0.9.2.min.js" type="text/javascript"></script> </head> <body> <h1>bokeh bar plot</h1> <div id="div_graph">{{div_bokeh|safe}}{{script_bokeh|safe}}</div> </body> </html>
Comments
Post a Comment