我有一张图表,x轴使用datetime,y轴使用美元,Bokeh。我想在绘图区域的左上角放置一个徽标。Bokeh文档在放置图像时显得特别神秘。此代码适用于:
from bokeh.plotting import figure, show
#p = figure(x_range=(0,1200), y_range=(0,600))
p = figure(plot_width=1200, plot_height=600,
sizing_mode = 'scale_width',
toolbar_location='above',
x_axis_label='date',
x_axis_type='datetime',
y_axis_label='value',
)
p.image_url(x=0, y=1, url=["Shrewd_Lines_200.png"], anchor='bottom_left')
show(p)
但是当我把它放在我的主图表中,那里的数据是datetime,我无法得到一个图像来显示。以下是主要图表中代码的关键摘录:
plot = figure(plot_width=1200, plot_height=600,
sizing_mode = 'scale_width',
toolbar_location='above',
tools=tools,
title=plot_dict['chart_title'],
x_axis_label='date',
x_axis_type='datetime',
y_axis_label='value',
)
plot.x_range.end=plot_dict['end_data'] + extend_time
if plot_dict['start_chart'] == 'auto':
plot.x_range.start=plot_dict['start_user_data']
else:
plot.x_range.start = plot_dict['start_chart']
plot.y_range.start=0
plot.y_range.end= extend_y * plot_dict['max_value']
plot.left[0].formatter.use_scientific = False
plot.title.text_font_size = "16pt"
我尝试了各种方法来绘制图像,例如:
plot.image_url(x=0, y=0, url=["Shrewd_Lines_200.png"], anchor='bottom_left')
plot.image_url(x=plot_dict['start_user_data'], y=10000000, url=["Shrewd_Lines_200.png"], anchor='bottom_left')
我在图表中有几个标签工作得很好。是否有一种使用屏幕单位指定图像位置和大小的方法,与指定标签位置的方法相同
我想我会发布我是如何工作的,以便继续前进。我使用下面的Bokeh图,将我的徽标与一些通用数学结合起来,将数据空间转换为屏幕空间。它不使用numpy数组或ColumnDataSource(两者都不坏,但尽量保持简单)就能做到这一点:
注意x_axis_类型可以是这个模式下的任何类型,datetime正是我要处理的问题
相关问题 更多 >
编程相关推荐