在直方图中绘制两条点线(gnuplot)? [英] Draw two pointlines in a histogram (gnuplot)?

查看:89
本文介绍了在直方图中绘制两条点线(gnuplot)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过gnuplot在直方图中绘制两条点线,结果图不完全是我想要的.实际上,我希望两个点线中的点(粉红色的点和浅绿色的点)对准两种类型的支柱的中心,因此浅绿色的点保持静止,而粉红色的点向右移动一点,就像黑色的点我已经画了.

I want to draw two pointsline in a histogram by gnuplot, The result chart is not exactly what I wanted. Actually, I want points in two pointlines(the pink one and the lightgreen one) align the center of two types of pillars, so the lightgreen one keeps still, while the pink one move a little to the right, just like the black one I have drawn.

"test.dat"如下:

the 'test.dat' is as follow:


1   10  15  8   22 
2   11  19  7   21
3   9   14  7   19
4   10  21  8   23
5   9   17  9   21

和"plt"文件:

set style data histogram
unset key 
set yrange[0:12]
set y2range[0:25]

plot "test.dat" using 2:xticlabel(1) axis x1y1,\
"test.dat" using 3:xticlabel(1) axis x1y2 with linespoints,\
"test.dat" using 4:xticlabel(1) axis x1y1,\
"test.dat" using 5:xticlabel(1) axis x1y2 with linespoints

推荐答案

我的答案基于

My answer is based on this contribution which uses boxes instead of a histogram. The benefit is that, you know exactly where those boxes are placed, which you can exploit for the line plot.

这是代码:

dx=1.
n=2.
total_box_width_relative=0.25
gap_width_relative=0.1
d_width=(gap_width_relative+total_box_width_relative)*dx/n  
set boxwidth total_box_width_relative/n relative  
set style fill transparent solid 0.5 noborder

plot "test.dat" u ($1):2 w boxes lc rgb"green" notitle,\    
     "test.dat" u ($1+d_width):4 w boxes lc rgb"red" notitle,\
     "test.dat" u ($1):3 w linespoints notitle,\              
     "test.dat" u ($1+d_width):5 w linespoints notitle        

set yrange [0:15]
replot

对代码的一些解释:

  • 应根据您的数据文件选择dx,否则框的间距将不可用.
  • 盒子的数据集数量由n
  • 给出
  • total_box_width_relativegap_width_relative控制框的轴向间距和间距
  • 两个set ...命令控制盒子的外观
  • 在plot命令中,您现在必须分开:使用原始的第一列数据调用一组框和线:($1),但是,对于第二组框和相应的线,则选择定义的轴向偏移量:($1+d_width)-这将确保折线图中的数据点与框对齐
  • 可能需要包含set yrange命令
  • The dx should be selected according to your data file, otherwise the spacing of the boxes will be off.
  • The number of data-sets for the boxes is given by n
  • The total_box_width_relative and gap_width_relative control the axial with and spacing of the boxes
  • the two set ... commands control the appearance of your boxes
  • within the plot command you now have to separate: You call one set of boxes and lines with the original 1st column data: ($1), however, for the second set of boxes and the corresponding line, you choose your defined axial offset: ($1+d_width) - this will ensure that the data points from the line plot will align with the boxes
  • it may be necessary to include a set yrange command

情节如下所示:

注意
我根据您提供的数据更改了折线图的数据.这样做只是为了使这些点更接近方框并说明效果.

Note
I changed the data for the line plots with regard to the data you provided. This was done only to bring the points closer to the boxes and illustrate the effect.

这篇关于在直方图中绘制两条点线(gnuplot)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆