commandをいちいち覚えてはいないものの,gnuplotの精義とかいう本を買ったところ大抵のことはこの本に載っています.
ところでgnuplotは1月にバージョン5.0がでていて,これにはヒアドキュメントとかいう超便利な機能がついてます.
これを使うと,あんまりgnuplotに詳しくない僕のような人間でも,簡単なグラフが簡単にかけてしまいます.
(なおC/C++erの方々にはImportとかいう便利機能もあるみたいですが,これは使い方を勉強する気がおきませんでした…)
解説はグーグルさんに任せるとして,これがC#などからgnuplotを使うのに非常に便利であることを書いておきます.
► スポイラーを表示
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace GnuplotLib
{
using XY = Tuple;
using XYZ = Tuple;
public class Gnuplot
{
#region enum
public enum Position
{
left,
right,
top,
bottom,
outside,
below,
unset,
off
}
public enum PlotMode
{
Plot,
Replot
}
#endregion
#region Internal
private static string gnuplotExeFilePath = "gnuplot";
private System.Diagnostics.Process GnuConsole
{
get;
set;
}
private bool Started = false;
#endregion
#region Property
public bool SetXaxisLogScale = false;
public bool SetYaxisLogScale = false;
public string GraphTitle = "";
public string XaxisLabel = "";
public string YaxisLabel = "";
public string ZaxisLabel = "";
public Position KeyPosition = Position.unset;
#endregion
#region Public Method
public Gnuplot(
bool redirectStandardInput = true,
bool createNoWindow = true,
bool useShellExecute = false
)
{
GnuConsole = new System.Diagnostics.Process();
GnuConsole.StartInfo.Arguments = "-p";
GnuConsole.StartInfo.FileName = gnuplotExeFilePath;
GnuConsole.StartInfo.CreateNoWindow = createNoWindow;
GnuConsole.StartInfo.UseShellExecute = useShellExecute;
GnuConsole.StartInfo.RedirectStandardInput = redirectStandardInput;
}
public void PlotXY(
string title,
List list,
string style
)
{
string command = "replot";
if (!Started)
{
Start();
command = "plot";
}
else
{
WritePreCommandsForGnuConsole();
}
string name = Math.Abs(title.GetHashCode()).ToString();
name = ReplaceNumber(name);
GnuConsole.StandardInput.WriteLine("$" + name + " list,
string style
)
{
string command = "replot";
if (!Started)
{
Start();
command = "splot";
}
else
{
WritePreCommandsForGnuConsole();
}
string name = Math.Abs(title.GetHashCode()).ToString();
name = ReplaceNumber(name);
GnuConsole.StandardInput.WriteLine("$" + name + " ();
/* listに数字を代入*/
var gnuplot = new GnuplotLib.Gnuplot();
gnuplot.XaxisLabel = "Speed(m/s)";
gnuplot.YaxisLabel = "RollAngle(°)";
gnuplot.PlotXY("V-ViecleRollAngle", list, "lines");
こんなグラフとか
[album]951[/album]
こんなグラフが書けます.
[album]950[/album]
バージョン5.0に対応した本でないかなぁ・・・