Bubble Plot(气泡图)是一种数据可视化图表,用于显示三个变量之间的关系。它通过在二维平面上绘制圆形气泡来表示数据点,其中每个气泡的位置由两个变量确定,而气泡的大小则表示第三个变量的值。
气泡图常用于以下应用场景:
C#private void Form1_Load(object sender, EventArgs e)
{
var plot = formsPlot1.Plot;
double[] xs = DataGen.Consecutive(31);
double[] ys = DataGen.Sin(31);
//ScottPlot 绘图库中的一个预定义颜色映射(colormap)
//用于在绘图中应用颜色渐变。
var colormap = ScottPlot.Drawing.Colormap.Viridis;
//创建气泡图
var myBubblePlot = plot.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
);
}
formsPlot1.Refresh();
}
C#private void Form1_Load(object sender, EventArgs e)
{
var plot = formsPlot1.Plot;
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 ScottPlot.Drawing.Font
{
Bold = true,
Color = Color.Black,
Alignment = Alignment.MiddleCenter
};
var myBubblePlot = plot.AddBubblePlot();
for (int i = 0; i < xs.Length; i++)
{
//随机大小和较小的气泡
double randomValue = rand.NextDouble();
double bubbleSize = randomValue * 30 + 10;
Color bubbleColor = ScottPlot.Drawing.Colormap.Jet.GetColor(randomValue, .5);
myBubblePlot.Add(
x: xs[i],
y: ys[i],
radius: bubbleSize,
fillColor: bubbleColor,
edgeColor: Color.Transparent,
edgeWidth: 1
);
//添上文字
plot.AddText(labels[i], xs[i], ys[i], labelFont);
}
formsPlot1.Refresh();
}
本文作者:技术老小子
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!