You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在gnuplot中用列数据分别指定填充色与边框色

用gnuplot的boxxyerrorbar实现填充色与边框色分别取数

核心思路

gnuplot的boxxyerrorbar支持通过fillcolor和linecolor分别指定填充与边框的颜色,结合palette cb(颜色板映射)可以直接从数据列读取颜色值,还支持对列数据做函数变换。

步骤与示例代码

假设你的数据文件名为data.txt,内容如下:

#x  y   fill-color   border-color
2   2      0.50          1.00
8   2      0.25          0.50
8   8      0.40          0.40
2   8      0.50          0.50

1. 基础配置

先设置颜色板、颜色范围和图形样式:

# 设置调色板(示例为灰度,可根据需求替换为其他配色,比如红色系)
set palette defined (0 "white", 1 "black")
# 颜色值范围对应数据中的[0.0:1.0]
set cbrange [0:1]
# 设置填充为实心
set style fill solid 1.0
# 启用boxxyerrorbar样式
set style boxxyerrorbar

2. 绘图命令(支持列数据变换)

使用using子句指定正方形的中心坐标、半边长(边长为2,所以半长是1),再分别从第3列取填充色、第4列做变换后取边框色:

plot 'data.txt' using 1:2:(1):(1) \
    fillcolor palette cb (column(3)) \
    linecolor palette cb (column(4)*0.5) \
    with boxxyerrorbar notitle
  • using 1:2:(1):(1):第1列=x中心,第2列=y中心,(1)=x方向半长,(1)=y方向半长(最终正方形边长为2)
  • fillcolor palette cb (column(3)):填充色由第3列的值映射到调色板
  • linecolor palette cb (column(4)*0.5):边框色由第4列的值乘以0.5后映射到调色板,实现函数变换

3. 针对相图的扩展(区分实测/外推数据)

如果需要用灰色边框表示实测、红色边框表示外推,只需自定义调色板:

# 自定义调色板:0对应灰色(实测),1对应红色(外推)
set palette defined (0 "#888888", 1 "#ff0000")
set cbrange [0:1]

# 绘图时直接用第4列的值映射
plot 'data.txt' using 1:2:(1):(1) \
    fillcolor palette cb (column(3)) \
    linecolor palette cb (column(4)) \
    with boxxyerrorbar notitle

此时数据中第4列填0则边框为灰色(实测),填1则为红色(外推),无需拆分两个文件。

内容的提问来源于stack exchange,提问作者fahd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 13:10:29