中国建设银行龙卡网站,带地板翻转的网站怎么做,兰州做网站或小程序,常州金坛建设局网站目录 基本介绍环境配置官方代码示例基础代码详解我的代码效果视频进阶代码及去水印 基本介绍 origin2021后可以使用python实现批量绘图#xff0c;一共有两种方式#xff1a;一种是嵌入式Python#xff0c;一种是外部Python访问Origin。详细介绍可以自己去查看#xff0c;打… 目录 基本介绍环境配置官方代码示例基础代码详解我的代码效果视频进阶代码及去水印 基本介绍 origin2021后可以使用python实现批量绘图一共有两种方式一种是嵌入式Python一种是外部Python访问Origin。详细介绍可以自己去查看打开origin-帮助-编程-python就可以打开网页 link查看。 这里主要介绍比较少人提及的外部Python访问Origin方式内部太麻烦了对于习惯使用pycharm的我来说。
环境配置
还是熟悉的Anaconda Prompt然后配置需要使用到的环境。首先先创建一个origin环境然后激活环境后进行pip安装。这里conda install会报错的 创建环境见我其他配置教程 【框架安装】win7 配置安装tensorflow和keras教程
pip install originpro然后就打开pycharm创建新项目设置环境。见我其他配置教程 【框架安装】win7 配置安装tensorflow和keras教程
官方代码示例
代码示例https://www.originlab.com/doc/en/ExternalPython/External-Python-Code-Samples 更多代码示例https://github.com/originlab/Python-Samples 官方函数指南https://docs.originlab.com/originpro/annotated.html
基础代码详解
这里部分代码有删减不可以直接运行可以参考下面步骤流程写自己的代码
part1 初始化
import os
import originpro as op
import numpy as np
import pandas as pd
# Very useful, especially during development, when you are liable to have a few uncaught exceptions.
# Ensures that the Origin instance gets shut down properly.
# Note: only applicable to external Python.
# 官网推荐加的不加白不加
import sys
def origin_shutdown_exception_hook(exctype, value, traceback):Ensures Origin gets shut down if an uncaught exceptionop.exit()sys.__excepthook__(exctype, value, traceback)
if op and op.oext:sys.excepthook origin_shutdown_exception_hookpart2 打开origin界面也可以不打开的但是打开可控一点
# Set Origin instance visibility.
# Important for only external Python.
# Should not be used with embedded Python.
# 这个命令可以打开一个origin界面
if op.oext:op.set_show(True)part3 读取数据并进行数据处理
# 可以实现设置一个origin模板这样可以减轻工作量
# 这里先设置好模板读取路径template_path以及图片保存路径save_img_path
# 可以看这个教程https://blog.originlab.com/origin-graph-templates-for-python-developers
working_folder os.path.dirname(os.path.realpath(__file__))
template_path os.path.join(working_folder,test111.otpu)
save_img_path working_folder
# 可以使用pandas 和numpy 处理数据
data pd.read_csv(csv_path, headerNone)
data np.array(data).flatten()part4 新建表格并将数据输入到表格
# Simple syntax to create a new workbook with one sheet
wks op.new_sheet(w,test)
# Insert list data into columns 1
# 这里0指的是第一列1指的是第二列data就是要输入进去的列向量np格式数据列名设置为。这里输入两列相同的数据
# 注意这个列名会显示到图上面的
wks.from_list(0, data, lname???)
wks.from_list(1, data, lname???)
part5 绘图
# Create a new graph object based on a graph template.
# Provide path to the template. Well use a built-in
gr op.new_graph(templatetemplate_path)# Add plots with data from worksheet to layer 1 and layer 2
# and then rescale.
# p1 就是绘制的第一条曲线
p1 gr[0].add_plot(wks, colyB, colxA)
# X is col A, Y is col B.
p1.color #335eff # 设置曲线颜色
# 可以到这个网站找合适的配色https://eng.m.fontke.com/tool/rgb/
# p2 就是绘制的第二条曲线
p2 gr[0].add_plot(wks, C, A)
# X is col A, Y is col C.
p2.color #ff5833
part6 保存图片
# 保存图片
fgr.save_fig(os.path.join(save_img_path,my_py_test.png))
# 打开刚刚保存的图片
if len(f):os.startfile(f)part7 退出origin
# Exit running instance of Origin.
if op.oext:op.exit()我的代码效果视频 进阶代码及去水印
见【OriginPython】使用External Python批量出图代码参考2