Gnuplot:如何绘制相反的条形图或金字塔条形图

Gnuplot:如何绘制相反的条形图或金字塔条形图,gnuplot,Gnuplot,是否可以将两个正y轴与gnuplot一起使用?这只是这个问题的一个简单例子 plot.gp: reset set style fill solid 1 set boxwidth 0.8 relative plot 'data1.dat' index 1 using 1:2 with boxes title 'A' ,\ '' index 2 using 1:(-$2) with boxes title 'B' 0.12 0.024 0.15 0.13

是否可以将两个正y轴与gnuplot一起使用?这只是这个问题的一个简单例子

plot.gp:

reset
set style fill solid 1
set boxwidth 0.8 relative
plot 'data1.dat' index 1 using 1:2     with boxes title 'A' ,\
              '' index 2 using 1:(-$2) with boxes title 'B'
0.12   0.024
0.15   0.132
0.18   0.241
0.22   0.136


0.12   0.039
0.15   0.219
0.18   0.197
0.22   0.155
### two "positive" y-axes
reset session

$Data <<EOD
0.12   0.024
0.15   0.132
0.18   0.241
0.22   0.136


0.12   0.039
0.15   0.219
0.18   0.197
0.22   0.155
EOD

set style fill transparent solid 0.5
set boxwidth 0.8 relative

set yrange[-0.3:0.3]
set ytics 0,0.1
set mytics 2
set y2range[0.3:-0.3]
set y2tics 0,0.1
set my2tics 2
set y2tics mirror
set xzeroaxis ls -1

plot $Data u 1:2 index 0 axis x1y1 w boxes title 'A' ,\
        '' u 1:2 index 1 axis x1y2 w boxes title 'B'
### end of code
### y-axis with two "positive" directions
reset session

$Data <<EOD
0.12   0.024
0.15   0.132
0.18   0.241
0.22   0.136


0.12   0.039
0.15   0.219
0.18   0.197
0.22   0.155
EOD

set style fill transparent solid 0.5
set boxwidth 0.8 relative
set xzeroaxis ls -1

Max = 0.3
Steps = 3
set yrange[-Max:Max]
set ytics ()            # remove all tics
do for [i=-Steps:Steps] {
    myTic = sprintf('set ytics add ("%g" %g)',abs(real(i)/Steps*Max),real(i)/Steps*Max)
    eval(myTic)
}

plot $Data u 1:2     index 0 axis x1y1 w boxes lc 3 title 'A' ,\
        '' u 1:(-$2) index 1 axis x1y1 w boxes lc 4 title 'B'
### end of code
我想在plot.gp的最后一行中使用
1:2
,而不是使用
1:($2)

data1.dat:

reset
set style fill solid 1
set boxwidth 0.8 relative
plot 'data1.dat' index 1 using 1:2     with boxes title 'A' ,\
              '' index 2 using 1:(-$2) with boxes title 'B'
0.12   0.024
0.15   0.132
0.18   0.241
0.22   0.136


0.12   0.039
0.15   0.219
0.18   0.197
0.22   0.155
### two "positive" y-axes
reset session

$Data <<EOD
0.12   0.024
0.15   0.132
0.18   0.241
0.22   0.136


0.12   0.039
0.15   0.219
0.18   0.197
0.22   0.155
EOD

set style fill transparent solid 0.5
set boxwidth 0.8 relative

set yrange[-0.3:0.3]
set ytics 0,0.1
set mytics 2
set y2range[0.3:-0.3]
set y2tics 0,0.1
set my2tics 2
set y2tics mirror
set xzeroaxis ls -1

plot $Data u 1:2 index 0 axis x1y1 w boxes title 'A' ,\
        '' u 1:2 index 1 axis x1y2 w boxes title 'B'
### end of code
### y-axis with two "positive" directions
reset session

$Data <<EOD
0.12   0.024
0.15   0.132
0.18   0.241
0.22   0.136


0.12   0.039
0.15   0.219
0.18   0.197
0.22   0.155
EOD

set style fill transparent solid 0.5
set boxwidth 0.8 relative
set xzeroaxis ls -1

Max = 0.3
Steps = 3
set yrange[-Max:Max]
set ytics ()            # remove all tics
do for [i=-Steps:Steps] {
    myTic = sprintf('set ytics add ("%g" %g)',abs(real(i)/Steps*Max),real(i)/Steps*Max)
    eval(myTic)
}

plot $Data u 1:2     index 0 axis x1y1 w boxes lc 3 title 'A' ,\
        '' u 1:(-$2) index 1 axis x1y1 w boxes lc 4 title 'B'
### end of code
发件人:

致:


这是一个具有单个绘图的解决方案,但是,y轴TIC位于不同的侧面。 也许有一些简单的方法让他们站在同一边

代码:

reset
set style fill solid 1
set boxwidth 0.8 relative
plot 'data1.dat' index 1 using 1:2     with boxes title 'A' ,\
              '' index 2 using 1:(-$2) with boxes title 'B'
0.12   0.024
0.15   0.132
0.18   0.241
0.22   0.136


0.12   0.039
0.15   0.219
0.18   0.197
0.22   0.155
### two "positive" y-axes
reset session

$Data <<EOD
0.12   0.024
0.15   0.132
0.18   0.241
0.22   0.136


0.12   0.039
0.15   0.219
0.18   0.197
0.22   0.155
EOD

set style fill transparent solid 0.5
set boxwidth 0.8 relative

set yrange[-0.3:0.3]
set ytics 0,0.1
set mytics 2
set y2range[0.3:-0.3]
set y2tics 0,0.1
set my2tics 2
set y2tics mirror
set xzeroaxis ls -1

plot $Data u 1:2 index 0 axis x1y1 w boxes title 'A' ,\
        '' u 1:2 index 1 axis x1y2 w boxes title 'B'
### end of code
### y-axis with two "positive" directions
reset session

$Data <<EOD
0.12   0.024
0.15   0.132
0.18   0.241
0.22   0.136


0.12   0.039
0.15   0.219
0.18   0.197
0.22   0.155
EOD

set style fill transparent solid 0.5
set boxwidth 0.8 relative
set xzeroaxis ls -1

Max = 0.3
Steps = 3
set yrange[-Max:Max]
set ytics ()            # remove all tics
do for [i=-Steps:Steps] {
    myTic = sprintf('set ytics add ("%g" %g)',abs(real(i)/Steps*Max),real(i)/Steps*Max)
    eval(myTic)
}

plot $Data u 1:2     index 0 axis x1y1 w boxes lc 3 title 'A' ,\
        '' u 1:(-$2) index 1 axis x1y1 w boxes lc 4 title 'B'
### end of code
结果:

reset
set style fill solid 1
set boxwidth 0.8 relative
plot 'data1.dat' index 1 using 1:2     with boxes title 'A' ,\
              '' index 2 using 1:(-$2) with boxes title 'B'
0.12   0.024
0.15   0.132
0.18   0.241
0.22   0.136


0.12   0.039
0.15   0.219
0.18   0.197
0.22   0.155
### two "positive" y-axes
reset session

$Data <<EOD
0.12   0.024
0.15   0.132
0.18   0.241
0.22   0.136


0.12   0.039
0.15   0.219
0.18   0.197
0.22   0.155
EOD

set style fill transparent solid 0.5
set boxwidth 0.8 relative

set yrange[-0.3:0.3]
set ytics 0,0.1
set mytics 2
set y2range[0.3:-0.3]
set y2tics 0,0.1
set my2tics 2
set y2tics mirror
set xzeroaxis ls -1

plot $Data u 1:2 index 0 axis x1y1 w boxes title 'A' ,\
        '' u 1:2 index 1 axis x1y2 w boxes title 'B'
### end of code
### y-axis with two "positive" directions
reset session

$Data <<EOD
0.12   0.024
0.15   0.132
0.18   0.241
0.22   0.136


0.12   0.039
0.15   0.219
0.18   0.197
0.22   0.155
EOD

set style fill transparent solid 0.5
set boxwidth 0.8 relative
set xzeroaxis ls -1

Max = 0.3
Steps = 3
set yrange[-Max:Max]
set ytics ()            # remove all tics
do for [i=-Steps:Steps] {
    myTic = sprintf('set ytics add ("%g" %g)',abs(real(i)/Steps*Max),real(i)/Steps*Max)
    eval(myTic)
}

plot $Data u 1:2     index 0 axis x1y1 w boxes lc 3 title 'A' ,\
        '' u 1:(-$2) index 1 axis x1y1 w boxes lc 4 title 'B'
### end of code

与theoz给出的答案相同,只是y2标签被移到绘图的左侧,并且
设置链接y2
命令用于概括轴反转

您可以调整偏移量
图形-1.03
以叠加“0”标签,然后通过将y2 tic范围更改为
设置Y2TIC 0.1,0.1
来删除重复的“0”标签

$Data <<EOD
0.12   0.024
0.15   0.132
0.18   0.241
0.22   0.136


0.12   0.039
0.15   0.219
0.18   0.197
0.22   0.155
EOD

set style fill transparent solid 0.5
set boxwidth 0.8 relative
set xzeroaxis ls -1

set yrange[-0.3:0.3]
set ytics 0,0.1
set mytics 2

# Set y2 axis to exact mirror of y1
# Shift tic labels to the left and use right-justified text
set link y2 via -y inv -y
set y2tics 0,0.1
set y2tics offset graph -1.03 right

plot $Data u 1:2 index 0 axis x1y1 w boxes title 'A' ,\
        '' u 1:2 index 1 axis x1y2 w boxes title 'B'

$Data您是否尝试过
multiplot
?有了这个,你肯定能找到解决办法。我会考虑如果没有
multiplot
,是否会有解决方案。非常感谢您的建议。我还没有尝试multiplot。将y2 tic标签移到左侧:
将y2tics偏移图设置为-1.03 right
。您可能需要调整值
1.03
,使“0”标签完全重叠。@Ethan啊,很有趣。我没有想到偏移量,你可以在图形坐标中进行。正如您所说,缺点是它取决于图形大小,所以每次更改图形大小时,都必须再次调整。我将补充另一个想法。谢谢你的帮助。谢谢,谢谢。这是有效的。