新建一个Form1,写入下面代码,并在Form1添加一个print事件,Form1_Paint。Form1_Paint中有一个随机数二维数组 twoDim,把他改成你想要输出的数组。即可在Form1像matlab plot一样画出二维数组。
原理:
通过调用
e.Graphics.DrawLine作图
并通过Color MapRainbowColor方法定义不同数值对应的颜色
对数组遍历后画出数组的彩色图
但是注意,在c#中这样做需要执行遍历语句多次,作图的效率很低!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace COLORMAP
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// Draw rainbow colors on the form.
private void Form1_Paint(object sender, PaintEventArgs e)
{
Random r = new Random();
float[,] twoDim = new float[100, 100];
for (int i = twoDim.GetLowerBound(0); i <=