【问题标题】:gnuplot histogram with colour gradient具有颜色渐变的 gnuplot 直方图
【发布时间】:2021-04-16 04:35:26
【问题描述】:
我尝试使用以下数据绘制 2(下)和 3(上)
数据:
Cl 5.1244 6.0975
Cl2 3.6397 5.0368
Cl3 4.9153 6.0568
Br 4.7905 5.2973
Br2 3.4454 4.3466
Br3 4.6047 5.2715
I 4.5664 4.6143
I2 3.3487 3.7660
I3 4.4178 4.6079
代码:
set border 2
set yrange [1.5:8.5]
set style data histogram
set style histogram cluster gap 1
set style fill solid
#set palette defined (0 "white", 7.0 "red")
#set boxwidth 0.5
set xtics format ""
plot "CBM-VBM2.dat" using ($2):xtic(1), '' u 3
cbm-vbm-绘图
【问题讨论】:
-
欢迎来到 StackOverflow!那么,你的问题是什么?我在你的问题中找不到问号。我不知道 gnuplot 有带有颜色渐变的框。对于带有渐变填充stackoverflow.com/a/60158377/7295599 的曲线,这是一个尴尬的解决方法,但我看不到这种方法适用于多个框。我想您必须将所有框拆分为子框并用不同(分级)颜色绘制它们。我想这会很长很麻烦,但应该是可行的
标签:
gnuplot
histogram
gradient
【解决方案1】:
嗯,它并没有像我预期的那样冗长。查找附件关于如何创建带有渐变的框的建议。
为了获得好看的图形和褪色效果,您可能需要调整一些变量,例如N 表示子框的数量或“衰落功能”,这里是sqrt(x)。
代码:
### gradient boxes
reset session
$Data <<EOD
1 1L 5.45 3.90 0x000000
2 2L 5.00 4.00 0x008888
3 3L 4.90 4.10 0xff00ff
4 4L 4.80 4.12 0x0000ff
5 5L 4.75 4.15 0x00ff00
EOD
$Levels <<EOD
Ti 4.35
Cu 4.70
Ni 5.23
Pt 5.64
graphene 4.50
EOD
ColorFade(x) = sqrt(x) # function between [0:1][0:1] to fade out the color
BoxWidth = 0.9 # relative boxwidth
BoxHeight = 0.3 # fade-box height
N = 21 # number of subbox steps
FadeDirection(col) = col==3 ? -1 : 1 # fading direction
BaseColor(n) = int(word($Data[n],5)) # base color
set print $FadeBoxes append
do for [a=1:|$Data|] {
do for [col=3:4] {
do for [i=0:N] {
x0 = a
y0 = -word($Data[a],col)
ystep = real(BoxHeight)/N*FadeDirection(col)
print sprintf("% 9g % 9g % 9g % 9g 0x%02x%06x", \
x0-BoxWidth/2., x0+BoxWidth/2., \
y0+i*ystep, y0+(i+1)*ystep, \
int(ColorFade(real(i)/N)*0xff),BaseColor(a))
}
}
}
set print
set style fill solid noborder
unset key
LevelXShift = 6
plot $FadeBoxes u 1:3:1:2:3:4:5 w boxxy fc rgb var ti "Levels", \
$Data u 1:(-$3):2 w labels offset 0, 0.7, \
$Levels u ($0/2+LevelXShift):(-$2):1 w labels offset 0, 0.7, \
'' u ($0/2+LevelXShift):(-$2):2 w labels offset 0,-0.7, \
'' u ($0/2+LevelXShift-0.2):(-$2):(0.4):(0) w vec lc "red" lw 2 nohead
### end of code
结果: