From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: Plotting in Emacs? Date: Tue, 18 Apr 2023 07:38:53 +0300 Message-ID: References: <87a5z56d0j.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3882"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.2.9+54 (af2080d) (2022-11-21) Cc: Help Gnu Emacs mailing list To: Marcin Borkowski Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Apr 18 06:51:28 2023 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1podJQ-0000mj-2O for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 18 Apr 2023 06:51:28 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1podIl-0006a0-Dz; Tue, 18 Apr 2023 00:50:47 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1podIi-0006Zc-8W for help-gnu-emacs@gnu.org; Tue, 18 Apr 2023 00:50:44 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1podIf-0008PX-OO for help-gnu-emacs@gnu.org; Tue, 18 Apr 2023 00:50:43 -0400 Original-Received: from localhost ([::ffff:41.75.176.86]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000103A05.00000000643E21A4.00004965; Mon, 17 Apr 2023 21:50:43 -0700 Mail-Followup-To: Marcin Borkowski , Help Gnu Emacs mailing list Content-Disposition: inline In-Reply-To: <87a5z56d0j.fsf@mbork.pl> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:143296 Archived-At: * Marcin Borkowski [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/