Created
November 5, 2021 10:48
-
-
Save Metaxal/0cb555abb0d928d2d892ee92580d3623 to your computer and use it in GitHub Desktop.
Customizing plot ticks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(require plot) | |
(define (tlayout low high) | |
(list | |
; major ticks: tick is shown with label | |
(pre-tick pi #t) | |
(pre-tick (sqrt 2) #t) | |
(pre-tick 0.5 #t) | |
; minor ticks: tick is shown, but without label | |
(pre-tick 1 #f) | |
(pre-tick 2 #f) | |
(pre-tick 3 #f) | |
(pre-tick 4 #f))) | |
(define (tformat low high pre-ticks) | |
; custom formatter of the major tick labels | |
(map (λ (p) (~r (pre-tick-value p) | |
#:precision 4 | |
#:min-width 4)) | |
pre-ticks)) | |
(parameterize ([plot-x-ticks | |
(ticks tlayout tformat)]) | |
(plot | |
(function values 0 5))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and this is how to have specific labels at specific positions:
(yes, the numbers are wrong, I don't care)