ScottPlot里面显示带色棒的scatter plot
date
Jan 5, 2022
slug
10030
status
Published
tags
C#
wpf
ScottPlot
summary
type
Post
using System.Windows;
using System.Windows.Input;
using ScottPlot;
using ScottPlot.Plottable;
using System.Drawing;
using System;
using System.Reflection;
using System.Linq;
namespace WpfApp2_ScottPlot2
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var plt = new ScottPlot.Plot(400, 300);
var cb = plt.AddColorbar(ScottPlot.Drawing.Colormap.Jet);
double[] xs = { 1, 2, 3, 4, 5 };
double[] ys = { 12, 25, 3, 47, 14 };
double[] values = { 2, 225, 43, 147, 44 };
double maxValue = values.Max();
cb.MinValue = values.Min();
cb.MaxValue = values.Max();
for (int i = 0; i < 5; i++)
{
plt.AddPoint(xs[i], ys[i], ScottPlot.Drawing.Colormap.Jet.GetColor(values[i] / maxValue));
}
new WpfPlotViewer(plt).Show();
}
}
}

第二个例子
using System.Windows;
using System.Windows.Input;
using ScottPlot;
using ScottPlot.Plottable;
using System.Drawing;
using System;
using System.Reflection;
using System.Linq;
namespace WpfApp2_ScottPlot2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var plt = new Plot();
var cb = plt.AddColorbar(ScottPlot.Drawing.Colormap.Jet);
int count = 1_000;
Random r = new Random();
double[] xs = new double[count];
double[] ys = new double[count];
double[] values = new double[count];
for (int i = 0; i < count; i++)
{
xs[i] = r.Next(count);
ys[i] = r.Next(count);
values[i] = r.Next(50);
}
double maxValue = values.Max();
cb.MinValue = values.Min();
cb.MaxValue = values.Max();
for (int i = 0; i < count; i++)
{
plt.AddPoint(xs[i], ys[i], ScottPlot.Drawing.Colormap.Jet.GetColor(values[i] / maxValue));
// plt.AddTooltip(label: values[i].ToString(), x: xs[i], y: ys[i]);
}
new WpfPlotViewer(plt).Show();
}
}
}