python - 如何在 hvPlot 图中禁用科学记数法?

标签 python bokeh hvplot holoviz

我今天刚刚开始使用 hvPlot,作为 Panel 的一部分。
我很难弄清楚如何在我的图中禁用科学记数法。例如,这里是一个简单的条形图。轴和提示框采用科学计数法。如何将格式更改为简单的 int?
enter image description here
我正在向非数字和非技术管理人员展示这一点。他们宁愿只看到基本的整数,而我不想向他们解释什么是科学记数法。
我在文档中找不到任何可以帮助我的内容:https://hvplot.holoviz.org/user_guide/Customization.html
我还尝试将 Bokeh 文档中的建议拼凑在一起。
我想不通。请帮忙!谢谢
我的简单 df:

   local_date      amount
0      Jan 19   506124.98
1      Feb 19   536687.28
2      Mar 19   652279.31
3      Apr 19   629440.06
4      May 19   703527.00
5      Jun 19   724234.08
6      Jul 19   733413.32
7      Aug 19   758647.44
8      Sep 19   782676.16
9      Oct 19   833674.28
10     Nov 19   864649.74
11     Dec 19   849920.47
12     Jan 20   857732.52
13     Feb 20   927399.50
14     Mar 20  1152440.49
15     Apr 20  1285779.35
16     May 20  1431744.76
17     Jun 20  1351893.95
18     Jul 20  1325507.38
19     Aug 20  1299528.81
和代码:
df.hvplot.bar(height=500,width=1000)

最佳答案

您可以指定要在 x 轴或 y 轴刻度中使用的格式化程序,例如:

df.hvplot.bar(height=500,width=1000, yformatter='%.0f')
根据Customization您还引用的页面,xformatteryformatter参数可以接受“printf 格式化程序,例如 '%.3f' 和 bokeh TickFormatter”。因此,另一种方法是传递自定义 formatter来自 boken.models.formatters并对其进行自定义(注意:您还可以探索许多其他格式化程序)。例如:
from bokeh.models.formatters import BasicTickFormatter
df.hvplot.bar(height=500,width=1000, yformatter=BasicTickFormatter(use_scientific=False))
两者都应该给你这样的结果:
enter image description here
现在,编辑悬停工具提示格式有点棘手。一种方法是将图形对象分配为自定义 HoverTool ,以下列方式:
from bokeh.models import HoverTool
hover = HoverTool(tooltips=[("amount", "@amount{0,0}"), ("local_date", "@local_date")]) 
df.hvplot.bar(height=500, width=1000, yformatter='%.0f', use_index=False).opts(tools=[hover])
您可以找到有关如何配置自定义 HoverTool 的更多详细信息here .

关于python - 如何在 hvPlot 图中禁用科学记数法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64338294/

相关文章:

python - 如何检查 float pandas 列是否只包含整数?

python - 在 Bokeh (0.11) 服务器应用程序中刷新/更新绘图的快速正确方法是什么?

python - 如何将 HoverTool 添加到数据表(Bokeh、Python)

python - 每个类别的 Holoviews 颜色

python - 使用 Holoviews 或 Hvplot 时将框缩放(或平移或滚轮缩放)设置为默认值

python-3.x - 更改 hvplot.hist 的默认悬停数据

python - 属性错误 : 'Response' object has no attribute 'read'

python - 按 id 汇总多个字符串列 - python

python - 如何在多个文件中一次高效地搜索多个字符串?

javascript - 模拟 Tableau 的嵌入式悬停工具图