EDIT: thanks to @tmwilson26 I was able to fix it using
javascript code
(see comments below). However, I would still be interested to know if there is a solution usingfrom_py_func
.Python /散焦 - FuncTickFormatter
我正在使用散景,并努力使用FuncTickFormatter
来格式化我的轴。
具体而言,我使用的是FuncTickFormatter.from_py_func
函数。
我下面的代码示例不会产生任何结果(但也没有错误消息)。
from bokeh.models import ColumnDataSource,Label, FuncTickFormatter,DatetimeTickFormatter,NumeralTickFormatter, Select, FixedTicker, Slider,TableColumn,DatePicker, DataTable, TextInput, HoverTool,Range1d,BoxZoomTool, ResetTool
from bokeh.plotting import figure, output_file, show, curdoc
from bokeh.layouts import row, column, widgetbox, layout
from bokeh.io import output_notebook, push_notebook, show
output_notebook()
x = np.arange(10)
y = [random.uniform(0,5000) for el in x]
xfactors = list("abcdefghi")
yrange = Range1d(0,5000)
p = figure(x_range = xfactors, y_range = yrange,y_minor_ticks = 10)
p.circle(x,y, size = 14, line_color = "grey" , fill_color = "lightblue", fill_alpha = 0.2)
def ticker():
a = '{:0,.0f}'.format(tick).replace(",", "X").replace(".", ",").replace("X", ".")
return a
# If I comment below line out, code is running just fine
p.yaxis.formatter = FuncTickFormatter.from_py_func(ticker)
show(p)
如果我将FuncTickFormatter行注释掉,代码运行正常。如果我在此代码之外使用定义的函数ticker
,也可以使用。
任何关于我做错的建议都会非常有帮助。
谢谢!
现在'tick'在'ticker'的内部范围或主外部范围内的程序中没有被定义。 “tick”应该是“ticker”的输入参数吗? – tmwilson26
是的,我知道。但是我理解文档的方式我不必定义它(参见[Bokeh](http://bokeh.pydata.org/en/latest/docs/user_guide/styling.html#functickformatter))。显然, t虽然... – FredMaster
也许我的版本不喜欢它,因为它返回'ValueError:Function“func”只能有一个参数,但是0提供.'如果我没有定义'tick'作为输入,也就是说,除非我使用'%'而不是'格式'方法重新格式化字符串,否则这个图仍然是空白的。 – tmwilson26