矩形等值线图
具有均匀分布点的矩形等值线图可以从 3D 点的 2D 数组创建。
Coordinates3d[,] cs = new Coordinates3d[50, 50];
for (int y = 0; y < cs.GetLength(0); y++)
{
for (int x = 0; x < cs.GetLength(1); x++)
{
double z = Math.Sin(x * .1) + Math.Cos(y * .1);
cs[y, x] = new(x, y, z);
}
}
var contour = WpfPlot1.Plot.Add.ContourLines(cs);
contour.LineColor = Colors.Black.WithAlpha(.5);
contour.LinePattern = LinePattern.Dotted;
WpfPlot1.Plot.Axes.TightMargins();
WpfPlot1.Plot.HideGrid();
WpfPlot1.Refresh();
不规则等值线图
等值线图可以从任意放置在 X/Y 平面中的 3D 数据点集合创建。
安慰WinForms 公司WPF其他
// generate irregularly spaced X/Y/Z data points
Coordinates3d[] cs = new Coordinates3d[1000];
for (int i = 0; i < cs.Length; i++)
{
double x = Generate.RandomNumber(0, Math.PI * 2);
double y = Generate.RandomNumber(0, Math.PI * 2);
double z = Math.Sin(x) + Math.Cos(y);
cs[i] = new(x, y, z);
}
// place markers at each data point
double minZ = cs.Select(x => x.Z).Min();
double maxZ = cs.Select(x => x.Z).Max();
double spanZ = maxZ - minZ;
IColormap cmap = new ScottPlot.Colormaps.MellowRainbow();
for (int i = 0; i < cs.Length; i++)
{
double fraction = (cs[i].Z - minZ) / (spanZ);
var marker = WpfPlot1.Plot.Add.Marker(cs[i].X, cs[i].Y);
marker.Color = cmap.GetColor(fraction).WithAlpha(.8);
marker.Size = 5;
}
// show contour lines
var contour = WpfPlot1.Plot.Add.ContourLines(cs);
// style the plot
WpfPlot1.Plot.Axes.TightMargins();
WpfPlot1.Plot.HideGrid();
WpfPlot1.Refresh();
带热图的等高线
等值线可以放置在热图的顶部。
安慰WinForms 公司WPF其他
Coordinates3d[,] cs = new Coordinates3d[50, 50];
for (int y = 0; y < cs.GetLength(0); y++)
{
for (int x = 0; x < cs.GetLength(1); x++)
{
double z = Math.Sin(x * .1) + Math.Cos(y * .1);
cs[y, x] = new(x, y, z);
}
}
var heatmap = WpfPlot1.Plot.Add.Heatmap(cs);
heatmap.FlipVertically = true;
heatmap.Colormap = new ScottPlot.Colormaps.MellowRainbow();
var contour = WpfPlot1.Plot.Add.ContourLines(cs);
contour.LabelStyle.Bold = true;
contour.LinePattern = LinePattern.DenselyDashed;
contour.LineColor = Colors.Black.WithAlpha(.5);
WpfPlot1.Plot.Axes.TightMargins();
WpfPlot1.Plot.HideGrid();
WpfPlot1.Refresh();
使用颜色图的等值线
如果提供了颜色图,则它将用于根据颜色图中的每一行的值为其着色。
安慰WinForms 公司WPF其他
Coordinates3d[,] cs = new Coordinates3d[50, 50];
for (int y = 0; y < cs.GetLength(0); y++)
{
for (int x = 0; x < cs.GetLength(1); x++)
{
double z = Math.Sin(x * .1) + Math.Cos(y * .1);
cs[y, x] = new(x, y, z);
}
}
var cl = WpfPlot1.Plot.Add.ContourLines(cs, count: 25);
cl.Colormap = new ScottPlot.Colormaps.MellowRainbow();
cl.LineWidth = 3;
cl.LabelStyle.IsVisible = false;
WpfPlot1.Plot.Axes.TightMargins();
WpfPlot1.Plot.HideGrid();
WpfPlot1.Refresh();