首页 > 解决方案 > Gnuplot:如何绘制相反的条形图或金字塔条形图

问题描述

是否可以在 gnuplot 中使用两个正 y 轴?这只是该问题的一个简单示例。

情节.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'

而不是使用1:(-$2)我想1:2在 plot.gp 的最后一行使用。

数据1.dat:

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

从:

在此处输入图像描述

到:

在此处输入图像描述

标签: gnuplot

解决方案


答案与theoz中的答案相同,只是 y2 标签移到图的左侧,并且该set link y2命令用于概括轴反转。

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

$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'

在此处输入图像描述


推荐阅读