使用散景时,如何设置图形的标题字体大小?
我试过(在ipython笔记本中):
import bokeh.plotting as bp
import numpy as np
bp.output_notebook()
x_points = np.random.rand(100)
y_points = np.random.rand(100)
bp.figure(title='My Title', x_axis_label='X axis', y_axis_label='Y axis', \
text_font_size='8pt')
bp.scatter(x_points, y_points)
bp.show()
Run Code Online (Sandbox Code Playgroud)
我已经尝试过text_font_size,label_text_font,title_font_size等.文档中的所有信息都在哪里?
我已经使用Bokeh成功绘制了几个数据集和拟合函数,但是我真的需要在图表中添加误差条,我该怎么做呢?
我有一个看起来像的df:
df.head()
Out[1]:
A B C
city0 40 12 73
city1 65 56 10
city2 77 58 71
city3 89 53 49
city4 33 98 90
Run Code Online (Sandbox Code Playgroud)
可以通过以下代码创建示例df:
df = pd.DataFrame(np.random.randint(100,size=(1000000,3)), columns=list('ABC'))
indx = ['city'+str(x) for x in range(0,1000000)]
df.index = indx
Run Code Online (Sandbox Code Playgroud)
我想做的是:
a)确定A列的适当直方图桶长度,并将每个城市分配给A列的桶
b)确定B列的适当直方图桶长度,并将每个城市分配给B列的桶
也许结果df看起来像(或者是否有更好的内置方式在熊猫?)
df.head()
Out[1]:
A B C Abkt Bbkt
city0 40 12 73 2 1
city1 65 56 10 4 3
city2 77 58 71 4 3
city3 89 53 49 5 3
city4 33 98 90 …Run Code Online (Sandbox Code Playgroud) 我一直在寻找Bokeh API文档几个小时,并没有找到任何相关的东西.所以我想问一下是否有人知道Bokeh API是否支持3D绘图(类似于你在matplotlib中可以做的mpl_toolkits.mplot3d)?
我使用以下代码生成交互式散景网络图.如何将节点名称添加到散景图中的节点?
from bokeh.io import show, output_notebook
from bokeh.models import Plot, Range1d, MultiLine, Circle, HoverTool, TapTool, BoxSelectTool
from bokeh.models.graphs import from_networkx, NodesAndLinkedEdges, EdgesAndLinkedNodes
from bokeh.palettes import Spectral4
from bokeh.models import LabelSet
plot = Plot(plot_width=900, plot_height=500,
x_range=Range1d(-1.1,1.1), y_range=Range1d(-1.1,1.1))
plot.title.text = "Graph Interaction Demonstration"
plot.add_tools(HoverTool(tooltips=None), TapTool(), BoxSelectTool())
graph_renderer = from_networkx(G, nx.circular_layout, scale=1, center=(0,0))
graph_renderer.node_renderer.glyph = Circle(size=15, fill_color=Spectral4[0])
graph_renderer.node_renderer.selection_glyph = Circle(size=15, fill_color=Spectral4[2])
graph_renderer.node_renderer.hover_glyph = Circle(size=15, fill_color=Spectral4[1])
graph_renderer.node_renderer.glyph.properties_with_values()
graph_renderer.edge_renderer.glyph = MultiLine(line_color="#CCCCCC", line_alpha=0.8, line_width=5)
graph_renderer.edge_renderer.selection_glyph = MultiLine(line_color=Spectral4[2], line_width=5)
graph_renderer.edge_renderer.hover_glyph = MultiLine(line_color=Spectral4[1], line_width=5)
graph_renderer.selection_policy = NodesAndLinkedEdges()
graph_renderer.inspection_policy …Run Code Online (Sandbox Code Playgroud) 首先,在此之前被标记为重复,我已经阅读了其他解决方案,不幸的是,它们都没有为我工作.
我的问题是我想在Juypter Notebook中显示散景图(仅在Jupyter Notebook中),而不是在新的选项卡/窗口中.
output_file
Run Code Online (Sandbox Code Playgroud)
至
output_notebook
Run Code Online (Sandbox Code Playgroud)
虽然情节是,如果我这样做了内嵌显示,背景虚化不会停止也打开一个新标签,并显示不必要的情节出现.
由于我将在我的项目中创建大量的图表,所以不必总是关闭这个新的选项卡并返回到笔记本,这是非常好的,但只是让它停止创建新选项卡,就像它可以使用例如matplotlib一样.
令我困惑的是,如果我加载官方教程并在那里输入代码,例如
import numpy as np
x = np.linspace(0, 10, 100)
y = np.exp(x)
p = figure()
p.line(x, y)
show(p)
Run Code Online (Sandbox Code Playgroud)
没有新标签打开.如果我现在在我的机器的Juypter Notebook上本地运行相同的代码,它会打开一个新选项卡.
我已经尝试了一段时间来解决这个问题,任何帮助都会非常感激.
先谢谢,文森特
我有一个散景图,工具栏中有一个重置按钮.基本上,当我更新我在图中绘制的数据时,我想"重置"图形.我怎样才能做到这一点?
我的散景应用程序有一个特定的设计.我正在使用bokeh 0.12.3和一个散景服务器来保持一切同步.请看看我的模型:
在左侧,有一个静态导航栏,视图的右侧部分将由手动添加的图组成.右侧的绘图列数量应改变窗口大小.我很清楚散布布局文档布局图和小部件,但它有点复杂.这是我目前的布局:
doc_layout = layout(children=[[column(radio_buttons,
cbx_buttons,
div,
data_table,
plot,
button)]],
sizing_mode='scale_width')
curdoc().add_root(doc_layout)
Run Code Online (Sandbox Code Playgroud)
为了添加我使用的新图:
doc_layout.children[-1].children.append(plot)
# appends plot to layout children [[column(..), plot]]
Run Code Online (Sandbox Code Playgroud)
但这种行为很奇怪,而且根本不是我想要达到的目标.新的图表添加在列(菜单面板)的顶部.
这里有一个简短的例子,你可以尝试看看我的意思:
from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.models.sources import ColumnDataSource
from bokeh.models.widgets import Button, DataTable, TableColumn
from bokeh.layouts import layout, widgetbox, column, row
WIDTH = 200
HEIGHT = 200
def add_plot():
p = figure(width=WIDTH, height=HEIGHT, tools=[], toolbar_location=None)
p.line([0, 1, 2, 3, 4, 5], [0, 1, 4, 9, 16, 25]) …Run Code Online (Sandbox Code Playgroud) 我正在散景图中显示一张图片,并使用BoxSelectTool绘制一个矩形.
box_select = BoxSelectTool(callback=callback)
p2 = figure(x_range=(0,700), y_range=(0,500),plot_width=1100,plot_height=1100,tools=[box_select])
p2.image_url( url='url',
x=1, y=1, w=700, h=500, anchor="bottom_left",source=im_src)
rect_source = ColumnDataSource(data=dict(x=[], y=[], width=[], height=[]))
callback = CustomJS(args=dict(rect_source=rect_source), code="""
// get data source from Callback args
var data = rect_source.data;
/// get BoxSelectTool dimensions from cb_data parameter of Callback
var geometry = cb_data['geometry'];
/// calculate Rect attributes
var width = geometry['x1'] - geometry['x0'];
var height = geometry['y1'] - geometry['y0'];
var x = geometry['x0'] + width/2;
var y = geometry['y0'] + height/2;
/// update data …Run Code Online (Sandbox Code Playgroud)