【问题标题】:gnuplot conditional fill color [duplicate]gnuplot条件填充颜色[重复]
【发布时间】:2017-02-27 17:21:13
【问题描述】:

gnuplot 的新手。可能是一个简单的问题,但感谢您的帮助。

我正在绘制一个堆叠直方图,每个类别有 5 个部分(来自文件的第 3-7 列)。根据第二列数据中的变量(0 或 1),这些部分的颜色可以是黑色、绿色、黄色、洋红色、红色,或者分别是红色、洋红色、黄色、绿色、黑色。我一直在尝试改变这项工作:

plot 'themesdat.txt' u 3 not lt rgb ($2?0xff5050:0x808080),\
 '' u 4 not lt rgb ($2?0x966496:0x00ff66),\
 '' u 5 not lt rgb 0xffff00,\
 '' u 6 not lt rgb ($2?0x00ff66:0x966496"),\
 '' u 7 :xticlabels(1) not lt rgb ($2?0x808080:0xff5050)

条件产生未定义值错误。正如我所说,可能是一个简单的问题,但我被卡住了!

编辑:数据文件示例(前 6 行):-

#title band1, band2, band3, band4, band5, labelx, label1, ... label5
#band colours: ff5050¸966496, ffff00, 00ff66, 808080 (reversed for 1,7,8,11,12,16,7,18,19)
Satisfaction 1 43 15 0 16 26 0 "severe problems" probs " " help? fine
Frustration 0 42 11 18 0 29 1 fine help problems "" "severe problems"
CopingAbility 1 47 13 7 11 22 2 "severe problems" probs " " help? fine
Category 1 0 0 0 0 0 3 "" "" "" "" ""

进一步编辑:我认为这可能是不可能的 - 使用数据文件中的列来改变颜色。即使是更简单的结构,rgb(2 美元),似乎也不起作用。

如果有人知道……?

【问题讨论】:

    标签: colors conditional gnuplot


    【解决方案1】:

    如果我理解正确,您可以尝试this question 中的一种方法,例如this answer。您还可以在那里找到解释。

    set terminal pngcairo  size 960,600
    set output "conditional_fill.png"
    
    datafile="themesdat.txt"
    set yrange [0:100]
    
    set key out
    set style data histograms
    set style histogram rowstacked
    set boxwidth 0.8 relative
    set style fill solid 1.0 border -1
    
    set style line  3 lt 1 lc rgb "black"
    set style line  4 lt 1 lc rgb "green"
    set style line  5 lt 1 lc rgb "yellow" 
    set style line  6 lt 1 lc rgb "magenta"
    set style line  7 lt 1 lc rgb "red"
    
    set style line 13 lt 1 lc rgb "red"
    set style line 14 lt 1 lc rgb "magenta"
    set style line 15 lt 1 lc rgb "yellow"
    set style line 16 lt 1 lc rgb "green"
    set style line 17 lt 1 lc rgb "black" 
    
    color(x,y) = 10*x + y
    
    stats datafile u 2 nooutput
    n = STATS_records
    
    set multiplot
    do for [i=0:n-1] {
       plot datafile u (0):xticlabels(1) notitle,\
            newhistogram "" at i, \
                  "" every ::i::i u (style = color($2, 3), 0) notitle,  \
                  "" every ::i::i u 3 ls style title "severe problems", \
                  "" every ::i::i u (style = color($2, 4), 0) notitle,  \
                  "" every ::i::i u 4 ls style title "probs",           \
                  "" every ::i::i u (style = color($2, 5), 0) notitle,  \
                  "" every ::i::i u 5 ls style title " ",               \
                  "" every ::i::i u (style = color($2, 6), 0) notitle,  \
                  "" every ::i::i u 6 ls style title "help?",           \
                  "" every ::i::i u (style = color($2, 7), 0) notitle,  \
                  "" every ::i::i u 7 ls style title "fine"
    }
    unset multiplot
    

    这是结果:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-04
      • 2014-04-27
      • 1970-01-01
      • 1970-01-01
      • 2014-10-27
      • 1970-01-01
      • 2021-03-28
      • 1970-01-01
      相关资源
      最近更新 更多