From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id YNXzISyVomTYQAAASxT56A (envelope-from ) for ; Mon, 03 Jul 2023 11:30:20 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id ML/4ISyVomRKdAAA9RJhRA (envelope-from ) for ; Mon, 03 Jul 2023 11:30:20 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 54F972BE35 for ; Mon, 3 Jul 2023 11:30:14 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGFrh-0007Ho-Ir; Mon, 03 Jul 2023 05:29:01 -0400 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 1qGFre-0007HW-T8 for emacs-orgmode@gnu.org; Mon, 03 Jul 2023 05:29:00 -0400 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGFrc-00064X-N0 for emacs-orgmode@gnu.org; Mon, 03 Jul 2023 05:28:58 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 70F3F240027 for ; Mon, 3 Jul 2023 11:28:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1688376534; bh=XCFea6FhHBrQe2K2Y+EF6k+v0cVYnrugksexzXQLq44=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version: Content-Transfer-Encoding:From; b=XMNUpumDoRlWgsTuhjv8oVGu2XYRSOrAbcQlXJLp1wS8KlbL6CxwAm4ZwZqV7WhPi fdVrVjRb9J5kylwfR3y6RBNx8mqPl+BQNbvTpk6irl0sMS5Scl/0VMnDVB0qrNC4p3 ly/Ab5i8zV4DES6DsFiLdZJSy/UKpoC45DcH/u/XXiFlzJzS/WTyQNnlDwPjWRPNPO RWhcShJjFTQAYME9JTlzpm8w7f90lhIX0Wwdg9Lmy5ppuSJpWy80vBfIg55go5HVX3 79uibyjubr4QPhQXmjK660NYNGkyhUvXtxuHGaDogdrAmUV6R5yVtAdPH8ZFK81e+C 0iPJAyCepJi/Q== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4QvgbT58g0z9rxM; Mon, 3 Jul 2023 11:28:53 +0200 (CEST) From: Ihor Radchenko To: Liu Hui Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH] ob-python: support header argument `:results file graphics' In-Reply-To: References: Date: Mon, 03 Jul 2023 09:28:48 +0000 Message-ID: <877crh8htb.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -53 X-Spam_score: -5.4 X-Spam_bar: ----- X-Spam_report: (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=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: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1688376615; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=9MGuBethfwCwAkvTS2XsHAxjZeDwthPdMkAeh4+D30E=; b=XJ4EstkhQWuj3cRS6gwUR2CUvAUo7V1byz+78cDZl/bdev/EyxQ/D5AEyRMJ0/Oyg3ux/Q 9byLp9MToNO8HEHo7KOwTKAEOrxqyvymhiRmpIZYegDXyXInL/7pgtZ4uz+Sbe6FUZye3c 69TQQn7pDH1egtnGen5DbfiWAi1/+0OI8kJOWkZXk1y+mLApfANfDhGAJSzpqPNRekx0fX kGaIhHn4NqQ0YzjbgZMpqCgC3/31vhQNKlxhWviery/D97YH8iiNjbh1k7jbLzWdTLgihU b6Gxs2NjVfc5QensarQxtr6NlF6HTBqYMFajNNlAfLmfJ+J23Hymz/BrW9nJ0g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=XMNUpumD; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1688376615; a=rsa-sha256; cv=none; b=heS/aQDmynOICwLBvBLEIQyqaPYjAh06KPJ0HnLXtXrdihsV/qXjuPASN8oPtOTi0oCEZm ic3FkzJXsJBkoJK5jiPigGnQGrLfu7XVx84eJkxfCdfZUxXy55UgBbomKReeWfyPgz7qJ2 Jn/kTReBuDjjUQHfDGoU6TUbcqMgr9hDoyx76chq/KbeQL1bhGEGvPYVESAFlo08peQmw3 tFOSMQIp1eyhGrBmZ6Oqo7A/LhvxPiSwvH7ck/9/6ImIVD+sxO1J4PGel6b7MoYs61j4CR VYKorTYuSR+AWlHGbal6ViVAfMFRNBAP9m8a9xNVY4bBRjX29CZ8NTkSqOiVow== X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -6.23 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=XMNUpumD; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 54F972BE35 X-Spam-Score: -6.23 X-TUID: ulcEGgxJm0rM Liu Hui writes: > This patch adds graphics output support for ob-python via matplotlib. > Specifically, it allows to use header argument `:results file > graphics' as follows: > > #+begin_src python :file "test.png" :results graphics file > import matplotlib.pyplot as plt > plt.plot([1,2,3,4,5]) > #+end_src This might be a useful feature, but it will break the existing conventions, if used as in the patch. Currently, the above combination of :file and :results is treated as the following: =E2=80=98graphics=E2=80=99 When used along with =E2=80=98file=E2=80=99 type, the result is a link= to the file specified in =E2=80=98:file=E2=80=99 header argument. However, unlike= plain =E2=80=98file=E2=80=99 type, code block output is not written to the disk. The block is expected to generate the file by its side-effects only, as in the following example: #+begin_src shell :results file link :file "org-mode-unicorn.svg" wget -c "https://orgmode.org/resources/img/org-mode-unicorn.svg" #+end_src #+RESULTS: [[file:org-mode-unicorn.svg]] If =E2=80=98:file=E2=80=99 header argument is omitted, interpret sourc= e block result as the file path. > +try: > + import matplotlib.pyplot > + if len(matplotlib.pyplot.get_fignums()) > 0: > + matplotlib.pyplot.gcf().savefig('%s') > + else: > + raise RuntimeError('No figure is found. You need to use matplotl= ib\ > + functions, such as plot and imshow, to produce the graphics.') > +except ModuleNotFoundError: > + raise RuntimeError('ob-python depends on matplotlib for saving graph= ics') What if the user wants to use, for example, pyplot instead of matplotlib? --=20 Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at