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