jython将matplotlib.pyplot导入为plt syntaxerror:(“在输入‘called’处没有可行的替代方法)

inb24sb2  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(329)

我想用jython调用一个python文件,这里有代码

package jpythonTest;

import org.python.core.PySystemState;
import org.python.util.PythonInterpreter;

public class te {

    public static void main(String[] args) {
        // TODO Auto-generated method stub  
        PythonInterpreter pi = new PythonInterpreter();
        PySystemState sys = pi.getSystemState();
        sys.path.add("H:\\anaconda\\Lib\\site-packages");   
        System.out.println(sys.path.toString());
        pi.execfile("src/main/java/jpythonTest/jython.py");
        pi.cleanup();
        pi.close();
        sys.close();    
    }
}

我使用jython standalone并将我的水蟒路径添加到其中。然后它会导致错误

Exception in thread "main" Traceback (most recent call last):
  File "src/main/java/jpythonTest/jython.py", line 2, in <module>
    import matplotlib.pyplot as plt
SyntaxError: ("no viable alternative at input 'called'", ('H:\\anaconda\\Lib\\site-packages\\matplotlib\\__init__.py', 237, 17, '        nonlocal called, ret\n'))

python文件


# -*- coding: utf-8 -*

import matplotlib.pyplot as plt
import pandas as pd
data = pd.read_csv(r'H:\desktop\workspace\src\main\java\distribute\1.txt',header=None)
data.columns=["date","av","price"]
data["price"]=data["price"].str.replace("$","");
data['price']=data['price'].fillna(0)
data['price']=pd.to_numeric(data['price'])
data["av"]=data["av"].str.replace("f","1");
data["av"]=data["av"].str.replace("t","0");
data['av']=pd.to_numeric(data['av'])
data_1=data[data['av']==1]
data_2=data[data['av']==0]
p1= plt.scatter(x=data_1["date"],y=data_1["price"],c='red')
p2= plt.scatter(x=data_2["date"],y=data_2["price"],c='blue')
plt.legend(handles=[p1,p2],labels = ['not_av','av'])
plt.xlabel("date")
plt.ylabel("price:$")
plt.show()

这个错误的原因是什么?如何解决?请帮助我!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题