python-3.x - 使用 € 作为散景中 NumeralTickFormatter 中的货币符号
问题描述
我想使用 € 符号而不是 $ 在由 holoviews (hv.Bars) 创建的散景图中格式化我的数字。
formatter = NumeralTickFormatter(format=f"{€ 0.00 a)")
不幸的是,这只会产生一个格式化的数字,而不是欧元符号
此外,这里提到的解决方法
和
formatter = PrintfTickFormatter(format=f'€ 0.00 a')
不起作用。
我实际上认为散景应该适应这一点,并提供添加任何东西作为符号的可能性。
解决方案
这可以使用FuncTickFormatter
一些 TypeScript 代码来完成。
from bokeh.models import FuncTickFormatter
p.xaxis.formatter = FuncTickFormatter(code='''Edit some typescript here.''')
最小示例
如果您的目标是为 0 到 1e7 之间的值编辑 x 轴,这应该可以工作。对于小于 1000 k
的值、介于 1000 和 1e6 之间的值以及m
更大的值,这将不选择任何单位。
from bokeh.plotting import figure, output_notebook, show
from bokeh.models import FuncTickFormatter
output_notebook()
# create a new plot with the toolbar below
p = figure(plot_width=400, plot_height=400,
title=None, toolbar_location="below")
x = [xx*1e6 for xx in range(1,6)]
y = [2, 5, 8, 2, 7]
p.circle(x, y, size=10)
p.xaxis.formatter = FuncTickFormatter(code='''
if (tick < 1e3){
var unit = ''
var num = (tick).toFixed(2)
}
else if (tick < 1e6){
var unit = 'k'
var num = (tick/1e3).toFixed(2)
}
else{
var unit = 'm'
var num = (tick/1e6).toFixed(2)
}
return `€ ${num} ${unit}`
'''
)
show(p)
输出
推荐阅读
- join - google sheet中没有名称时如何删除JOIN函数中的分隔符?
- android - Flutter 卡在 Running Gradle 任务 bundleRelease
- laravel - 将@符号与模型一起使用的目的是什么
- flutter - Flutter 切换飞行模式
- kubernetes - 如何使用 Workload 身份通过 Google Cloud .NET SDK 访问 Google Kubernetes Engine 中的 ESP?
- java - 数组中每个类别的总和
- python - 如何在文件的特定位置插入数据?
- json - 为什么我在 VS Code 的左上角看到红色图标而不是 json 图标?
- python - Splash 在返回 HTML 响应之前不解析 JS
- python - url网页抓取的python问题