轴和滴答声
Axis定制
轴可以通过不同的方式进行定制。轴标签和颜色是最常见的自定义类型。
var plt = new ScottPlot.Plot(600, 400);
// plot sample data
plt.AddSignal(DataGen.Sin(51));
plt.AddSignal(DataGen.Cos(51));
// These shortcuts are the easiest way to set axis labels
plt.XLabel("Horizontal Axis");
plt.YLabel("Vertical Axis");
plt.Title("Axis Customization");
// Axes labels can be further customized for any axis
plt.YAxis.Label("Vertical Axis", Color.Magenta, size: 24, fontName: "Comic Sans MS");
// This method will set the color of axis labels, lines, ticks, and tick labels
plt.XAxis.Color(Color.Green);
plt.SaveFig("Axis_label.png");
禁用网格
可以使用一种方法设置主X轴网和Y轴网的可见性。
var plt = new ScottPlot.Plot(600, 400);
// plot sample data
plt.AddSignal(DataGen.Sin(51));
plt.AddSignal(DataGen.Cos(51));
// hide grids
plt.Grid(false);
plt.SaveFig("axis_gridDisableAll.png");
禁用垂直网格
可以单独控制每个轴的轴线可见性。使用此选项可选择性地仅为感兴趣的轴启用网格线。请记住,垂直网格线由水平轴控制。
var plt = new ScottPlot.Plot(600, 400);
// plot sample data
plt.AddSignal(DataGen.Sin(51));
plt.AddSignal(DataGen.Cos(51));
// each axis has its own visibility controls
plt.XAxis.Grid(false);
plt.SaveFig("axis_gridDisableOne.png");
网格样式
通用网格线配置可用。
var plt = new ScottPlot.Plot(600, 400);
// plot sample data
plt.AddSignal(DataGen.Sin(51));
plt.AddSignal(DataGen.Cos(51));
// these helper methods set grid
plt.Grid(color: Color.FromArgb(50, Color.Green));
plt.Grid(lineStyle: LineStyle.Dot);
plt.SaveFig("asis_gridConfigure.png");
无框架情节
无框绘图可以显示接近图形边缘的数据。
var plt = new ScottPlot.Plot(600, 400);
plt.AddSignal(DataGen.Sin(51));
plt.AddSignal(DataGen.Cos(51));
plt.AxisAuto(0, 0); // zero margin between data and edge of plot
plt.Frameless();
plt.SaveFig("asis_frameless.png");
只有一个轴
可以禁用轴记号和线。请注意,以这种方式隐藏它们可以保留它们的空白。设置XAxis。IsVisible to false将使轴完全崩溃。
var plt = new ScottPlot.Plot(600, 400);
// plot sample data
plt.AddSignal(DataGen.Sin(51));
plt.AddSignal(DataGen.Cos(51));
// hide just the horizontal axis ticks
plt.XAxis.Ticks(false);
// hide the lines on the bottom, right, and top of the plot
plt.XAxis.Line(false);
plt.YAxis2.Line(false);
plt.XAxis2.Line(false);
plt.SaveFig("one_axisonly.png");
旋转X记号
水平刻度标签可以根据需要旋转。
var plt = new ScottPlot.Plot(600, 400);
// plot sample data
plt.AddSignal(DataGen.Sin(51));
plt.AddSignal(DataGen.Cos(51));
plt.XAxis.Label("Horizontal Axis");
plt.YAxis.Label("Vertical Axis");
// rotate horizontal axis tick labels
plt.XAxis.TickLabelStyle(rotation: 45);
plt.SaveFig("ticks_rotated.png");
旋转的扁虱
垂直刻度标签可以根据需要旋转。
var plt = new ScottPlot.Plot(600, 400);
// plot sample data
plt.AddSignal(DataGen.Sin(51));
plt.AddSignal(DataGen.Cos(51));
plt.XAxis.Label("Horizontal Axis");
plt.YAxis.Label("Vertical Axis");
// rotate horizontal axis tick labels
plt.YAxis.TickLabelStyle(rotation: 45);
plt.SaveFig("ticks_rotatedY.png");
绘制日期时间数据
此示例演示如何在水平轴上显示日期时间数据。使用日期时间。ToOADate()将DateTime[]转换为double[],绘制数据,然后告诉轴将刻度标签格式化为日期。
var plt = new ScottPlot.Plot(600, 400);
// create data sample data
DateTime[] myDates = new DateTime[100];
for (int i = 0; i < myDates.Length; i++)
myDates[i] = new DateTime(1985, 9, 24).AddDays(7 * i);
// Convert DateTime[] to double[] before plotting
double[] xs = myDates.Select(x => x.ToOADate()).ToArray();
double[] ys = DataGen.RandomWalk(myDates.Length);
plt.AddScatter(xs, ys);
// Then tell the axis to display tick labels using a time format
plt.XAxis.DateTimeFormat(true);
plt.SaveFig("ticks_dateTime.png");