You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by al...@apache.org on 2022/06/23 07:04:39 UTC
[incubator-linkis] branch dev-1.2.0 updated: The python plt show method directly supports display (#2324)
This is an automated email from the ASF dual-hosted git repository.
alexkun pushed a commit to branch dev-1.2.0
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git
The following commit(s) were added to refs/heads/dev-1.2.0 by this push:
new 583b2a20d The python plt show method directly supports display (#2324)
583b2a20d is described below
commit 583b2a20dbc0d23db54d0536fbbaf427228a9733
Author: peacewong <wp...@gmail.com>
AuthorDate: Thu Jun 23 15:04:33 2022 +0800
The python plt show method directly supports display (#2324)
* Override plt.show to show_matplotlib method close #2216
* update path
---
.../entrance/restful/EntranceMetricRestfulApi.java | 2 +-
.../python/src/main/resources/python/python.py | 28 +++++++++++++++-
.../spark/src/main/resources/python/mix_pyspark.py | 38 ++++++++++++++++++++--
3 files changed, 63 insertions(+), 5 deletions(-)
diff --git a/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/restful/EntranceMetricRestfulApi.java b/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/restful/EntranceMetricRestfulApi.java
index ef16f06d4..e0216d28e 100644
--- a/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/restful/EntranceMetricRestfulApi.java
+++ b/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/restful/EntranceMetricRestfulApi.java
@@ -36,7 +36,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@RestController
-@RequestMapping(path = "/entrance/api/metrics")
+@RequestMapping(path = "/entrance/operation/metrics")
public class EntranceMetricRestfulApi {
private EntranceServer entranceServer;
diff --git a/linkis-engineconn-plugins/engineconn-plugins/python/src/main/resources/python/python.py b/linkis-engineconn-plugins/engineconn-plugins/python/src/main/resources/python/python.py
index d8df20ae4..1d06bdbcb 100644
--- a/linkis-engineconn-plugins/engineconn-plugins/python/src/main/resources/python/python.py
+++ b/linkis-engineconn-plugins/engineconn-plugins/python/src/main/resources/python/python.py
@@ -87,10 +87,22 @@ sys.stdout = linkisOutput
sys.stderr = errorOutput
intp = gateway.entry_point
-def show_matplotlib(p, fmt="png", width="auto", height="auto",
+def show_matplotlib(p=None,fmt="png", width="auto", height="auto",
**kwargs):
"""Matplotlib show function
"""
+
+ if p==None:
+ try:
+ import matplotlib
+ matplotlib.use('Agg')
+ import matplotlib.pyplot
+ p=matplotlib.pyplot
+ except Exception as e:
+ print("Failed to import matplotlib")
+ print(e)
+ return
+
if fmt == "png":
img = BytesIO()
p.savefig(img, format=fmt)
@@ -178,6 +190,20 @@ class PythonContext(object):
except ImportError:
return
+def setup_plt_show():
+ """Override plt.show to show_matplotlib method
+ """
+ try:
+ import matplotlib
+ matplotlib.use('Agg')
+ import matplotlib.pyplot
+ matplotlib.pyplot.show=show_matplotlib
+ except Exception as e:
+ print(e)
+ return
+
+setup_plt_show()
+
show = __show__ = PythonContext(intp)
__show__._setup_matplotlib()
diff --git a/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/resources/python/mix_pyspark.py b/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/resources/python/mix_pyspark.py
index c7093c4d8..7f83ab78a 100644
--- a/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/resources/python/mix_pyspark.py
+++ b/linkis-engineconn-plugins/engineconn-plugins/spark/src/main/resources/python/mix_pyspark.py
@@ -16,8 +16,6 @@
import sys, getopt, traceback, json, re
import os
os.environ['PYSPARK_ALLOW_INSECURE_GATEWAY']='1'
-import matplotlib
-matplotlib.use('Agg')
zipPaths = sys.argv[4]
paths = zipPaths.split(':')
for i in range(len(paths)):
@@ -44,6 +42,13 @@ except ImportError:
import time
import threading
+try:
+ import matplotlib
+ matplotlib.use('Agg')
+except Exception as e:
+ print("Failed to import matplotlib")
+ print(e)
+
# for back compatibility
from pyspark.sql import SQLContext, HiveContext, Row
@@ -149,9 +154,20 @@ def showAlias(obj,alias):
else:
print((str(obj)))
-def show_matplotlib(p, fmt="png", width="auto", height="auto", **kwargs):
+def show_matplotlib(p=None, fmt="png", width="auto", height="auto", **kwargs):
"""Matplotlib show function
"""
+ if p==None:
+ try:
+ import matplotlib
+ matplotlib.use('Agg')
+ import matplotlib.pyplot
+ p=matplotlib.pyplot
+ except Exception as e:
+ print("Failed to import matplotlib")
+ print(e)
+ return
+
if fmt == "png":
img = BytesIO()
p.savefig(img, format=fmt)
@@ -227,6 +243,22 @@ watchdog_thread = threading.Thread(target=java_watchdog_thread)
watchdog_thread.setDaemon(True)
watchdog_thread.start()
+
+def setup_plt_show():
+ """Override plt.show to show_matplotlib method
+ """
+ try:
+ import matplotlib
+ matplotlib.use('Agg')
+ import matplotlib.pyplot
+ matplotlib.pyplot.show=show_matplotlib
+ except Exception as e:
+ print(e)
+ return
+
+setup_plt_show()
+
+
while True :
req = intp.getStatements()
try:
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org