gnuplot Python API
源文件
#!/usr/bin/env python from os import popen class gnuplot_leon:
# Author : Leon Email: yangli0534@gmail.com
# a gnuplot api of python def __init__(self):
self.gnuplot = popen('gnuplot','w')
self.write = self.gnuplot.write
self.flush = self.gnuplot.flush
self.close = self.gnuplot.close
#return gp def set_plot_size(self,x=0.85,y=0.85):
self.write(''.join(['set size ',str(x),' ,',str(y),'\n']))
#self.write(''.join(['set term png size ',str(x),' ',str(y),'\n']))
#self.flush() def set_canvas_size(self,x=600,y=400):
#self.write('set size 0.85, 0.85\n')
self.write(''.join(['set term png size ',str(x),' ',str(y),'\n'])) def set_title(self,title='gnuplot'):
self.write(''.join(['set title "{/Times:Italic ',str(title), '}"\n']))
self.write('set title font ",10" norotate tc rgb "white"\n') def set_gif(self):
self.write('set terminal gif animate\n') def set_png(self):
self.write('set terminal png\n') def set_file_name(self,filename='gnuplot.gif'):
self.write(''.join(['set output ', '"',str(filename) ,'"','\n'])) def set_tics_color(self,color='orange'):
self.write(''.join(['set tics textcolor rgb ','"',str(color),'"','\n'])) def set_border_color(self,color='orange'):
self.write(''.join(['set border lc rgb ','"',str(color),'"','\n'])) def set_grid_color(self,color='orange'):
self.write(''.join(['set grid lc rgb ','"',str(color),'"','\n'])) def set_bkgr_color(self,color='orange'):
self.write(''.join(['set object 1 rectangle from screen 0,0 to screen 1,1 fc rgb ','"',str(color),'"',' behind\n'])) def set_xlabel(self,text='x',color='white'):
self.write(''.join(['set xlabel " {/Times:Italic distance: ', str(text) ,' } " tc rgb ','"',str(color),'"',' \n'])) def set_ylabel(self,text='x',color='white'):
self.write(''.join(['set ylabel " {/Times:Italic distance: ', str(text) ,' } " tc rgb ','"',str(color),'"',' \n'])) def auto_scale_enable(self):
self.write('set autoscale\n') def set_key(self,onoff='off ',text='gnuplot',color='white'):
self.write('unset key\n')
self.write(''.join(['set key ',str(onoff),' title "',str(text),'" textcolor rgbcolor "',str(color),'"\n']))
#self.write('show key\n') def set_x_range(self,start,end):
self.write(''.join(['set xrange [ ',str(start),':',str(end),']\n'])) def set_y_range(self,start,end):
self.write(''.join(['set yrange [ ',str(start),':',str(end),']\n'])) def set_frame_start(self,linestype = 'l',linewidth=3,l_color='green,'):
#self.write('plot "-" w l lw 1.5 lc rgb "green"\n')
self.write(''.join(['plot "-" notitle w ',str(linestype),' lw ', str(linewidth), ' lc rgb ', '"', str(l_color),'" \n'])) def update_point(self,x,y):
self.write(''.join([str(x),' ',str(y),'\n'])) def set_frame_end(self):
self.write('e\n') def set_output_valid(self):
self.write('set output\n') def close(self):
self.close()
例'1
#!/usr/bin/env python import sys
import math
import os
from gnuplot_leon import * # Author : Leon Email: yangli0534@gmail.com
# fdtd simulation , plotting with gnuplot, writting in python
# perl and gnuplot software packages should be installed before running this program
# 1d fdtd with absorbing boundary and TFSF boundary between [49] and [50]
# lossy dielectric material localted at > ez[150] gp = gnuplot_leon() gp.set_plot_size(1,1)
gp.set_canvas_size(600,800)
gp.set_title('fdtd simulation by leon : gnuplot class test')
title = 'fdtd simulation by leon,yangli0534\\\\@gmail.com'
#gp.write('set terminal gif animate\n')
gp.set_title(title)
#gp.set_gif()
gp.set_png()
gp.set_file_name('demo1.png')
gp.set_tics_color('white')
gp.set_border_color('orange')
gp.set_grid_color('orange')
gp.set_bkgr_color('gray10')
gp.set_xlabel('length','white')
gp.set_ylabel('amplitude','white')
gp.auto_scale_enable()
gp.set_key('off','sin(x)','white') size = 400#physical distance sinwave=size * [0.00]# cnt = 0
elem = 0.00000
pi = 3.14159265358979323846
#gp.write(''.join(['set xrange [0:',str(size),'-1]\n']));
gp.set_x_range(0,size-1)
#for i in range(0,size):
# sinwave[i] = 0.0 for mm in range(0, size-1):
sinwave[mm] = math.sin(2*pi*mm/size) gp.set_frame_start('l', 3, 'green')
cnt = 0
for elem in sinwave:
gp.update_point(cnt,elem)
#print ''.join([str(cnt),':',str(elem),'\n'])
cnt += 1
gp.set_frame_end()
gp.set_key('off','sin(x)','white')
gp.set_output_valid()
gp.close()
例2
#!/usr/bin/env python import sys
import math
import os
from gnuplot_leon import * # Author : Leon Email: yangli0534@gmail.com
# fdtd simulation , plotting with gnuplot, writting in python
# perl and gnuplot software packages should be installed before running this program
# 1d fdtd with absorbing boundary and TFSF boundary between [49] and [50]
# lossy dielectric material localted at > ez[150] gp = gnuplot_leon() gp.set_plot_size(0.85,0.85)
gp.set_canvas_size(600,400)
#gp.set_title('fdtd simulation by leon : gnuplot class test')
title = 'fdtd simulation by leon,yangli0534\\\\@gmail.com' gp.set_title(title)
gp.set_gif()
#gp.set_png()
gp.set_file_name('demo2.gif')
gp.set_tics_color('white')
gp.set_border_color('orange')
gp.set_grid_color('orange')
gp.set_bkgr_color('gray10')
gp.set_xlabel('length','white')
gp.set_ylabel('amplitude','white')
gp.auto_scale_enable()
gp.set_key('off','sin(x)','white') size = 400#physical distance
ez=size * [0.00]#electric field
hy=size * [0.00]#magnetic field
ceze=size * [0.00]#
cezh=size * [0.00]#
chye=size * [0.00]#
chyh=size * [0.00]#
#sinwave=size * [0.00]#
imp0 = 377.00
LOSS = 0.01
LOSS_LAYER = 250
MaxTime = 18000
cnt = 0
elem = 0.00000 gp.set_x_range(0,size-1)
for i in range(0,size):
ez[i] = 0.0
hy[i] = 0.0
#sinwave[i] = 0.0
if (i < 100):
#$epsR[$i] = 1.0;
ceze[i] = 1.0
cezh[i] = imp0
elif(i < LOSS_LAYER):
#$epsR[$i] = 1.0;
ceze[i] = 1.0
cezh[i] = imp0/9.0
else :
#$epsR[$i] = 9.0;
ceze[i] = (1.0-LOSS)/(1.0+LOSS)
cezh[i] = imp0 / 9 /(1.0+LOSS)
if( i < LOSS_LAYER):
chye[i] = 1.0/imp0
chyh[i] = 1.0
else:
chye[i] = 1.0/imp0/(1.0+LOSS)
chyh[i] = (1.0-LOSS)/(1.0+LOSS)
for qTime in range(0, MaxTime):
# update magnetic field
for mm in range(0, size-1):
hy[mm] = hy[mm]*chyh[mm] + (ez[mm+1]-ez[mm])*chye[mm]
#sinwave[mm] = math.sin(mm/size*2*pi)
hy[49] = hy[49]-math.exp(-(qTime - 30.0)*(qTime - 30.0)/100.0)/imp0
# update electric field
ez[0] = ez[1]#abc
#$ez[$size-1] = $ez[$size-2];
for mm in range(1, size-1):
ez[mm] = ez[mm]*ceze[mm] + (hy[mm] - hy[mm-1])*cezh[mm]
if(qTime % 30 == 0):
gp.set_frame_start('l', 3, 'green')
cnt = 0
for elem in ez:
gp.update_point(cnt,elem)
cnt += 1
gp.set_frame_end()
ez[50] = ez[50]+math.exp(-(qTime +0.5-(-0.5)- 30.0)*(qTime +0.5-(-0.5)- 30.0)/100.0);
#gp.write('set output\n')
#gp.close()
gp.set_output_valid()
gp.close()
gnuplot Python API的更多相关文章
- Appium python API 总结
Appium python api 根据testerhome的文章,再补充一些文章里面没有提及的API [TOC] [1]find element driver 的方法 注意:这几个方法只能通过sel ...
- The novaclient Python API
The novaclient Python API Usage First create a client instance with your credentials: >>> f ...
- Openstack python api 学习文档 api创建虚拟机
Openstack python api 学习文档 转载请注明http://www.cnblogs.com/juandx/p/4953191.html 因为需要学习使用api接口调用openstack ...
- BotVS开发基础—Python API
代码 import json def main(): # python API列表 https://www.botvs.com/bbs-topic/443 #状态信息 LogStatus(" ...
- 《Spark Python API 官方文档中文版》 之 pyspark.sql (一)
摘要:在Spark开发中,由于需要用Python实现,发现API与Scala的略有不同,而Python API的中文资料相对很少.每次去查英文版API的说明相对比较慢,还是中文版比较容易get到所需, ...
- 《Spark Python API 官方文档中文版》 之 pyspark.sql (二)
摘要:在Spark开发中,由于需要用Python实现,发现API与Scala的略有不同,而Python API的中文资料相对很少.每次去查英文版API的说明相对比较慢,还是中文版比较容易get到所需, ...
- HBase Python API
HBase Python API HBase通过thrift机制可以实现多语言编程,信息通过端口传递,因此Python是个不错的选择 吐槽 博主在Mac上配置HBase,奈何Zoomkeeper一直报 ...
- 二、Blender/Python API总览
原文:https://docs.blender.org/api/blender_python_api_current/info_overview.html Python in Blender Ble ...
- Appium+python自动化8-Appium Python API
Appium+python自动化8-AppiumPython API 前言: Appium Python API全集,不知道哪个大神整理的,这里贴出来分享给大家. 1.contexts conte ...
随机推荐
- SqlServer常用语句参考
1.SQL SERVER中如何使用SQL 语句复制表结构: select * into 新表 from 旧表 where 1=2 把“旧表”的表结构复制到“新表”,1=2不复制数据,如果要复制数据,就 ...
- jython 2.7 b3发布
Jython 2.7b3 Bugs Fixed - [ 2108 ] Cannot set attribute to instances of AST/PythonTree (blocks pyfla ...
- xshell下载文件到本地/上传文件到服务器
xshell很好用,然后有时候想在windows和linux上传或下载某个文件,其实有个很简单的方法就是rz,sz首先你的Ubuntu需要安装rz.sz(如果没有安装请执行以下命令,安装完的请跳过.其 ...
- Durandal介绍
Durandal是一个JS框架用于构建客户端single page application(SPAs).它支持MVC,MVP与MVVM前端构架模式.使用RequireJS做为其基本约定层,D ...
- mysql grant all on *.* to xxx@'%' 报Access denied for user 'root'@'localhost'
今日,开发反馈某台mysql服务器无法登陆,解决之后,远程登录后发现用户只能看到information_schema,其他均看不到. 故登录服务器执行: mysql> grant all on ...
- Erlang进程间消息接收超时设定
Erlang消息接收函数,一般都会设计成尾递归调用自己的模式.但是这样的模式,如果没有消息则会无限的等待下去,所以为了不无限等待,这里可以加个超时设定,例如: flush() -> re ...
- Error occurred in deployment step 'Add Solution': Operation is not valid due to the current state of the object.
Sharepoint 部署的时候出现一个错误 Error occurred in deployment step 'Add Solution': Operation is not valid due ...
- UWP开发-HTTP详解
HTTP作为一个基础功能,有必要介绍下在UWP下的使用方法. 一.Get请求: 一般我们用到的是GetAsync方法 public static async Task Gets(Uri uri) { ...
- Android中进程与线程
常说的主线程(UI线程)是什么? 当一个Android程序刚启动的时候,我们的android系统就会启动一个带有一个单一线程的linux进程.默认情况下,所有的组件比如Activity都运行在同样的一 ...
- iOS加载程序视图的方式
The UIViewController class provides built-in support for loading a view controller's views whenever ...