数据区背景图像
图像可用于数据区的背景。
// plot sample data
var sig1 = WpfPlot1.Plot.Add.Signal(Generate.Sin());
var sig2 = WpfPlot1.Plot.Add.Signal(Generate.Cos());
sig1.LineWidth = 3;
sig2.LineWidth = 3;
// One could load an image from a file...
// Image bgImage = new("background.png");
// But in this example we will use a sample image:
Image bgImage = SampleImages.ScottPlotLogo();
WpfPlot1.Plot.DataBackground.Image = bgImage;
WpfPlot1.Refresh();
图 背景 图像
图像可以用作图形的背景。
// plot sample data
var sig1 = WpfPlot1.Plot.Add.Signal(Generate.Sin());
var sig2 = WpfPlot1.Plot.Add.Signal(Generate.Cos());
// One could load an image from a file...
// Image bgImage = new("background.png");
// But in this example we will use a sample image:
Image bgImage = SampleImages.MonaLisa();
WpfPlot1.Plot.FigureBackground.Image = bgImage;
// Color the axes and data so they stand out against the dark background
WpfPlot1.Plot.Axes.Color(Colors.White);
sig1.Color = sig1.Color.Lighten(.2);
sig2.Color = sig2.Color.Lighten(.2);
sig1.LineWidth = 3;
sig2.LineWidth = 3;
// Shade the data area to make it stand out
WpfPlot1.Plot.DataBackground.Color = Colors.Black.WithAlpha(.5);
WpfPlot1.Refresh();
颜色插值
可以混合颜色以创建一系列颜色。此策略使用线性 RGB 插值。
for (int i = 0; i <= 10; i++)
{
double fraction = (double)i / 10;
double x = i;
double y = Math.Sin(Math.PI * 2 * fraction);
var circle = WpfPlot1.Plot.Add.Circle(x, y, 2);
circle.FillColor = Colors.Blue.MixedWith(Colors.Green, fraction);
circle.LineColor = Colors.Black.WithAlpha(.5);
}
WpfPlot1.Refresh();
自定义字体文件
用户可以通过从字体文件加载来应用自定义字体。
// Add a font file to use its typeface for fonts with a given name
Fonts.AddFontFile(
name: "Alumni Sans",
path: Path.Combine(Paths.FontFolder, @"AlumniSans/AlumniSans-Regular.ttf"));
// plot sample data
var sig1 = WpfPlot1.Plot.Add.Signal(Generate.Sin(51));
sig1.LegendText = "Sin";
var sig2 = WpfPlot1.Plot.Add.Signal(Generate.Cos(51));
sig2.LegendText = "Cos";
// custom fonts may be used in legends
WpfPlot1.Plot.Legend.FontName = "Alumni Sans";
WpfPlot1.Plot.Legend.FontSize = 24;
// custom fonts may be used in plottables that contain text
var text = WpfPlot1.Plot.Add.Text("Hello", 25, 0.5);
text.LabelStyle.FontName = "Alumni Sans";
text.LabelStyle.FontSize = 24;
// Custom fonts may be used for axis labels.
// Note that bold is disabled because support for
// bold would require loading an additional font file.
WpfPlot1.Plot.Title("Custom Font Demo");
WpfPlot1.Plot.Axes.Title.Label.FontName = "Alumni Sans";
WpfPlot1.Plot.Axes.Title.Label.FontSize = 36;
WpfPlot1.Plot.Axes.Title.Label.Bold = false;
WpfPlot1.Plot.XLabel("Horizontal Axis");
WpfPlot1.Plot.Axes.Bottom.Label.FontName = "Alumni Sans";
WpfPlot1.Plot.Axes.Bottom.Label.FontSize = 24;
WpfPlot1.Plot.Axes.Bottom.Label.Bold = false;
WpfPlot1.Plot.YLabel("Vertical Axis");
WpfPlot1.Plot.Axes.Left.Label.FontName = "Alumni Sans";
WpfPlot1.Plot.Axes.Left.Label.FontSize = 24;
WpfPlot1.Plot.Axes.Left.Label.Bold = false;
WpfPlot1.Refresh();