From: Jean Louis <bugs@gnu.support>
To: Marcin Borkowski <mbork@mbork.pl>
Cc: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: Plotting in Emacs?
Date: Tue, 18 Apr 2023 07:38:53 +0300 [thread overview]
Message-ID: <ZD4e3eaZPZ91tZZC@protected.localdomain> (raw)
In-Reply-To: <87a5z56d0j.fsf@mbork.pl>
* Marcin Borkowski <mbork@mbork.pl> [2023-04-18 07:18]:
> we all know Emacs can draw -- there's Artist mode, there are SVGs and
> XBMs etc. Do you know of any packages which could use these features to
> plot charts directly in an Emacs buffer? Bonus points of the input can
> be an Org mode table (or a fragment of it, say the last 180 rows). They
> can be ASCII art charts or SVGs, or even XBMs -- I don't care. I would
> prefer, though, not to call gnuplot or other external software -- doing
> it all in Elisp would be better. (Though gnuplot would be ok if I could
> show the plot in the Org buffer, which is probably possible -- still,
> I'd like to explore my alternatives.)
This is not a package, just a guidance for you to use chart.el Emacs
library.
In this function I am getting some basic data I need, how you will get
data from Org table is for you to figure it out.
(defun cf-interactions-chart (&optional id)
"Opens up new chart buffer for interactions for contact ID"
(interactive)
(when-tabulated-id "people"
(let* ((sql (format "SELECT interactiontypes_name, interactions_count FROM interactiontypes, interactions WHERE interactions_people = %s AND interactions_interactiontypes = interactiontypes_id" id))
(data (rcd-sql-list sql cf-db))
(title (concat "Interactions with " (cf-people-name id)))
(namelst (reverse (mapcar (lambda (i) (car i)) data)))
(nametitle "Types of interactions")
(numlst (reverse (mapcar (lambda (i) (cadr i)) data)))
(numtitle "Number of interactions"))
(chart-bar-quickie 'vertical title namelst nametitle numlst numtitle))))
The result of that function is shown on this picture:
https://gnu.support/images/2023/04/2023-04-18/Screenshot-2023-04-18-07-29-53-903005389.png
> I found `orgtbl-ascii-plot', which looks great, but not exactly what
> I want -- it gives a "vertical" plot going down, and I want a more
> traditional "horizontal" plot going right.
I cannot know what you mean with horizontal plot.
Another function I use to create statistics uses R:
(defun rcd-r-pie-chart (title labels values output-file &optional overwrite colors)
(let* ((values (mapcar #'number-to-string values))
(colors (or colors (rcd-r-colors (length values))))
(colors (mapcar #'string-to-single-quotes colors))
(colors (string-join colors ", "))
(values (string-join values ", "))
(labels (mapcar #'string-to-single-quotes labels))
(labels (string-join labels ", "))
(script (format "
# Draw Pie Chart in R
# Data for Pie chart
x = c(%s)
labels = c(%s)
colors = c(%s)
# Give the chart file a name.
png(file = \"%s\", width=800, height=800)
# Plot the chart.
pie(x, labels=labels, height=0.20, main='%s', col=colors)
# Save the file.
dev.off()
" values labels colors output-file title)))
(if (and (file-exists-p output-file) (not overwrite))
(if (yes-or-no-p (format "Delete %s?" output-file))
(delete-file output-file)))
(string-to-file-force script "~/script")
(rcd-command-output-from-input "R" script "--vanilla")
(if (not (file-exists-p output-file))
(rcd-warning-message "File %s not created. Verify why." output-file)
(find-file output-file))))
And the result of that function is shown here:
https://gnu.support/images/2023/04/2023-04-18/stat.jpg
For those few missing functions you need to make the above work, you
can contact me privately.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
next prev parent reply other threads:[~2023-04-18 4:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-18 4:16 Plotting in Emacs? Marcin Borkowski
2023-04-18 4:38 ` Jean Louis [this message]
2023-05-23 17:14 ` Marcin Borkowski
2023-04-18 7:39 ` Tak Kunihiro
2023-05-20 7:55 ` Marcin Borkowski
2023-05-20 8:26 ` Daniel Fleischer
2023-05-23 17:18 ` Marcin Borkowski
2023-05-23 18:07 ` Daniel Fleischer
2023-05-24 4:36 ` Marcin Borkowski
2023-05-25 2:32 ` Emanuel Berg
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZD4e3eaZPZ91tZZC@protected.localdomain \
--to=bugs@gnu.support \
--cc=help-gnu-emacs@gnu.org \
--cc=mbork@mbork.pl \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).