bokeh

How to configure bokeh plot to have responsive width and fixed height

家住魔仙堡 提交于 2021-02-07 18:15:33
问题 I use bokeh embedded via the components function. Acutally I use : plot.sizing_mode = "scale_width" Which scales according to the width and maintains the aspect ratio. But I would like to have a responsive width but a fixed or maximum height. How is that possible to achieve? 回答1: There are stretch_both and scale_both options. How the item being displayed should size itself. Possible values are "fixed", "scale_width", "scale_height", "scale_both", and "stretch_both". "stretch_both" elements

interactive scatter plot in bokeh with hover tool

依然范特西╮ 提交于 2021-02-07 12:52:27
问题 I'm trying to make a an interactive plots with bokeh and the hover tool. More precisely, I'm trying to make a plot like the one I made in seaborn but I'd like it to be more interactive, meaning : I'd like people to see the income level when they hover over one point. I'd like the plot to stay scattered like that such thas each point is an individual point, letting people hover over them in the process. I'd like to pick the colors,to divide between different levels of income. How would I do

DropDown not working with Bokeh

拟墨画扇 提交于 2021-02-07 08:19:50
问题 I have a script to plot the prices of some share that the user wants to look at : he can choose the shares via a Dropdown button and Bokeh will draw the curve accordingly. (I am working in jupyter notebook) : from bokeh.io import output_notebook, show from bokeh.plotting import figure output_notebook() my code is the following : from bokeh.models import Callback, ColumnDataSource, Select,CustomJS from bokeh.plotting import figure, show, gridplot from bokeh.models.widgets.layouts import VBox

Embedding multiple bokeh HTML plots into flask

泄露秘密 提交于 2021-02-07 02:59:00
问题 I've searched for the past 3 hours on the bokeh website and stack overflow but none of it is really what i was looking for. I've generated my plots already, and have them in html files. All i want to do is embed the plots into my dashboard in a multi grid like formation in the white area in the pic below. However, adding just 2 plots cause them to overlay and be really weird. I used the {{ include }} method to include the graphs this way: Anyone can give me pointers on how to align them well?

Embedding multiple bokeh HTML plots into flask

我怕爱的太早我们不能终老 提交于 2021-02-07 02:57:36
问题 I've searched for the past 3 hours on the bokeh website and stack overflow but none of it is really what i was looking for. I've generated my plots already, and have them in html files. All i want to do is embed the plots into my dashboard in a multi grid like formation in the white area in the pic below. However, adding just 2 plots cause them to overlay and be really weird. I used the {{ include }} method to include the graphs this way: Anyone can give me pointers on how to align them well?

Python获取任意渐变色区段的16进制色值列表

不想你离开。 提交于 2021-02-06 10:41:59
背景 在玩转可视化的过程中,matplotlib及任意的其他可视化库,都有自己的cmap生成器,然而,有些时候,可能需要根据列表的长度预生成一组渐变色。 代码 def gen_colors(N): values = [int(i*250/N) for i in range(N)] # print(values) colors=["#%02x%02x%02x"%(200,int(g),40)for g in values] # 250 250 250 ,g值越小越靠近0红色 return colors colors = gen_colors(df['2020年'].shape[0]) colors 在Bokeh中进行渲染测试: x = y = [i for i in range(21)] p=figure() p.scatter(x,y,radius=0.2, fill_color=colors, fill_alpha=1.0, line_color=None ) show(p) 如果你想要其他色盘中的某一端色值: from PIL import Image # 16进制颜色格式颜色转换为RGB格式 def Hex_to_RGB(hex): r = int(hex[1:3],16) g = int(hex[3:5],16) b = int(hex[5:7], 16) return r

How to create custom hover tool with value mapping

本小妞迷上赌 提交于 2021-02-05 12:13:34
问题 I am trying to create a custom hover tool using which takes the y-value of the plot and maps the value to different value. The code I could come up with so far to achieve this functionality is from bokeh.models import HoverTool import holoviews as hv df = pd.DataFrame( { "zero": [0, 0, 0, 0, 0, 0, 0], "one": [1, 1, 1, 1, 1, 1, 1], "two": [2, 2, 2, 2, 2, 2, 2], } ) mapping = {i: c for i, c in enumerate(df.columns)} def col_mapping(num): return mapping[int(num)] hover = HoverTool(tooltips=[("x"

How to create custom hover tool with value mapping

╄→尐↘猪︶ㄣ 提交于 2021-02-05 12:11:55
问题 I am trying to create a custom hover tool using which takes the y-value of the plot and maps the value to different value. The code I could come up with so far to achieve this functionality is from bokeh.models import HoverTool import holoviews as hv df = pd.DataFrame( { "zero": [0, 0, 0, 0, 0, 0, 0], "one": [1, 1, 1, 1, 1, 1, 1], "two": [2, 2, 2, 2, 2, 2, 2], } ) mapping = {i: c for i, c in enumerate(df.columns)} def col_mapping(num): return mapping[int(num)] hover = HoverTool(tooltips=[("x"

Why is Bokeh's plot not changing with plot selection?

被刻印的时光 ゝ 提交于 2021-02-05 09:29:17
问题 Struggling to understand why this bokeh visual will not allow me to change plots and see the predicted data. The plot and select (dropdown-looking) menu appears, but I'm not able to change the plot for items in the menu. Running Bokeh 1.2.0 via Anaconda. The code has been run both inside & outside of Jupyter. No errors display when the code is run. I've looked through the handful of SO posts relating to this same issue, but I've not been able to apply the same solutions successfully. I wasn't

Python加载basemap绘制分省地图

瘦欲@ 提交于 2021-02-03 11:56:55
背景 Bokeh的Geo采用谷歌地图API,无法调用;国内的百度、腾讯、高德API在热点图渲染时可以用,至于Echarts的使用,也出现了一些鸡肋BUG,于是想从根源上解决这个问题。 代码 安装Basemap、下载繁体字转简体字代码。 (一)注意在渲染全国地图时,一定要加上湾湾,确保政治正确: m = Basemap ( llcrnrlon = 77 , llcrnrlat = 14 , urcrnrlon = 140 , urcrnrlat = 51 , projection = 'lcc' , lat_1 = 33 , lat_2 = 45 , lon_0 = 100 ) # m= Basemap(llcrnrlon=73, llcrnrlat=18, urcrnrlon=135, urcrnrlat=53) # m.drawcountries(linewidth=0.5) # m.drawcoastlines(linewidth=0.5) m . readshapefile ( 'gadm36_CHN_shp/gadm36_CHN_0' , 'china' , drawbounds = True ) # 中国,竟然没有湾湾,NND m . readshapefile ( 'gadm36_CHN_shp/gadm36_TWN_0' , 'taiwan' , drawbounds