散景:竖线的宽度不变 [英] Bokeh: The widths of vertical bars doesn't change

查看:44
本文介绍了散景:竖线的宽度不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个找不到解决方案的问题.我想更改绘图的条形宽度,但不管我在方法vbar的WIDTH参数中输入多少,图形都保持不变.

这是代码:

来自bokeh.io导入显示的

 ,output_file来自bokeh.plotting导入图将熊猫作为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 =图形(x_axis_type ='datetime',plot_width = 1230,plot_height = 500,title =运动")p.vbar(x = df ['DT'],top = df ['SUM_IN'],宽度= 100,fill_alpha = 0.8,color ='green')p.vbar(x = df ['DT'],top = df ['SUM_OUT'],宽度= 100,fill_alpha = 0.8,color ='red')p.xgrid.grid_line_color =无显示(p) 

这是我的数据框的信息:

RangeIndex:133个条目,从0到132数据列(总共5列):DT 133非空datetime64 [ns] TRANSACT_IN 133非空int64 TRANSACT_OUT
133非空int64 SUM_IN 133非空int64 SUM_OUT
133个非null int64 dtypes:datetime64ns,int64(4)

解决方案

日期时间轴上的基础标度是毫秒-自纪元.因此,当前您正在寻找跨数月的500ms宽的条形图.您需要将条形图 很多 变宽.例如,一条一天"宽的酒吧将需要:

  width = 24 * 60 * 60 * 1000#86400000 

或者,在最近的Bokeh版本中,您也可以使用 datetime.timedelta ,例如

  width = timedelta(days = 1) 

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

The plot with WIDTH=500

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

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)

解决方案

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)

这篇关于散景:竖线的宽度不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆