Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bokeh: The widths of vertical bars doesn't change

I came across one problem I couldn't find a solution. I would like to change the bar width of my plot, but doesn't matter the number I put in the WIDTH parameter of the method vbar, the graph remains the same.

The plot with WIDTH=100

enter image description here

The plot with WIDTH=500

enter image description here

Apply Zoom is not a solution. The bar seems like a line

enter image description here

Here is the code:

from bokeh.io import show, output_file
from bokeh.plotting import figure
import pandas as pd

df = pd.read_csv('Data/moviments.txt', delimiter='\t', encoding='utf-8')

output_file("bar_basic.html")

df['DT']=pd.to_datetime(df['DT'])

p = figure(x_axis_type='datetime',
           plot_width=1230,
           plot_height=500,
           title='Moviments')

p.vbar(x=df['DT'],top=df['SUM_IN'], width=100, fill_alpha=0.8, color='green')
p.vbar(x=df['DT'],top=df['SUM_OUT'], width=100, fill_alpha=0.8, color='red')

p.xgrid.grid_line_color = None

show(p)

That is the info of my dataframe:

RangeIndex: 133 entries, 0 to 132 Data columns (total 5 columns): DT 133 non-null datetime64[ns] TRANSACT_IN 133 non-null int64 TRANSACT_OUT
133 non-null int64 SUM_IN 133 non-null int64 SUM_OUT
133 non-null int64 dtypes: datetime64ns, int64(4)

like image 403
Arnold Souza Avatar asked Jan 02 '23 09:01

Arnold Souza


1 Answers

The underlying scale on datetime axes is milliseconds-since-epoch. So, currently you are looking at bars 500ms wide across a scale of months. You need to make the bars much wider. For instance, a bar "one day" wide would need:

width=24*60*60*1000 # 86400000

Alternatively with recent Bokeh versions you can also use a datetime.timedelta, e.g.

width=timedelta(days=1)
like image 69
bigreddot Avatar answered Jan 05 '23 17:01

bigreddot