当前位置: 首页 > news >正文

c#用Gnuplot画图源码

直接调用这个类即可,需要下载个GnuPlot安装下。

// Author: Leonardo Tazziniusing System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;/// <summary>
/// Tested with Gnuplot 5.2
/// </summary>
public class GnuPlot
{public GnuPlot(){// Default path for gnuplotthis.Path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "gnuplot\\bin\\gnuplot.exe");// TODO: Check if path is valid}public GnuPlot(string path){this.Path = path;}/// <summary>/// Path of gnuplot.exe/// </summary>public string Path { get; set; }/// <summary>/// Graph input CSV with GnuPlot. NumWaves is the number of channels to draw. If imageOut a PNG image is saved into out.png and displayed. /// </summary>public void DrawGraph(string csvFileName, int numWaves, bool generatePngImage = true){// gnuplot.exe not foundif(!File.Exists(Path)){MessageBox.Show("gnuplot.exe not found. Please check the path.");return;}var gnuPlot = new Process();gnuPlot.StartInfo.FileName = Path;gnuPlot.StartInfo.CreateNoWindow = true;gnuPlot.StartInfo.UseShellExecute = false;gnuPlot.StartInfo.RedirectStandardInput = true;gnuPlot.Start();StreamWriter gnuPlotSw = gnuPlot.StandardInput;if (generatePngImage){// TODO: Remove dependency from Windows FormsRectangle bounds = Screen.PrimaryScreen.WorkingArea;gnuPlotSw.WriteLine("set terminal png size " + (bounds.Width * 0.9) + "," + (bounds.Height * 0.8));gnuPlotSw.WriteLine("set out 'out.png'");}gnuPlotSw.WriteLine("set style data lines");      //linespointsgnuPlotSw.WriteLine("set datafile separator ';'");//gnuPlotSw.WriteLine("set decimalsign locale; set decimalsign ','");gnuPlotSw.WriteLine("set xlabel 'time  (s)'");gnuPlotSw.WriteLine("set ylabel 'value (v)'");gnuPlotSw.WriteLine("set grid");//gnuPlotSw.WriteLine("set xtics 0,0.5");//gnuPlotSw.WriteLine("set ytics 0,5");// TODO: evaluate add "every .." to gnuplot cmd line    gnuPlotSw.Write("plot '" + System.IO.Path.GetFullPath(csvFileName) + "' using 1:2 title 'CH1'");if (numWaves == 2)gnuPlotSw.WriteLine(", '' using 1:3 title 'CH2'");elsegnuPlotSw.Write("\n");gnuPlotSw.Flush();if (generatePngImage){gnuPlotSw.WriteLine("exit");gnuPlotSw.Flush();gnuPlot.WaitForExit();Process.Start("out.png");}gnuPlot.Close();}}

读吧数据存为csv,传入DrawGraph即可;数据如下:

TIME(s);CH1(v);
-600.99999949;1.5001;
-599.99999949;-0.0598999999999998;
-598.99999949;-0.0398999999999998;
-597.99999949;-0.0398999999999998;
-596.99999949;-0.0398999999999998;
-595.99999949;-0.0398999999999998;
-594.99999949;-0.0398999999999998;
-593.99999949;-0.0398999999999998;
-592.99999949;-0.0598999999999998;
-591.99999949;-0.0398999999999998;
-590.99999949;-0.0398999999999998;
-589.99999949;-0.0598999999999998;
-588.99999949;-0.0398999999999998;
-587.99999949;-0.0398999999999998;
-586.99999949;-0.0398999999999998;
-585.99999949;-0.0598999999999998;

显示示意:

http://www.lryc.cn/news/171466.html

相关文章:

  • 【前端设计模式】之工厂模式
  • Hive 的函数介绍
  • 【Linux基础】第31讲 Linux用户和用户组权限控制命令(三)
  • html form表单高级用法
  • openssl升级
  • 【数据结构】图的遍历:广度优先(BFS),深度优先(DFS)
  • Mysql 学习总结(89)—— Mysql 库表容量统计
  • virtualBox安装配置使用
  • 北斗导航 | RTD、RTK完好性之B值、VPL与HPL计算(附B值计算matlab源代码)
  • more often than not 的含义
  • 【Linux】Linux环境配置安装
  • 从零学习开发一个RISC-V操作系统(二)丨GCC编译器和ELF格式
  • 论文阅读_大语言模型_Llama2
  • 当量因子法、InVEST、SolVES模型等多技术融合在生态系统服务功能社会价值评估中的应用及论文写作、拓展分析
  • k8s Limits 限制内存
  • 单片机第三季-第三课:STM32开发板原理图、配置、浮点运算单元
  • 观察者模式 发布-订阅模式(设计模式与开发实践 P8)
  • 【日常业务开发】Java实现异步编程
  • 学习笔记|模数转换器|ADC原理|STC32G单片机视频开发教程(冲哥)|第十七集:ADC采集
  • OpenCV实现“蓝线挑战“特效
  • 容器管理工具 Docker生态架构及部署
  • js判断数据类型的方法
  • 达梦数据库随系统开机自动启动脚本
  • Python开发利器之VS Code
  • 【Axure视频教程】输入框控制滑动评分条
  • 【学习笔记】[AGC064C] Erase and Divide Game
  • 算法通关村-----数组中元素出现次数问题
  • Qt-键盘消息的传递-键盘消息的获取-C++
  • 数据结构与算法(五)--链表概念以及向链表添加元素
  • 计算机视觉与深度学习-图像分割-视觉识别任务02-目标检测-【北邮鲁鹏】