源文件

 #!/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的更多相关文章

  1. Appium python API 总结

    Appium python api 根据testerhome的文章,再补充一些文章里面没有提及的API [TOC] [1]find element driver 的方法 注意:这几个方法只能通过sel ...

  2. The novaclient Python API

    The novaclient Python API Usage First create a client instance with your credentials: >>> f ...

  3. Openstack python api 学习文档 api创建虚拟机

    Openstack python api 学习文档 转载请注明http://www.cnblogs.com/juandx/p/4953191.html 因为需要学习使用api接口调用openstack ...

  4. BotVS开发基础—Python API

    代码 import json def main(): # python API列表 https://www.botvs.com/bbs-topic/443 #状态信息 LogStatus(" ...

  5. 《Spark Python API 官方文档中文版》 之 pyspark.sql (一)

    摘要:在Spark开发中,由于需要用Python实现,发现API与Scala的略有不同,而Python API的中文资料相对很少.每次去查英文版API的说明相对比较慢,还是中文版比较容易get到所需, ...

  6. 《Spark Python API 官方文档中文版》 之 pyspark.sql (二)

    摘要:在Spark开发中,由于需要用Python实现,发现API与Scala的略有不同,而Python API的中文资料相对很少.每次去查英文版API的说明相对比较慢,还是中文版比较容易get到所需, ...

  7. HBase Python API

    HBase Python API HBase通过thrift机制可以实现多语言编程,信息通过端口传递,因此Python是个不错的选择 吐槽 博主在Mac上配置HBase,奈何Zoomkeeper一直报 ...

  8. 二、Blender/Python API总览

    原文:https://docs.blender.org/api/blender_python_api_current/info_overview.html Python in Blender  Ble ...

  9. Appium+python自动化8-Appium Python API

    Appium+python自动化8-AppiumPython API   前言: Appium Python API全集,不知道哪个大神整理的,这里贴出来分享给大家. 1.contexts conte ...

随机推荐

  1. 基于FreeBSD 64位内核的kFreeBSD无法在Virtualbox下安装

    ArchBSD同上 感谢大A(豆瓣)的投稿 :)

  2. [PE结构分析] 11.资源表结构

    资源表是一个树形结构,可以设置成2的31次方的层数,Windows 使用了3级: 类型->名称->语言 其中涉及到四个结构: Data Description Resource Direc ...

  3. window下安装redis

    以cmd安装方法: .下载安装包:https://github.com/dmajkic/redis/downloads .安装包下载后根据操作系统选择对应版本文件,里面会有几个dll分别为: redi ...

  4. oGrid 初探

    oGrid 是个还蛮有趣的 pure JavaScript grid 控件 code 并不多而且是纯 JavaScript 写成,一条小龙觉得还算蛮好理解,不像其他几乎都是用 Jquery 为 bas ...

  5. ng-show

    //当ng-show="false"时,自动添加 #animate.ng-hide { } #animate.ng-hide-add { } #animate.ng-hide-ad ...

  6. 使用NPOI将多张图片导入execl

    protected void btn_Export_Click(object sender, EventArgs e) { List<BNXX_SJXJ_XJSJ> list = View ...

  7. 2015年第8本(英文第7本):the city of ember 微光城市

    书名:the City of Ember(中文名:微光城市) 作者:Jeanne DuPrau 单词数:6.2万 不重复单词数:未知 首万词不重复单词数:未知 蓝思值:未知 阅读时间:2015年4月2 ...

  8. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q81-Q84)

    Question 81You need to create a Web Part that creates a copy of the out-of-the-box Contribute permis ...

  9. Java 中Comparator 的使用,实现集合排序

    目标:实现对Person 对象的年龄,从小到大排序 1.实现排序 package com.app; import java.util.ArrayList; import java.util.Colle ...

  10. 浅析LruCache原理

    Android用LruCache来取代原来强引用和软引用实现内存缓存,因为据说自2.3以后Android将更频繁的调用GC,导致软引用缓存的数据极易被释放. LruCache使用一个LinkedHas ...