源文件

  1. #!/usr/bin/env python
  2.  
  3. from os import popen
  4.  
  5. class gnuplot_leon:
  6. # Author : Leon Email: yangli0534@gmail.com
  7. # a gnuplot api of python
  8.  
  9. def __init__(self):
  10. self.gnuplot = popen('gnuplot','w')
  11. self.write = self.gnuplot.write
  12. self.flush = self.gnuplot.flush
  13. self.close = self.gnuplot.close
  14. #return gp
  15.  
  16. def set_plot_size(self,x=0.85,y=0.85):
  17. self.write(''.join(['set size ',str(x),' ,',str(y),'\n']))
  18. #self.write(''.join(['set term png size ',str(x),' ',str(y),'\n']))
  19. #self.flush()
  20.  
  21. def set_canvas_size(self,x=600,y=400):
  22. #self.write('set size 0.85, 0.85\n')
  23. self.write(''.join(['set term png size ',str(x),' ',str(y),'\n']))
  24.  
  25. def set_title(self,title='gnuplot'):
  26. self.write(''.join(['set title "{/Times:Italic ',str(title), '}"\n']))
  27. self.write('set title font ",10" norotate tc rgb "white"\n')
  28.  
  29. def set_gif(self):
  30. self.write('set terminal gif animate\n')
  31.  
  32. def set_png(self):
  33. self.write('set terminal png\n')
  34.  
  35. def set_file_name(self,filename='gnuplot.gif'):
  36. self.write(''.join(['set output ', '"',str(filename) ,'"','\n']))
  37.  
  38. def set_tics_color(self,color='orange'):
  39. self.write(''.join(['set tics textcolor rgb ','"',str(color),'"','\n']))
  40.  
  41. def set_border_color(self,color='orange'):
  42. self.write(''.join(['set border lc rgb ','"',str(color),'"','\n']))
  43.  
  44. def set_grid_color(self,color='orange'):
  45. self.write(''.join(['set grid lc rgb ','"',str(color),'"','\n']))
  46.  
  47. def set_bkgr_color(self,color='orange'):
  48. self.write(''.join(['set object 1 rectangle from screen 0,0 to screen 1,1 fc rgb ','"',str(color),'"',' behind\n']))
  49.  
  50. def set_xlabel(self,text='x',color='white'):
  51. self.write(''.join(['set xlabel " {/Times:Italic distance: ', str(text) ,' } " tc rgb ','"',str(color),'"',' \n']))
  52.  
  53. def set_ylabel(self,text='x',color='white'):
  54. self.write(''.join(['set ylabel " {/Times:Italic distance: ', str(text) ,' } " tc rgb ','"',str(color),'"',' \n']))
  55.  
  56. def auto_scale_enable(self):
  57. self.write('set autoscale\n')
  58.  
  59. def set_key(self,onoff='off ',text='gnuplot',color='white'):
  60. self.write('unset key\n')
  61. self.write(''.join(['set key ',str(onoff),' title "',str(text),'" textcolor rgbcolor "',str(color),'"\n']))
  62. #self.write('show key\n')
  63.  
  64. def set_x_range(self,start,end):
  65. self.write(''.join(['set xrange [ ',str(start),':',str(end),']\n']))
  66.  
  67. def set_y_range(self,start,end):
  68. self.write(''.join(['set yrange [ ',str(start),':',str(end),']\n']))
  69.  
  70. def set_frame_start(self,linestype = 'l',linewidth=3,l_color='green,'):
  71. #self.write('plot "-" w l lw 1.5 lc rgb "green"\n')
  72. self.write(''.join(['plot "-" notitle w ',str(linestype),' lw ', str(linewidth), ' lc rgb ', '"', str(l_color),'" \n']))
  73.  
  74. def update_point(self,x,y):
  75. self.write(''.join([str(x),' ',str(y),'\n']))
  76.  
  77. def set_frame_end(self):
  78. self.write('e\n')
  79.  
  80. def set_output_valid(self):
  81. self.write('set output\n')
  82.  
  83. def close(self):
  84. self.close()

例'1

  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. import math
  5. import os
  6. from gnuplot_leon import *
  7.  
  8. # Author : Leon Email: yangli0534@gmail.com
  9. # fdtd simulation , plotting with gnuplot, writting in python
  10. # perl and gnuplot software packages should be installed before running this program
  11. # 1d fdtd with absorbing boundary and TFSF boundary between [49] and [50]
  12. # lossy dielectric material localted at > ez[150]
  13.  
  14. gp = gnuplot_leon()
  15.  
  16. gp.set_plot_size(1,1)
  17. gp.set_canvas_size(600,800)
  18. gp.set_title('fdtd simulation by leon : gnuplot class test')
  19. title = 'fdtd simulation by leon,yangli0534\\\\@gmail.com'
  20. #gp.write('set terminal gif animate\n')
  21. gp.set_title(title)
  22. #gp.set_gif()
  23. gp.set_png()
  24. gp.set_file_name('demo1.png')
  25. gp.set_tics_color('white')
  26. gp.set_border_color('orange')
  27. gp.set_grid_color('orange')
  28. gp.set_bkgr_color('gray10')
  29. gp.set_xlabel('length','white')
  30. gp.set_ylabel('amplitude','white')
  31. gp.auto_scale_enable()
  32. gp.set_key('off','sin(x)','white')
  33.  
  34. size = 400#physical distance
  35.  
  36. sinwave=size * [0.00]#
  37.  
  38. cnt = 0
  39. elem = 0.00000
  40. pi = 3.14159265358979323846
  41. #gp.write(''.join(['set xrange [0:',str(size),'-1]\n']));
  42. gp.set_x_range(0,size-1)
  43. #for i in range(0,size):
  44. # sinwave[i] = 0.0
  45.  
  46. for mm in range(0, size-1):
  47. sinwave[mm] = math.sin(2*pi*mm/size)
  48.  
  49. gp.set_frame_start('l', 3, 'green')
  50. cnt = 0
  51. for elem in sinwave:
  52. gp.update_point(cnt,elem)
  53. #print ''.join([str(cnt),':',str(elem),'\n'])
  54. cnt += 1
  55. gp.set_frame_end()
  56. gp.set_key('off','sin(x)','white')
  57. gp.set_output_valid()
  58. gp.close()

例2

  1. #!/usr/bin/env python
  2.  
  3. import sys
  4. import math
  5. import os
  6. from gnuplot_leon import *
  7.  
  8. # Author : Leon Email: yangli0534@gmail.com
  9. # fdtd simulation , plotting with gnuplot, writting in python
  10. # perl and gnuplot software packages should be installed before running this program
  11. # 1d fdtd with absorbing boundary and TFSF boundary between [49] and [50]
  12. # lossy dielectric material localted at > ez[150]
  13.  
  14. gp = gnuplot_leon()
  15.  
  16. gp.set_plot_size(0.85,0.85)
  17. gp.set_canvas_size(600,400)
  18. #gp.set_title('fdtd simulation by leon : gnuplot class test')
  19. title = 'fdtd simulation by leon,yangli0534\\\\@gmail.com'
  20.  
  21. gp.set_title(title)
  22. gp.set_gif()
  23. #gp.set_png()
  24. gp.set_file_name('demo2.gif')
  25. gp.set_tics_color('white')
  26. gp.set_border_color('orange')
  27. gp.set_grid_color('orange')
  28. gp.set_bkgr_color('gray10')
  29. gp.set_xlabel('length','white')
  30. gp.set_ylabel('amplitude','white')
  31. gp.auto_scale_enable()
  32. gp.set_key('off','sin(x)','white')
  33.  
  34. size = 400#physical distance
  35. ez=size * [0.00]#electric field
  36. hy=size * [0.00]#magnetic field
  37. ceze=size * [0.00]#
  38. cezh=size * [0.00]#
  39. chye=size * [0.00]#
  40. chyh=size * [0.00]#
  41. #sinwave=size * [0.00]#
  42. imp0 = 377.00
  43. LOSS = 0.01
  44. LOSS_LAYER = 250
  45. MaxTime = 18000
  46. cnt = 0
  47. elem = 0.00000
  48.  
  49. gp.set_x_range(0,size-1)
  50. for i in range(0,size):
  51. ez[i] = 0.0
  52. hy[i] = 0.0
  53. #sinwave[i] = 0.0
  54. if (i < 100):
  55. #$epsR[$i] = 1.0;
  56. ceze[i] = 1.0
  57. cezh[i] = imp0
  58. elif(i < LOSS_LAYER):
  59. #$epsR[$i] = 1.0;
  60. ceze[i] = 1.0
  61. cezh[i] = imp0/9.0
  62. else :
  63. #$epsR[$i] = 9.0;
  64. ceze[i] = (1.0-LOSS)/(1.0+LOSS)
  65. cezh[i] = imp0 / 9 /(1.0+LOSS)
  66. if( i < LOSS_LAYER):
  67. chye[i] = 1.0/imp0
  68. chyh[i] = 1.0
  69. else:
  70. chye[i] = 1.0/imp0/(1.0+LOSS)
  71. chyh[i] = (1.0-LOSS)/(1.0+LOSS)
  72. for qTime in range(0, MaxTime):
  73. # update magnetic field
  74. for mm in range(0, size-1):
  75. hy[mm] = hy[mm]*chyh[mm] + (ez[mm+1]-ez[mm])*chye[mm]
  76. #sinwave[mm] = math.sin(mm/size*2*pi)
  77. hy[49] = hy[49]-math.exp(-(qTime - 30.0)*(qTime - 30.0)/100.0)/imp0
  78. # update electric field
  79. ez[0] = ez[1]#abc
  80. #$ez[$size-1] = $ez[$size-2];
  81. for mm in range(1, size-1):
  82. ez[mm] = ez[mm]*ceze[mm] + (hy[mm] - hy[mm-1])*cezh[mm]
  83. if(qTime % 30 == 0):
  84. gp.set_frame_start('l', 3, 'green')
  85. cnt = 0
  86. for elem in ez:
  87. gp.update_point(cnt,elem)
  88. cnt += 1
  89. gp.set_frame_end()
  90. ez[50] = ez[50]+math.exp(-(qTime +0.5-(-0.5)- 30.0)*(qTime +0.5-(-0.5)- 30.0)/100.0);
  91. #gp.write('set output\n')
  92. #gp.close()
  93. gp.set_output_valid()
  94. 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. 重新想象 Windows 8 Store Apps (49) - 输入: 获取输入设备信息, 虚拟键盘, Tab 导航, Pointer, Tap, Drag, Drop

    [源码下载] 重新想象 Windows 8 Store Apps (49) - 输入: 获取输入设备信息, 虚拟键盘, Tab 导航, Pointer, Tap, Drag, Drop 作者:weba ...

  2. javascript:Bing Maps AJAX Control, Version 7.0

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. java int转byte和long转byte

    在网络编程中,出于节约带宽或者编码的需要,通常需要以原生方式处理long和int,而不是转换为string. public class ByteOrderUtils { public static b ...

  4. 三、动态SQL语句

    //备注:该博客引自:http://limingnihao.iteye.com/blog/106076 有些时候,sql语句where条件中,需要一些安全判断,例如按某一条件查询时如果传入的参数是空, ...

  5. Jquery_Ajax GET方式传递文本

    第一个网页: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. ...

  6. PHP学习笔记:使用session来存储用户的登录信息

    session可以用来存储多种类型的数据,因此具有很多的用途,常用来存储用户的登录信息,购物车数据,或者一些临时使用的暂存数据等. 用户在登录成功以后,通常可以将用户的信息存储在session中,一般 ...

  7. GDB调试器使用总结

    概述:GDB是linux下调试程序的神器,做为linux程序员,如果不能熟练的使用GDB进行程序调试,那将是很失败的事情.强大的功能使GDB的使用也变得比较复杂,如果是初学者肯定会比繁杂的命令吓到.下 ...

  8. sharepoint获取exchange邮箱报错:该帐户无权模拟所请求的用户

    现象: sharepoint获取exchange邮箱报错:该帐户无权模拟所请求的用户 处理办法: 1.Open the Exchange Management Shell 2.输入: New-Mana ...

  9. Searching External Data in SharePoint 2010 Using Business Connectivity Services

    from:http://blogs.msdn.com/b/ericwhite/archive/2010/04/28/searching-external-data-in-sharepoint-2010 ...

  10. 搭建Android 5.0开发环境

    1.Android SDK的安装 下载地址:http://developer.android.com/index.html 访问网站的话请自备梯子 选择:adt-bundle-windows-x86_ ...