![](/img/trans.png)
[英]How do i automatically update a dropdown selection widget when another selection widget is changed? (Python panel pyviz)
[英]How do I format numeric values in a Panel widget?
Using the Python library Panel , I'm trying to format an IntSliderRange to f"{the_slider_number} kr"
but the formatting argument in that class is not doing anything with the python text formatting tricks I am familiar with: 'kr', '{ } kr'、'{0} kr' 等。
運行help(pn.widgets.IntRangeSlider)
告訴我必須提供“格式字符串或散景 TickFormatter”,但我似乎找不到任何相關的搜索結果。
Copilot 建議將 '0[.]0a' 作為一個參數來處理格式,即以千為單位表示數字(1234 ->“1.2k”),但這根本不是我想要的。
有人認識這個格式化系統嗎? 我在哪里可以找到如何使用它?
最好的起點是關於格式化程序的散景文檔,特別是關於NumeralTickFormatter 的預定義格式化程序的部分。 您可以使用所有這些示例並將其傳遞給您的 slider。
from bokeh.plotting import show, output_notebook
from bokeh.models import Slider
output_notebook()
slider = Slider(
start=0,
end=10,
value=2,
step=0.1,
format ='$0,0.00'
)
show(slider)
此外,您可以將格式化程序的任何實例傳遞給format
。 例如,如果您想要一個€
符號,則沒有現有的字符串表示法。 但是您可以使用PrintfTickFormatter
來修改字符串。
from bokeh.plotting import show, output_notebook
from bokeh.models import Slider, PrintfTickFormatter
output_notebook()
slider = Slider(
start=0,
end=10,
value=2,
step=0.1,
format = PrintfTickFormatter(format='€%.2f')
)
show(slider)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.