【问题标题】:Defining tunable new point types through macro通过宏定义可调的新点类型
【发布时间】:2015-03-13 10:50:38
【问题描述】:

我想使用具有另一种颜色的粗边框的符号来绘制数据点。 我通过用相同的符号(例如一个圆圈;pt 7)绘制两倍的数据点来做到这一点,但大小因给定因素(此处为1.5)而不同,当然,颜色也不同(此处为颜色@987654323 @ -red- 和 3 -blue-)。

p 'data.dat' pt 7 lc 1 ps 1*1.5, '' pt 7 lc 3 ps 1

我正在尝试通过宏来实现这一点。到目前为止,我已经将这一行添加到 gnuplot 初始化文件中(如果我没记错的话,.gnuplot ot gnuplot.ini):

#Define points with a surrounding color
surr(a,b,c,d)=sprintf("pt %d lc %s ps %d*1.5, \"\" pt %d lc %s ps %d",a,b,d,a,c,d)

在 gnuplot 中,我会这样做:

s=surr(7,1,3,1)
p 'data.dat' @s

这很好,但我想从两方面改进它:

一:能够做某事

s=surr(7,@cblue,@cblue2,2) 

cblue = 'rgbcolor "#0083AB"'
cblue2 = 'rgbcolor "#64A8A3"'

之前定义

但是@cblue 不是整数,这不起作用。另一方面,我希望仍然能够使用整数。不幸的是,我不知道哪种格式适合这里。

二:调整两个符号之间的比率(在我的定义中固定为 1.5)。但是,定义

surr(a,b,c,d,e)=sprintf("pt %d lc %s ps %d*%d, \"\" pt %d lc %s ps %d",a,b,d,e,a,c,d)    

抱怨%d*%d 并且我不知道如何解决这个问题。

有什么想法吗?

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    如果你想对你给出的参数有充分的灵活性,你必须只使用字符串参数:

    surr(pt, lc1, lc2, ps, fac)=sprintf("pt %s lc %s ps %s*%s, \"\" pt %s lc %s ps %s", pt, lc1, ps, fac, pt, lc2, ps)
    

    现在你可以使用任何你想要的东西了:

    cblue = 'rgbcolor "#0083AB"'
    cblue2 = 'rgbcolor "#64A8A3"'
    
    s=surr("7",cblue,cblue2,"1", "2")
    plot 'data.dat' @s
    

    s = surr("7", "2", "3", "2", "4")
    plot 'data.dat' @s
    

    允许您输入整数或字符串的一个选项是使用字符串 concat 运算符.,它执行从 int 到 string 的转换(而不是从 double 到 string!)。试试

    surr(pt, lc1, lc2, ps, fac) = "pt ".pt." lc ".lc1." ps ".ps.sprintf("*%f", fac).", '' pt ".pt." lc ".lc2." ps ".ps
    
    cblue = 'rgbcolor "#0083AB"'
    cblue2 = 'rgbcolor "#64A8A3"'
    s=surr(7, cblue,cblue2,1, 2)
    
    plot 'data.dat' @s
    

    至少在 Linux 上确实有效,不确定这种自动转换是否也适用于 Windows。

    【讨论】:

    • 非常感谢!这两种解决方案都可以在 Mac 上完美运行。我不知道字符串 concat 运算符,很方便的东西。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-26
    • 2015-05-16
    相关资源
    最近更新 更多