- 积分
- 1905
- 明经币
- 个
- 注册时间
- 2022-4-4
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 枫叶棋语 于 2023-4-11 19:49 编辑
import sys
import clr
from System.Collections.Generic import List
sys.path.append(r'D:\Program Files\Python38')
sys.path.append(r'D:\Program Files\Python38\Lib\site-packages')
sys.path.append(r'D:\Program Files\Python38\Lib\site-packages\pythonnet\runtime')
clr.AddReference('Python.Runtime')
from Python.Runtime import *
import Python.Runtime as pyr
import os
os.environ["PYTHONHOME"] = r'D:\Program Files\Python38'
os.environ["PYTHONNET_PYDLL"]=r'D:\Program Files\Python38\python38.dll'
os.environ['PYTHONPATH'] = r'D:\Program Files\Python38\Lib' + ';' +r'D:\Program Files\Python38\Lib\site-packages'
if not PythonEngine.IsInitialized:
PythonEngine.Initialize()
pyb=Py.Import("builtins") #导入Cpython基本库
np = Py.Import("numpy")#导入numpy
cv = Py.Import("cv2")#导入opencv
plt=Py.Import("matplotlib.pyplot")#导入matplotlib
x= np.array(pyb.list([1,2,3,4,5]))
y=np.array(pyb.list([2,4,1,3,5]))
plt.plot(x,y)
plt.title('折线图示例')
plt.xlabel('x 轴')
plt.ylabel('y 轴')
plt.show()
# Python 2.7可以这样使用
# pyb= PythonEngine.ImportModule("__builtin__")
# np= PythonEngine.ImportModule("numpy")
|
评分
-
查看全部评分
|