* Plotting in Emacs?
@ 2023-04-18 4:16 Marcin Borkowski
2023-04-18 4:38 ` Jean Louis
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Marcin Borkowski @ 2023-04-18 4:16 UTC (permalink / raw)
To: Help Gnu Emacs mailing list
Hi everyone,
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.)
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.
The reason I want this is that I weigh myself every day, I put the
datapoints in an Org mode table (and use Org spreadsheet to compute
moving averages), and now I'd like to see a nice chart telling me
whether my diet works and I'm losing weight. So, calculating linear
regression (pretty easy with Org mode) and plotting a regression line
would also be cool.
Any ideas?
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Plotting in Emacs?
2023-04-18 4:16 Plotting in Emacs? Marcin Borkowski
@ 2023-04-18 4:38 ` Jean Louis
2023-05-23 17:14 ` Marcin Borkowski
2023-04-18 7:39 ` Tak Kunihiro
2023-05-20 8:26 ` Daniel Fleischer
2 siblings, 1 reply; 10+ messages in thread
From: Jean Louis @ 2023-04-18 4:38 UTC (permalink / raw)
To: Marcin Borkowski; +Cc: Help Gnu Emacs mailing list
* 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/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Plotting in Emacs?
2023-04-18 4:16 Plotting in Emacs? Marcin Borkowski
2023-04-18 4:38 ` Jean Louis
@ 2023-04-18 7:39 ` Tak Kunihiro
2023-05-20 7:55 ` Marcin Borkowski
2023-05-20 8:26 ` Daniel Fleischer
2 siblings, 1 reply; 10+ messages in thread
From: Tak Kunihiro @ 2023-04-18 7:39 UTC (permalink / raw)
To: Marcin Borkowski; +Cc: Help Gnu Emacs mailing list
I suggest to use org-babel with R.
1. Install R.
2. Create a file `weight.org'.
3. Paste following lines and save.
4. M-x org-babel-execute-buffer
I spent significant time on this system. On this system, debug is hard.
Thus I do not suggest to do something complicated more than weight chart
using org-babel with R.
#+tblname: orgtbl0
| rownames | col1 | col2 |
|----------+------+------|
| day 1 | 1 | 60 |
| day 2 | 2 | 59 |
| day 3 | 3 | 58 |
| day 4 | 4 | 57 |
| day 5 | 5 | 58 |
#+header: :var dframe=orgtbl0 :rownames yes :colnames yes
#+header: :file plot.png
#+begin_src R :results graphics file :exports results
xx <- dframe[,1]
yy <- dframe[,2]
plot(xx,yy)
#+end_src
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Plotting in Emacs?
2023-04-18 7:39 ` Tak Kunihiro
@ 2023-05-20 7:55 ` Marcin Borkowski
0 siblings, 0 replies; 10+ messages in thread
From: Marcin Borkowski @ 2023-05-20 7:55 UTC (permalink / raw)
To: Tak Kunihiro; +Cc: Help Gnu Emacs mailing list, tkk
On 2023-04-18, at 09:39, Tak Kunihiro <homeros.misasa@gmail.com> wrote:
> I suggest to use org-babel with R.
>
> 1. Install R.
> 2. Create a file `weight.org'.
> 3. Paste following lines and save.
> 4. M-x org-babel-execute-buffer
Thanks, though I'd much prefer a pure Elisp solution. I managed to stay
away from R for all my life, and from what I heard about it, I'd like to
keep it that way... ;-)
Best,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Plotting in Emacs?
2023-04-18 4:16 Plotting in Emacs? Marcin Borkowski
2023-04-18 4:38 ` Jean Louis
2023-04-18 7:39 ` Tak Kunihiro
@ 2023-05-20 8:26 ` Daniel Fleischer
2023-05-23 17:18 ` Marcin Borkowski
2 siblings, 1 reply; 10+ messages in thread
From: Daniel Fleischer @ 2023-05-20 8:26 UTC (permalink / raw)
To: help-gnu-emacs
Marcin Borkowski [2023-04-18 Tue 06:16] wrote:
> The reason I want this is that I weigh myself every day, I put the
> datapoints in an Org mode table (and use Org spreadsheet to compute
> moving averages), and now I'd like to see a nice chart telling me
> whether my diet works and I'm losing weight. So, calculating linear
> regression (pretty easy with Org mode) and plotting a regression line
> would also be cool.
Plotting == gnuplot. You got to have a library that creates plots out of
data. Here is a snippet I use for the same purpose:
#+begin_src gnuplot :var data=body-data :file a.png
reset
set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 7 pi -1 ps 1.5
set style line 2 lc rgb '#269C52' lt 1 lw 2 pt 5 pi -1 ps 1.5
set pointintervalbox 3
set title "Body Metrics"
set xdata time
set timefmt "%Y-%m-%d"
set format x "%d/%m/%y"
set key spacing 1.5
set ytics 1
set y2tics 1
set ytics nomirror
set xtics nomirror
set xlabel "Date"
set ylabel "Kg"
set y2label "Fat \%"
set xrange ["2020-08-01":]
set yrange [80:90]
set y2range [10:25]
plot data using 1:2 axis x1y1 with lp ls 1 title 'Weight',\
'' using 1:3 axis x1y2 with lp ls 2 title 'Fat'
#+end_src
#+RESULTS:
[[file:a.png]]
#+NAME: body-data
| Date | Weight | Fat |
|------------------+--------+------|
| [2020-08-04 Tue] | 85.5 | |
| [2020-08-05 Wed] | 85.1 | 18.2 |
| [2020-08-06 Thu] | 86.5 | 18.9 |
| [2020-08-07 Fri] | 85.7 | 18.7 |
| [2020-08-08 Sat] | 85.3 | 18.3 |
| [2020-08-09 Sun] | 85.9 | 18.6 |
Feel free to change the gnuplot parameters for taste and the weight/fat
numbers as well.
--
Daniel Fleischer
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Plotting in Emacs?
2023-04-18 4:38 ` Jean Louis
@ 2023-05-23 17:14 ` Marcin Borkowski
0 siblings, 0 replies; 10+ messages in thread
From: Marcin Borkowski @ 2023-05-23 17:14 UTC (permalink / raw)
To: Jean Louis; +Cc: Help Gnu Emacs mailing list
On 2023-04-18, at 06:38, Jean Louis <bugs@gnu.support> wrote:
>> 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.
Thanks for your answer.
By "horizontal" plot I meant one where the independant variable is on
the horizontal axis.
Best,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Plotting in Emacs?
2023-05-20 8:26 ` Daniel Fleischer
@ 2023-05-23 17:18 ` Marcin Borkowski
2023-05-23 18:07 ` Daniel Fleischer
2023-05-25 2:32 ` Emanuel Berg
0 siblings, 2 replies; 10+ messages in thread
From: Marcin Borkowski @ 2023-05-23 17:18 UTC (permalink / raw)
To: Daniel Fleischer; +Cc: help-gnu-emacs
On 2023-05-20, at 10:26, Daniel Fleischer <danflscr@gmail.com> wrote:
> Marcin Borkowski [2023-04-18 Tue 06:16] wrote:
>
>> The reason I want this is that I weigh myself every day, I put the
>> datapoints in an Org mode table (and use Org spreadsheet to compute
>> moving averages), and now I'd like to see a nice chart telling me
>> whether my diet works and I'm losing weight. So, calculating linear
>> regression (pretty easy with Org mode) and plotting a regression line
>> would also be cool.
>
>
> Plotting == gnuplot. You got to have a library that creates plots out of
> data. Here is a snippet I use for the same purpose:
Well, as I said in my message, I explicitly want to avoid external
dependencies (like gnuplot). And for a solution using gnuplot, showing
the plot in the Emacs buffer is a must.
That said, chart.el (recommended elsewhere in this thread) is definitely
one interesting possibility.
Best,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Plotting in Emacs?
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
1 sibling, 1 reply; 10+ messages in thread
From: Daniel Fleischer @ 2023-05-23 18:07 UTC (permalink / raw)
To: help-gnu-emacs
Marcin Borkowski [2023-05-23 Tue 19:18] wrote:
> Well, as I said in my message, I explicitly want to avoid external
> dependencies (like gnuplot). And for a solution using gnuplot, showing
> the plot in the Emacs buffer is a must.
>
> That said, chart.el (recommended elsewhere in this thread) is definitely
> one interesting possibility.
This library looks experimental, with only ascii bar plot support. If
you want anything nicer you got to use an external package; even Emacs
built-in Calculator uses gnuplot to draw functions and data.
As for showing the plot, the babel code block I showed generates the
following result section
#+RESULTS:
[[file:a.png]]
Then you only need to make sure org mode shows images by calling
`org-toggle-inline-images' and it's part of the buffer, if that wasn't
clear.
--
Daniel Fleischer
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Plotting in Emacs?
2023-05-23 18:07 ` Daniel Fleischer
@ 2023-05-24 4:36 ` Marcin Borkowski
0 siblings, 0 replies; 10+ messages in thread
From: Marcin Borkowski @ 2023-05-24 4:36 UTC (permalink / raw)
To: Daniel Fleischer; +Cc: help-gnu-emacs
On 2023-05-23, at 20:07, Daniel Fleischer <danflscr@gmail.com> wrote:
> Marcin Borkowski [2023-05-23 Tue 19:18] wrote:
>
>> Well, as I said in my message, I explicitly want to avoid external
>> dependencies (like gnuplot). And for a solution using gnuplot, showing
>> the plot in the Emacs buffer is a must.
>>
>> That said, chart.el (recommended elsewhere in this thread) is definitely
>> one interesting possibility.
>
> This library looks experimental, with only ascii bar plot support. If
> you want anything nicer you got to use an external package; even Emacs
> built-in Calculator uses gnuplot to draw functions and data.
Well, I was under the impression that ASCII bar plots are the main
purpose of that package...
> As for showing the plot, the babel code block I showed generates the
> following result section
>
> #+RESULTS:
> [[file:a.png]]
>
> Then you only need to make sure org mode shows images by calling
> `org-toggle-inline-images' and it's part of the buffer, if that wasn't
> clear.
Ah, thanks, I missed that.
Still, I think I will (eventually) write my own. Gnuplot plots are
anything but good-looking (unless properly configured which I do not how
to do) - for good-looking plots I'd go to pgfplot, and for my use-case
I'd really prefer an ASCII art one.
Best,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Plotting in Emacs?
2023-05-23 17:18 ` Marcin Borkowski
2023-05-23 18:07 ` Daniel Fleischer
@ 2023-05-25 2:32 ` Emanuel Berg
1 sibling, 0 replies; 10+ messages in thread
From: Emanuel Berg @ 2023-05-25 2:32 UTC (permalink / raw)
To: help-gnu-emacs
Marcin Borkowski wrote:
> And for a solution using gnuplot, showing the plot in the
> Emacs buffer is a must.
Well, tell gnuplot you'd like an ASCII diagram, you'll get it.
But a PNG is also possible just as well as several other
formats all in speaking terms with Emacs :)
That said, the most important part to be played by Emacs is
editing the instructions to gnuplot how it will process the
data and how it visually will present the result.
With an Emacs major mode for the purpose, it's a very
pleasant game.
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-05-25 2:32 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-18 4:16 Plotting in Emacs? Marcin Borkowski
2023-04-18 4:38 ` Jean Louis
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
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).