使用mathematica在C#中绘图

使用mathematica在C#中绘图,c#,plot,wolfram-mathematica,C#,Plot,Wolfram Mathematica,请帮助我绘制从C#发送到mathematica内核的数据。 我想从C#中编写mathematica代码并绘制光谱数据。 我想我已经添加了必要的汇编和引用。我的C#代码如下 public void button2_Click(object sender, System.EventArgs e) { double baseline; int indexOfPeak; int minimumIndicesBetweenPeaks; int num

请帮助我绘制从C#发送到mathematica内核的数据。 我想从C#中编写mathematica代码并绘制光谱数据。 我想我已经添加了必要的汇编和引用。我的C#代码如下

public void button2_Click(object sender, System.EventArgs e)
{
       double baseline;
       int indexOfPeak;
       int minimumIndicesBetweenPeaks;
       int numberOfPixels; 
       double[] spectrum;
       int startingIndex;
       if (spectrometerIndex == -1)
          return; 
       numberOfPixels = wrapper.getNumberOfPixels(spectrometerIndex);
       wrapper.setIntegrationTime(spectrometerIndex, 500000);
       wrapper.setBoxcarWidth(spectrometerIndex, 10);
       wrapper.setCorrectForElectricalDark(spectrometerIndex, 1);
       spectrum = (double[])wrapper.getSpectrum(spectrometerIndex);
       for (int index = 0; index < numberOfPixels; ++index)
       {
           listBox2.Items.Add("pixel[" + index + "] = " +
           spectrum[index]);               
       }
       MathKernel mathKernel = new MathKernel();
       mathkernel.ListPlot[spectrum];
    }            
}
public void按钮2\u单击(对象发送者,System.EventArgs e)
{
双基线;
int indexOfPeak;
峰间最小积分;
整数像素;
双[]谱;
int启动指数;
如果(光谱索引==-1)
返回;
numberOfPixels=wrapper.getNumberOfPixels(光谱仪索引);
wrapper.setIntegrationTime(光谱仪索引,500000);
包装物.立根盒宽度(光谱指数,10);
包装器。设置校正的电子柜(光谱仪指数,1);
spectrum=(双[])wrapper.getSpectrum(spectrumentIndex);
对于(int index=0;index
以下是基于帖子的两种方法

您可能需要为Mathematica设置合适的
光谱
数据格式,例如:

string data = "1.234, 2.345, 3.456";
用于GIF格式

MathKernel mathKernel = new MathKernel();
mathKernel.CaptureGraphics = true;
mathKernel.GraphicsFormat = "GIF";
mathKernel.Compute("Show[ListPlot[{" + data + "}]]");
mathKernel.Graphics[0].Save("C:\\Temp\\plot.gif", System.Drawing.Imaging.ImageFormat.Gif);
用于增强图元文件(可缩放图形)


另外,我不知道wolfram mathematica,但我怀疑ListPlot是否是数组。我认为在尝试使用高级库之前,你应该先学习C#。您还可以在函数开始时声明一堆未初始化的变量,这与作用域和资源管理的概念背道而驰。压痕应加以改进。
光谱仪索引从哪里来?尊敬的先生,非常感谢您的回复。我不熟悉C#和Mathematica,我这样做是为了获取科学数据。我试过了,但我无法在Windows窗体中绘制光谱。在mathkernel对象中,Graphics属性没有任何值。运行时,显示异常-“索引超出了数组的边界”。
MathKernel mathKernel  = new MathKernel();
mathKernel.Compute("ExportString[ListPlot[{" + data + "}], {\"Base64\", \"EMF\"}]");
byte[] decodedBytes = Convert.FromBase64String(mathKernel.Result.ToString());
File.WriteAllBytes("C:\\Temp\\plot.emf", decodedBytes);