VS 2017 @ Windows 10 x64 (ASUS X450J)
In order to draw such a simple graph, it is necessary to call at least four of the PLplot functions:
plinit
, to initialize PLplot.plenv
, to define the range and scale of the graph, and draw labels, axes, etc.- One or more calls to
plline
orplstring
to draw lines or points as needed. Other more complex routines includeplbin
andplhist
to draw histograms, andplerrx
andplerry
to draw error-bars. plend
, to close the plot.
1-1 New console project
1-2 nuget add plplot (5.13.4 latest 5.13.7)
1-3 using PLplot;
1-4 example 0x1
1-5 error
System.BadImageFormatException: '試圖載入格式錯誤的程式。 (發生例外狀況於 HRESULT: 0x8007000B)'
1-6 Any cpu 改成 x64
double[] x = new double[10], y = new double[10];
for (int i=0; i<10; i++)
{
x[i] = (double)i;
y[i] = Math.Pow(x[i], 2);
}
var pl = new PLStream();
pl.sdev("pngcairo");
pl.sfnam("pngex1.png");
pl.spal0("cmap0_alternate.pal");
pl.init();
pl.env(0, 10, 0, 100, AxesScale.Independent, AxisBox.BoxTicksLabelsAxes);
pl.schr(0, 1.25);
pl.lab("X-axis", "Y-axis", "Title");
pl.col0(9);
pl.line(x, y);
pl.col0(3);
pl.sym(x, y, '0');
pl.eop();
pl.gver(out var verText);
//Console.ReadLine();
Console.WriteLine("Showing chart...");
var p = new Process();
string chartFileNamePath = @".\" + "pngex1.png";
p.StartInfo = new ProcessStartInfo(chartFileNamePath)
{
UseShellExecute = true
};
p.Start();
// Console.ReadLine();
1-7 Console mode 程式需結束,否則會有一個大的黑色方塊在中下方。
沒有留言:
張貼留言