问题都在标题中。我正在尝试使用从 bokeh.charts 导入的 Histogram 对象,但无法弄清楚如何以对数比例显示它。在我的特殊情况下,我需要以对数刻度显示 x 轴和 y 轴。
制作 100% 堆积条形图的最简单方法是什么Bokeh?,例如,假设我有以下列
S P
34 65
23 44
12 81
9 23
Run Code Online (Sandbox Code Playgroud)
在excel我可以使这种类型的情节很容易,所以我会得到这样的东西:
但是,我想进行一些交互(例如在悬停时显示值),因此我想在Bokeh. 我是初学者,Bokeh我还没有找到任何类似的例子。那么,最好的方法是什么?
我在运行我的代码时收到此错误。主要问题是 hplot 没有正确导入。
File "MACD.py", line 10, in <module>
from bokeh.plotting import figure, show, output_file, hplot
ImportError: cannot import name hplot
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
macds = macd, macdsignal, macdhist = MACD(hloc, fastperiod=12, slowperiod=26, signalperiod=9)
macdhist_f=[]
iter=0
for x in np.nditer(macdhist):
iter+=1
macdhist_f.append([iter,float(x)])
print(type(x))
print macdhist_f
macdhist_df = pd.DataFrame(macdhist_f)
defaults.width = 450
defaults.height = 350
hist = Histogram(macdhist_df, values='macd hist', bins=50,
title="MACD Histogram")
show(hplot(hist))
coin = "DASH_"
output_file(coin + "html", title="macd")
Run Code Online (Sandbox Code Playgroud) 如何调整 HTMLTamplateFormatter 中数据的数字格式。我希望数字格式为“(0,0)”。以下是错误尝试的示例代码:
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, TableColumn, HTMLTemplateFormatter, NumberFormatter
from bokeh.io import show
dict1 = {'x':[0]*6,'y':[500,1000,-1000,1000,-5000,500],'z':[0,0,1,1,1,2]}
source = ColumnDataSource(data=dict1)
template="""
<b><div style="background:<%=
(function colorfromint(){
if(z == 1){
return("NavajoWhite")}
else{if(z == 2){
return("Orange")}
else{return("")}
}}()) %>;
font-style:'(0,0)'"> ### this part needs fixed
<%= value %></div></b>
"""
formater = HTMLTemplateFormatter(template=template)
columns = [
TableColumn(field="x", title="x"),
TableColumn(field="y", title="y",formatter=formater)
]
data_table = DataTable(source=source, columns=columns, width=800)
show(data_table)
Run Code Online (Sandbox Code Playgroud) 我试图绘制相当大量的数据,这些数据一直追溯到 1998 年。
我的代码似乎工作正常,但运行时抛出错误消息“BokehUserWarning:ColumnDataSource 的列必须具有相同长度”
这是我的代码:
import pandas as pd
from bokeh.io import show, output_file, gridplot
from bokeh.plotting import figure
#Create dataframe
df = pd.read_csv('/Users/macbook/Desktop/source.tab', names=[
'#','datesent','total','place'] delimiter='\t', header=None, encoding="ISO-8859-1")
#Format date
df['datesent'] = pd.to_datetime(df['datesent'], dayfirst=True)
#Datamunging
transactionssent = dict(pd.melt(df,value_vars=['datesent']).groupby('value').size())
transactionssent_dataframe = pd.DataFrame.from_dict(transactionssent, orient= 'index')
transactionssent_dataframe.columns = ['Number of sent transactions']
transactionssent_dataframe.index.rename('Date of sending', inplace= True)
#X- and Y-axis
x = pd.bdate_range('2017-1-1', '2200-1-1')
y = transactionssent_dataframe['Number of sent transactions']
#Bokeh object
ts = figure(x_axis_type="datetime")
#Show plot
ts.line(x, y)
output_file('/Users/macbook/Desktop/plot.html')
Run Code Online (Sandbox Code Playgroud)
所有的输出实际上都符合预期。错误是什么意思?我真的必须从数据框中创建一个 …
我想在双轴图上绘制一些数据,我在文档中找到了一个示例,但我需要动态范围 (DataRange1d),因为我的数据在可视化过程中会发生变化,我事先不知道它会是什么。
我的问题:两个 y 范围具有相同的缩放比例,并且锁定在一起:我无法仅缩小范围。
from numpy import pi, arange, sin, linspace
from bokeh.plotting import show
from bokeh.models import LinearAxis, Range1d, DataRange1d
from bokeh.models import Plot, Title, PanTool, WheelZoomTool
from bokeh.models import Circle, ColumnDataSource
# get some data
x = arange(-2*pi, 2*pi, 0.1)
y = sin(x)
y2 = linspace(0, 100, len(y))
# configure plot
p = Plot(title = Title(text="Titre"), x_range = DataRange1d(), y_range = DataRange1d())
p.add_tools(PanTool(), WheelZoomTool())
p.add_layout(LinearAxis(), "below")
p.add_layout(LinearAxis(), "left")
# add extra y range
p.extra_y_ranges = …Run Code Online (Sandbox Code Playgroud) 我有一个简单的多数据条形图(非堆叠),并希望能够在用鼠标悬停时显示条形图的(最大值)值。
但是,我无法将悬停位置链接到数据。我不确定从条形图中调用索引的语法/编码如何。
这是我的代码:
from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource, FactorRange
from bokeh.plotting import figure
output_file("bars.html")
LOCATIONS = ['CPC','OG2','HS82-83','IG6','IG4','IG10']
CHECKS = ['AID CHECKS', 'ITEMS SCREENED', 'PERSONS SCREENED']
data = {'LOCATIONS' : LOCATIONS,
'AID CHECKS' : [208,622,140,1842,127,1304],
'PERSONS SCREENED' : [201,484,126,1073,81,676],
'ITEMS SCREENED' : [28,71,31,394,32,207]}
x = [ (location, check) for location in LOCATIONS for check in CHECKS ]
counts = sum(zip(data['AID CHECKS'], data['PERSONS SCREENED'], data['ITEMS SCREENED']), ()) # like an hstack
source = ColumnDataSource(data=dict(x=x, counts=counts))
p = figure(x_range=FactorRange(*x), …Run Code Online (Sandbox Code Playgroud) 我想创建一个背景虚化的彩条使用matplotlib的coolwarm颜色表。没有必要打勾。我该怎么做?
我想Hovertool在一个图中使用多个s 和Hovertool'snames属性来选择性地应用每个工具。以
hover1 = HoverTool(tooltips=[("group", "1")], names = ['line1'])
hover2 = HoverTool(tooltips=[("group", "2")], names = ['lines2'])
Run Code Online (Sandbox Code Playgroud)
和两个数据源:
source1 = ColumnDataSource(data=dict(
xs=[[1, 3, 2], [3, 4, 6, 6]],
ys=[[2, 1, 4], [4, 7, 8, 5]],
))
source2 = ColumnDataSource(data=dict(
xs=[[1, 3, 2], [6, 7, 9, 8]],
ys=[[-1, 0, 1], [1, 1, 2, 1]]
))
Run Code Online (Sandbox Code Playgroud)
我虽然以下(使用 bokeh.models API)应该做我想做的
p = figure(plot_width=400, plot_height=400)
l1 = MultiLine(xs='xs', ys='ys', name='lines1')
l2 = MultiLine(xs='xs', ys='ys', name='lines2')
p.add_tools(hover)
p.add_tools(hover2)
p.add_glyph(source1, l1) …Run Code Online (Sandbox Code Playgroud) 我一直在玩散景,以获得交互式散点图、工具提示和交互式图例等。
目前,我可以使用绘图后面的 Pandas 数据框中列的值来设置点的颜色。但是我想知道是否可以使用数据框中的另一列设置标记类型(菱形、圆形、方形等)?
我很欣赏这意味着您需要一个双重图例,但希望这不会成为太大的问题。
bokeh ×10
python ×6
pandas ×2
python-3.x ×2
bar-chart ×1
datatable ×1
histogram ×1
hover ×1
html ×1
matplotlib ×1
plot ×1
python-2.7 ×1
ta-lib ×1