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 ...
随机推荐
- 【JS复习笔记】00 序
作为一个前端苦手,说是复习,你就当我是重学好了. 好吧,我当然不可能抱着一个砖头去复习,所以捡了本薄的来读——<JavaScript语言精粹>. 当初带我的人说这本书挺好,就看这本书好了. ...
- sql添加合计
在项目中发现有这样的写法 SELECT ZoneID,CountSQAZFZSBJZ3G+CountSQGZJRJZSL3G AS column1FROM G3MulticarrierSiteCove ...
- Linux Shell系列教程之(十七) Shell文件包含
本文是Linux Shell系列教程的第(十七)篇,更多Linux Shell教程请看:Linux Shell系列教程 通过文件包含,可以引用其他文件的内容,也可以将复杂内容分开,使程序结构更加清晰. ...
- 非线性数据拟合-nls
code{white-space: pre;} pre:not([class]) { background-color: white; }if (window.hljs && docu ...
- LINUX重启MYSQL的命令
LINUX重启MYSQL的命令 标签: mysqllinuxservice脚本web服务server 2010-06-25 10:21 62152人阅读 评论(0) 收藏 举报 分类: Linux( ...
- 一句命令快速合并 JS、CSS
在项目开发环境下,我们会把 JS 代码尽可能模块化,方便管理和修改,这就避免不了会出现一个项目自身 JS 文件数量达到 10 个或者更多. 而项目上线后,会要求将所有 JS 文件合并为 1 个或者几个 ...
- [js开源组件开发]图片懒加载lazyload
图片懒加载lazyload 前端对请求的一种优化方式,为什么叫懒加载,无从查起,反正我当初一直认为它是滚动加载的一种类型.它主要是以图片或背景在可视区域内时才显示真正的图片,减少src带来的负荷.所以 ...
- SharePoint Iframe 报错“此内容不能显示在一个框架中”<续>
在之前的SharePoint站点iframe引用中,我们遇到过下面的问题,就是其它系统或者不通环境的SharePoint站点,引用SharePoint页面会报错“此内容不能显示在一个框架中”,之前我们 ...
- android Android-PullToRefresh 下拉刷新
1.github下载地址 原作者: https://github.com/chrisbanes/Android-PullToRefresh 我自己的: https://github.com/zyj ...
- AsyncTask.cancel()的结束问题
实际项目中有这么一个问题,用户进入详情界面,那么我们就要网络加载数据并展现在UI上,这个加载用线程或者异步. 这里就拿项目中统一用异步任务来获取网络数据把. 用户可能会有这么一个操作,它在一个商品(说 ...