You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@linkis.apache.org by GitBox <gi...@apache.org> on 2022/06/07 03:19:11 UTC
[GitHub] [incubator-linkis] peacewong commented on issue #2216: [Feature] [1.2.0]The python plt show method directly supports display
peacewong commented on issue #2216:
URL: https://github.com/apache/incubator-linkis/issues/2216#issuecomment-1148149312
Implementation steps: define a new show method, and then rewrite plt.show
```
def show_plog(fmt="png", width="auto", height="auto",
**kwargs):
"""Matplotlib show function
"""
import matplotlib.pyplot as p
if fmt == "png":
img = BytesIO()
p.savefig(img, format=fmt)
img_str = b"data:image/png;base64,"
img_str += base64.b64encode(img.getvalue().strip())
img_tag = "<img src={img} style='width={width};height:{height}'>"
# Decoding is necessary for Python 3 compability
img_str = img_str.decode("utf-8")
img_str = img_tag.format(img=img_str, width=width, height=height)
elif fmt == "svg":
img = StringIO()
p.savefig(img, format=fmt)
img_str = img.getvalue()
else:
raise ValueError("fmt must be 'png' or 'svg'")
html = "<div style='width:{width};height:{height}'>{img}<div>"
#print(html.format(width=width, height=height, img=img_str))
intp.showHTML(html.format(width=width, height=height, img=img_str))
img.close()
plt.show=show_plog
plt.show()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@linkis.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@linkis.apache.org
For additional commands, e-mail: notifications-help@linkis.apache.org