【问题标题】:Single histogram multiple y axis with different x axis labels具有不同 x 轴标签的多个 y 轴的单个直方图
【发布时间】:2020-03-15 17:50:38
【问题描述】:

我的 test.dat 文件看起来像

# Experiment No.  Total U_Na-Z (millimoles/g of zeolite) Total Na_Na-Z in melt (mmoles/g zeolite)         Total U_Li-Z (millimoles/g of zeolite) Total Na_Li-Z in melt (mmoles/g zeolite)
Experiment No.  Total U loading (mmoles/g zeolite)   Total Na in melt (mmoles/g of zeolite)           Total U loading (mmoles/g zeolite)   Total Na in melt (mmoles/g of zeolite) 
1                0.074798319                          4.60                                              0.061795848                          1.38
2                0.148512605                          3.73                                              0.122910867                          1.72
3                0.223310924                          4.02                                              0.216806723                          1.46
4                0.287268908                          5.26                                              0.275399753                          1.60               

我想针对 Col 1(x 轴)绘制一个带有两个 y 轴(Col 2 作为 y,Col 3 作为 y2)的直方图,并且在同一个直方图中,Col 4(作为 y)和 Col 5(因为 y2) 必须针对 Col 1 绘制,当然要使用不同的颜色。脚本如下(来自 gnuplot 的新直方图脚本相应修改)

set terminal postscript eps enhanced colour font 'Times-Roman,12' size 5in,4in  
set output "Histogram1.eps"
#------------------------------------------------------------------------------
set style line 1 lt 2 lw 1 lc rgb "#000FF"
set style line 2 lt 3 lw 1 lc rgb "#228B22"
set style line 3 lt 4 lw 1 lc rgb "#FF4500"
set style line 4 lt 5 lw 1 lc rgb "#8B0000"
set style line 5 lt 6 lw 1 lc rgb "dark-magenta"
#------------------------------------------------------------------------------
set xtics out scale 1.5 
set ytics out scale 1.5
set y2tics out scale 1.5 
set ytics nomirror
set yrange [0:0.50]
set y2range [0:6] 
set key off
set tics font ", 14"
set xlabel "Experiment No." font ",16"
set ylabel "U loading in zeolite (mmoles/g zeolite)" font ",16"
set y2label "Na in melt (mmoles/g zeolite)" font ",16"
set key autotitle columnheader
set key inside left horizontal
set style fill solid 1.00 noborder
set style histogram clustered gap 1 title textcolor lt -1
# ----------------------------------------
set rmargin screen 0.9
set lmargin screen 0.1
set bmargin screen 0.1
# ----------------------------------------

现在 plot 命令被指定为

plot \
newhistogram "Sodium Zeolite", \
'test.dat' using 2:xtic(1) ls 1 ti col axis x1y1, '' 3:xticlabels(1) ls 2 ti col axis x1y2, \
newhistogram "Lithium Zeolite", \
'' using 4:xtic(1) ls 3 ti col axis x1y1, '' 5:xticlabels(1) ls 4 ti col axis x1y2 

在 x 轴上,对于前四个数据,必须显示“钠沸石”,对于巢四,必须显示“锂沸石”。但这似乎不起作用。任何建议都会有所帮助。

谢谢你,

【问题讨论】:

    标签: gnuplot histogram


    【解决方案1】:

    几个小问题:

    • 您需要告诉程序使用直方图绘图样式。最好的办法是在 plot 命令前加一行:

      设置样式数据直方图

    • 关键字是axes,而不是axis

    • using 关键字必须出现在每个情节子句中

    • 没有必要在每个绘图中多次发出xticlabels(1) 命令(虽然它也不应该造成伤害,但标签会在同一个地方打印两次)。

    这给出了一个修改后的绘图命令:

    set style data histogram
    plot \
      newhistogram "Sodium Zeolite", \
      'test.dat' using 2:xtic(1) ls 1 ti col axes x1y1, \
      '' using 3 ls 2 ti col axes x1y2, \
      newhistogram "Lithium Zeolite", \
      '' using 4:xtic(1) ls 3 ti col axes x1y1, \
      '' using 5 ls 4 ti col axes x1y2
    

    如图所示输出

    【讨论】:

      猜你喜欢
      • 2012-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      • 2020-06-11
      • 2019-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多