I have just started using hvPlot today, as part of Panel.
I am having a difficult time figuring out how to disable scientific notation in my plots. For example here is a simple bar plot. The axis and the tootltip are in scientific notation. How can I change the format to a simple int?
I am showing this to non numerical and non techy management. They would rather see just basic integers and I don’t want to have to explain to them what scientific notation is.
I could not find anything in the docs to help me: https://hvplot.holoviz.org/user_guide/Customization.html
I’ve also tried to cobble together suggestions from Bokeh docs.
I can’t figure it out. Please help! Thanks
My simple 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
And code:
df.hvplot.bar(height=500,width=1000)
First of all, create a vector and its plot using plot function. Then, use options(scipen=999) to remove scientific notation from the plot.
Subplots ¶ When plotting multiple columns, hvPlot will overlay the plots onto one axis by default so that they can be compared easily in a compact format:
When plotting multiple columns, hvPlot will overlay the plots onto one axis by default so that they can be compared easily in a compact format:
In matplotlib axis formatting, "scientific notation" refers to a multiplier for the numbers show, while the "offset" is a separate term that is added. The x-axis will have an offset (note the + sign) and the y-axis will use scientific notation (as a multiplier -- No plus sign).
To prevent scientific notation, we must pass style='plain' in the ticklabel_format method. Pass two lists to draw a line using plot () method. Using ticklabel_format () method with style='plain'. If a parameter is not set, the corresponding property of the formatter is left unchanged.
You can specify the formatter you would like to use in either x- or y-axis ticks, as such:
df.hvplot.bar(height=500,width=1000, yformatter='%.0f')
According to the Customization page you also referenced, the xformatter
and yformatter
arguments can accept "printf formatter, e.g. '%.3f', and bokeh TickFormatter". So, another way to do it is by passing a custom formatter
from boken.models.formatters
and customize it as such (Note: there's many other formatters you can also explore). For example:
from bokeh.models.formatters import BasicTickFormatter
df.hvplot.bar(height=500,width=1000, yformatter=BasicTickFormatter(use_scientific=False))
Both should give you a result like this:
Now, editing the hover tooltip format is a bit tricker. One way to do it is to assign the figure object as custom HoverTool
, in the following fashion:
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])
You can find more details on how to configure a custom HoverTool
here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With