Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 908EF200B6B for ; Fri, 26 Aug 2016 03:19:37 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 8EE4B160ABD; Fri, 26 Aug 2016 01:19:37 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D44C9160AA5 for ; Fri, 26 Aug 2016 03:19:36 +0200 (CEST) Received: (qmail 34545 invoked by uid 500); 26 Aug 2016 01:19:35 -0000 Mailing-List: contact commits-help@zeppelin.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zeppelin.apache.org Delivered-To: mailing list commits@zeppelin.apache.org Received: (qmail 34536 invoked by uid 99); 26 Aug 2016 01:19:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Aug 2016 01:19:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0608FE098D; Fri, 26 Aug 2016 01:19:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: bzz@apache.org To: commits@zeppelin.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: zeppelin git commit: [ZEPPELIN-1327] Fix bug in z.show for Python interpreter Date: Fri, 26 Aug 2016 01:19:35 +0000 (UTC) archived-at: Fri, 26 Aug 2016 01:19:37 -0000 Repository: zeppelin Updated Branches: refs/heads/master 42e3a141d -> 8064c5491 [ZEPPELIN-1327] Fix bug in z.show for Python interpreter ### What is this PR for? Currently, height parameter for z.show implementation to display PNG images in Python interpreter is not working. This PR fix that bug. ### What type of PR is it? Bug Fix ### What is the Jira issue? [ZEPPELIN-1327](https://issues.apache.org/jira/browse/ZEPPELIN-1327) ### How should this be tested? ```python import matplotlib.pyplot as plt x = [1,2,3,4,5] y = [6,7,8,9,0] plt.plot(x, y, marker="o") z.show(plt, height="200px") plt.close() ``` ### Questions: * Does the licenses files need update? No * Is there breaking changes for older versions? No * Does this needs documentation? No Author: Paul Bustios Closes #1352 from bustios/ZEPPELIN-1327 and squashes the following commits: 8eff11a [Paul Bustios] Change default values of width and height and add img tag for PNG images b3c74a8 [Paul Bustios] Add comment explaining the need for decoding bytes to string 1a78a37 [Paul Bustios] Fix bug in z.show for Python interpreter Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/8064c549 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/8064c549 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/8064c549 Branch: refs/heads/master Commit: 8064c54917f86ad08a15ba8c86341dce6dfac391 Parents: 42e3a14 Author: Paul Bustios Authored: Tue Aug 23 17:54:07 2016 -0300 Committer: Alexander Bezzubov Committed: Fri Aug 26 10:19:30 2016 +0900 ---------------------------------------------------------------------- python/src/main/resources/bootstrap.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/8064c549/python/src/main/resources/bootstrap.py ---------------------------------------------------------------------- diff --git a/python/src/main/resources/bootstrap.py b/python/src/main/resources/bootstrap.py index 16950fd..235f7ab 100644 --- a/python/src/main/resources/bootstrap.py +++ b/python/src/main/resources/bootstrap.py @@ -117,7 +117,6 @@ class PyZeppelinContext(object): def __init__(self): self.max_result = 1000 - self.py3 = bool(sys.version_info >= (3,)) def input(self, name, defaultValue=""): print(self.errorMsg) @@ -165,28 +164,27 @@ class PyZeppelinContext(object): #) body_buf.close(); header_buf.close() - def show_matplotlib(self, p, width="100%", height="100%", - fmt='png', **kwargs): + def show_matplotlib(self, p, fmt="png", width="auto", height="auto", + **kwargs): """Matplotlib show function """ - if fmt == 'png': + if fmt == "png": img = BytesIO() p.savefig(img, format=fmt) - html = "%html " img_str = b"data:image/png;base64," img_str += base64.b64encode(img.getvalue().strip()) - # Need to do this for python3 compatibility - if self.py3: - img_str = img_str.decode('ascii') - - elif fmt == 'svg': + img_tag = "" + # Decoding is necessary for Python 3 compability + img_str = img_str.decode("ascii") + img_str = img_tag.format(img=img_str, width=width, height=height) + elif fmt == "svg": img = StringIO() p.savefig(img, format=fmt) - html = "%html
{img}
" img_str = img.getvalue() else: raise ValueError("fmt must be 'png' or 'svg'") + html = "%html
{img}
" print(html.format(width=width, height=height, img=img_str)) img.close()