图表:气泡
 

气泡图

气泡图在特定的X/Y位置显示圆圈。每个圆圈都可以单独定制。保存创建气泡图时返回的对象,并调用其Add()方法添加气泡。

var plt = new ScottPlot.Plot(600, 400);

double[] xs = DataGen.Consecutive(31);
double[] ys = DataGen.Sin(31);
var colormap = Drawing.Colormap.Viridis;

var myBubblePlot = plt.AddBubblePlot();
for (int i = 0; i < xs.Length; i++)
{
    double fraction = (double)i / xs.Length;
    myBubblePlot.Add(
        x: xs[i],
        y: ys[i],
        radius: 10 + i,
        fillColor: colormap.GetColor(fraction, alpha: .8),
        edgeColor: System.Drawing.Color.Black,
        edgeWidth: 2
    );
}

plt.Title("Advanced Bubble Plot");
plt.AxisAuto(.2, .25); // zoom out to accommodate large bubbles

plt.SaveFig("bubble_quickstart.png");
 

带标签的气泡

气泡图可以与其他图类型组合,以创建更高级的图表。在本例中,每个气泡都有一个文本对象。气泡的颜色也根据其大小而定,因此较小的气泡更蓝。

var plt = new ScottPlot.Plot(600, 400);

Random rand = new(0);
int pointCount = 30;
double[] xs = DataGen.Consecutive(pointCount);
double[] ys = DataGen.Random(rand, pointCount, 10);
string[] labels = ys.Select(x => x.ToString("N2")).ToArray();
var labelFont = new Drawing.Font
{
    Bold = true,
    Color = Color.Black,
    Alignment = Alignment.MiddleCenter
};

var myBubblePlot = plt.AddBubblePlot();
for (int i = 0; i < xs.Length; i++)
{
    // give each bubble a random size and make smaller ones bluer
    double randomValue = rand.NextDouble();
    double bubbleSize = randomValue * 30 + 10;
    Color bubbleColor = Drawing.Colormap.Jet.GetColor(randomValue, .5);

    myBubblePlot.Add(
        x: xs[i],
        y: ys[i],
        radius: bubbleSize,
        fillColor: bubbleColor,
        edgeColor: Color.Transparent,
        edgeWidth: 1
    );

    plt.AddText(labels[i], xs[i], ys[i], labelFont);
}

plt.Title("Bubble Plot with Labels");
plt.AxisAuto(.2, .25); // zoom out to accommodate large bubbles

plt.SaveFig("bubble_withText.png");