Skip to content

Commit 1680e42

Browse files
authored
Merge pull request #288 from nhirschey/tickformat
2 parents e1d854c + d7d4def commit 1680e42

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/01_0_axis-styling.fsx

+24
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,30 @@ plot2
9999
plot2 |> GenericChart.toChartHTML
100100
(***include-it-raw***)
101101

102+
(**
103+
### Formatting the tick label
104+
105+
You can use `TickFormat` to format the tick label. The formatting rule uses the d3 formatting mini-languages which are very similar to those in Python. See [here](https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_format) for numbers and [here](https://github.com/d3/d3-time-format#locale_format) for dates. Plotly adds two items to d3's date formatter: "%h" for half of the year as a decimal number as well as "%{n}f" for fractional seconds with n digits. For example, "2016-10-13 09:15:23.456" with TickFormat "%H~%M~%S.%2f" would display "09~15~23.46".
106+
107+
This example styles the x-axis tick labels as dollars and the y-axis tick label as percentages with one decimal place.
108+
*)
109+
110+
let dollarAxis = LinearAxis.init(TickFormat="$")
111+
let percentAxis = LinearAxis.init(TickFormat=".1%")
112+
113+
let plot3 =
114+
Chart.Point(x,y)
115+
|> Chart.withXAxis dollarAxis
116+
|> Chart.withYAxis percentAxis
117+
118+
(*** condition: ipynb ***)
119+
#if IPYNB
120+
plot3
121+
#endif // IPYNB
122+
123+
(***hide***)
124+
plot3 |> GenericChart.toChartHTML
125+
(***include-it-raw***)
102126

103127
(**
104128
## Multiple axes

0 commit comments

Comments
 (0)