From: Brice Waegenire <brice.wge@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [BUG] org--plot/sensible-tick-num when range is a power of 10
Date: Tue, 9 Jul 2024 18:34:20 +0200 [thread overview]
Message-ID: <CAL5NfX2UMXYWCy8qe2ttEgLmyM8JNDGUVaM4=078g7jbjfcajg@mail.gmail.com> (raw)
Hello,
I've found a bug in =org--plot/sensible-tick-num=, when a plot has a
range of a power of 10 (1, 10, 100, ...).
To reproduce, run =org-plot/gnuplot= on the following plot:
#+plot: type:radar min:0 max:10
| Metric | Value |
|---------+-------|
| alpha | 2 |
| beta | 4 |
| gamma | 6 |
| delta | 8 |
| epsilon | 10 |
It produce the error: =let*: Wrong type argument: number-or-marker-p, nil=.
A workaround is to fix the =ticks= value for example by appending =ticks:5=
to the plot line.
I'm not really sure how to correctly fix that bug, but the following
function work fine, at least for my use case. When =org-plot/prime-factors=
return =nil=, it returns ='(5)= instead:
#+begin_src elisp
(defun org--plot/sensible-tick-num (table &optional hard-min hard-max)
"From a the values in a TABLE of data, guess an appropriate number of ticks.
If HARD-MIN and HARD-MAX can be used to fix the ends of the axis."
(let* ((row-data
(mapcar (lambda (row) (org--plot/values-stats
(mapcar #'string-to-number (cdr row))
hard-min
hard-max)) table))
(row-normalised-ranges (mapcar (lambda (r-data)
(let ((val (round (*
(plist-get r-data :range-factor)
(plist-get r-data :nice-range)))))
(if (= (% val 10) 0) (/ val 10) val)))
row-data))
(range-prime-decomposition (mapcar (lambda (row-normalised-range)
(or
(org--plot/prime-factors row-normalised-range)
'(5)))
row-normalised-ranges))
(weighted-factors (sort (apply #'org--plot/merge-alists #'+ 0
(mapcar (lambda (factors)
(org--plot/item-frequencies factors t))
range-prime-decomposition))
(lambda (a b) (> (cdr a) (cdr b))))))
(apply #'* (org--plot/nice-frequency-pick weighted-factors))))
#+end_src
Cheers,
--
bricewge ~ 8929 BBC5 73CD 9206 3DDD 979D 3D36 CAA0 116F 0F99
next reply other threads:[~2024-07-09 16:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-09 16:34 Brice Waegenire [this message]
2024-07-11 11:43 ` [BUG] org--plot/sensible-tick-num when range is a power of 10 Ihor Radchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAL5NfX2UMXYWCy8qe2ttEgLmyM8JNDGUVaM4=078g7jbjfcajg@mail.gmail.com' \
--to=brice.wge@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.