Width of rectangles

Hi there,

I am facing a situation in which I feel particularly stuck. I am designing a heatmap with rectangles. This heatmap is interacting with 2D plots : x_axis_type is datetime and they share the same range. It turns out in this situation the width parameter value has absolutely no effect ; I have huge white gaps, which are the main area once the figure is zoomed enough. I wish I had absolutely no gaps, and see the rectangles standing edge to edge from one another. Here is some piece of code for this figure and the resulting plot:

`plot_options = dict(plot_width=width, plot_height=300, x_axis_type="datetime",    x_range=p1.x_range)

p4 = figure(title="Analyse d'anomalie", tools="reset, pan, box_select, wheel_zoom",
                y_range=tuple(anomaly_names), **plot_options)
for j,name in list(zip(range(len(anomaly_names)), anomaly_names)):
        p4.rect(x="estampilles", y=heatmap_y_coordinate[j], width=1, height=1,
                color=transform(name, mapper), dilate=True, source=source)`

Thanks everybody for your input.

G.H.

Please provide a minimal reproducible example. So that anyone can actually run your code without any actions other than copying and pasting it into a .py file.

Here is the code with the issue : a useless width parameter resulting in very narrow rectangles.

`import random
import datetime
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, CustomJS, Slider, LinearColorMapper
from bokeh.plotting import figure, show
from bokeh.transform import transform

estampilles = [datetime.datetime(2014, 6, 30, 0, 15),
 datetime.datetime(2014, 6, 30, 0, 30),
 datetime.datetime(2014, 6, 30, 0, 45),
 datetime.datetime(2014, 6, 30, 1, 0),
 datetime.datetime(2014, 6, 30, 1, 15),
 datetime.datetime(2014, 6, 30, 1, 30),
 datetime.datetime(2014, 6, 30, 1, 45),
 datetime.datetime(2014, 6, 30, 2, 0),
 datetime.datetime(2014, 6, 30, 2, 15),
 datetime.datetime(2014, 6, 30, 2, 30),
 datetime.datetime(2014, 6, 30, 2, 45),
 datetime.datetime(2014, 6, 30, 3, 0),
 datetime.datetime(2014, 6, 30, 3, 15),
 datetime.datetime(2014, 6, 30, 3, 30),
 datetime.datetime(2014, 6, 30, 3, 45),
 datetime.datetime(2014, 6, 30, 4, 0),
 datetime.datetime(2014, 6, 30, 4, 15),
 datetime.datetime(2014, 6, 30, 4, 30),
 datetime.datetime(2014, 6, 30, 4, 45),
 datetime.datetime(2014, 6, 30, 5, 0)]

anomaly_names = ['twosigma Energy Consumption',
 'iForest Energy Consumption',
 'kPCA Energy Consumption',
 ]
coordinate_name = ['twosigma Energy Consumption_coor',
 'iForest Energy Consumption_coor',
 'kPCA Energy Consumption_coor',
 ]

source_dic = dict()
source_dic["estampilles"] = estampilles
source_dic[anomaly_names[0]] = [0 for i in range(20)]
source_dic[anomaly_names[1]] = [random.random() for i in range(20)]
source_dic[anomaly_names[2]] = [random.random() for i in range(20)]
source_dic[coordinate_name[0]] = [anomaly_names[0] for i in range(20)]
source_dic[coordinate_name[1]] = [anomaly_names[1] for i in range(20)]
source_dic[coordinate_name[2]] = [anomaly_names[2] for i in range(20)]

source = ColumnDataSource(source_dic)
colors = ["#75968f", "#a5bab7", "#c9d9d3", "#e2e2e2", "#dfccce", "#ddb7b1", "#cc7878", "#933b41", "#550b1d"]
mapper = LinearColorMapper(palette=colors, low=0, high=1)
p = figure(title="Analyse", tools="pan, wheel_zoom", y_range=tuple(anomaly_names), plot_width=1200, plot_height=300,
x_axis_type="datetime")
for j, name in list(zip(range(len(anomaly_names)), anomaly_names)):
    p.rect(x="estampilles", y=coordinate_name[j], width=100, height=1, color=transform(name, mapper), dilate=True,
source=source)

show(p)`

Hi @GuillaumeHuin,

Because your x-axis is in terms of time, your width will need to be also. Try: width=datetime.timedelta(minutes=15)

1 Like

Thank you very much @carolyn !