gnuplot在直方图中的第n个框上显示颜色 [英] Gnuplot color every nth box in histogram

查看:107
本文介绍了gnuplot在直方图中的第n个框上显示颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制大量条形图,因此我只标记第n个xtic(如.dat文件中的"所示).这是我的输入".dat"文件的前15行:

1 150
" " 260
" " 340
" " 410
5 270
" " 280
" " 260
" " 370
" " 220
10 230
" " 340
" " 300
" " 200
" " 240
15 160

绘制此数据可以正常工作.但是,在我的实际.dat文件中,我需要绘制约500k值(500k框).因此,我想为每10k盒子上某种颜色上色(或在上面的示例中,每5号上色).这是使用的代码:

set terminal postscript eps color
set output "genetic.eps"
set ylabel "Number of Exons"

set style fill solid 1.0 noborder

plot "genes.dat" using 2:xticlabels(1) smooth frequency with boxes notitle

谢谢!

解决方案

在您的情况下,平滑频率实际上没有做任何事情(仅当多个点具有相同的x坐标,但没有指定一个时,它才有效,默认为使用行号.

我们可以摆脱平滑频率选项,而使用可变的线条颜色.如果我们希望将第5个框设置为红色,将其他框设置为蓝色,则可以

plot "genes.dat" u 0:2:(int($0)%5==0?(255<<16):255):xticlabels(1) with boxes lc rgbcolor variable

在绘图规范中,我们使用

  • 0-0列是行号,这将是x值
  • 2-第二列将是y值
  • (int($0)%5==0?(255<<16):255)
    • 确定行号是否为5的倍数
    • 如果是,请将颜色设置为255,以16位偏移(全红色)
    • 如果不是,则将颜色设置为255(全蓝色)
  • xticlabels(1)-Xtic标签

lc rgbcolor variable表示使用基于第三列的rgbcolor值(十六进制格式RRGGBB的24位整数)设置线条颜色.

有关更多详细信息,请参见help linecolor.

在提供的示例中,我首先运行set yrange[0:*],以避免默认的yrange值被第一个框砍掉.

行号从0开始,因为0被5整除,所以第一个框是红色,第六个框是红色,依此类推.如果希望将第5号,第10号等以红色框显示,请在plot命令的颜色规范中使用int($0+1).

注意:这一切都在gnuplot 5中起作用.早期版本不支持移位,因此我们必须将移位表达式替换为计算的实际结果,在这种情况下为16711680. /p>

I am plotting a large number of bars and therefore I only mark the every nth xtic (as seen in the .dat file with " "). Here are the first 15 lines of my input ".dat" file:

1 150
" " 260
" " 340
" " 410
5 270
" " 280
" " 260
" " 370
" " 220
10 230
" " 340
" " 300
" " 200
" " 240
15 160

Plotting this data works fine. However, in my actual .dat file I have about 500k values to plot (500k boxes). Therefore I wanted to color every 10k box with a certain color (or in the example above, every 5th). This is the code used:

set terminal postscript eps color
set output "genetic.eps"
set ylabel "Number of Exons"

set style fill solid 1.0 noborder

plot "genes.dat" using 2:xticlabels(1) smooth frequency with boxes notitle

Thanks!

解决方案

In your case, the smooth frequency isn't actually doing anything (that only works when multiple points have the same x-coordinate, but by not specifying one, the default is to use the line number).

We can get arid of the smooth frequency option and use the variable line color. If we wish to set every 5th box red, and the others blue, we can do

plot "genes.dat" u 0:2:(int($0)%5==0?(255<<16):255):xticlabels(1) with boxes lc rgbcolor variable

In the plot specification, we use

  • 0 - 0 column is the line number, this will be the x-value
  • 2 - the 2nd column will be the y-value
  • (int($0)%5==0?(255<<16):255)
    • Determine if line number is a multiple of 5
    • If it is, set color to 255 shifted by 16 bits (full red)
    • If not, set color to 255 (full blue)
  • xticlabels(1) - the xtic labels

The lc rgbcolor variable means to set the line color using an rgbcolor value (a 24 bit integer of the form RRGGBB in hex form) based on a third column.

See help linecolor for more details.

In the provided example, I first ran set yrange[0:*] in order to avoid the default yrange value calculation from chopping off the first box.

Line numbers start at 0, and as 0 is divisible by 5, the first box is red, as is the sixth, and so on. If we wish to have the 5th, 10th, and so on boxes red, use int($0+1) in the color specification in the plot command.

Note: This all works in gnuplot 5. Earlier versions do not support bit shifting, so we must replace the shift expression with the actual result of the computation, which is 16711680 in this case.

这篇关于gnuplot在直方图中的第n个框上显示颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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