Gnuplot在rowstack直方图中重复颜色 [英] Gnuplot repeats colors in rowstack histograms
问题描述
我目前使用gnuplot和rowstacked直方图绘制一些数据。
问题是,在选择了9种不同的颜色后,颜色开始重复。人们可以看到这也发生在官方的gnuplot例子(参见 http://gnuplot.sourceforge.net/ demo / histograms.html - Example 4& 5)
I am currently plotting some data using gnuplot with rowstacked histograms. The problem is, that the colors start to repeat after 9 different colors have been chosen. One can see this also happening in the official gnuplot examples (see http://gnuplot.sourceforge.net/demo/histograms.html - Example 4 & 5)
有没有办法让gnuplot使用更多不同的颜色?
Is there any way to tell gnuplot to use more different colors?
推荐答案
没有完全自动化的方法来做到这一点,但你可以使用设置样式线...
,然后使用它们。这里,我只是使用一个简单的迭代来定义几种颜色:
There is no fully automated way to do this, but you can define as many line styles as you want with set style line ...
and then use them. Here, I just use a simple iteration to define several colors:
do for [i=1:20] {
set style line i linecolor rgb hsv2rgb(0.05*(i-1), 1, 1)
}
set style data histograms
set style histogram rowstacked
set style fill solid border -1
set boxwidth 0.75
plot for [i=1:20] 'mydata.dat' u 2 ls i t 'ls '.i
数据文件只包含值
1 0.1
2 0.2
3 0.3
注意, hsv2rgb
函数仅从5.0开始定义。对于早期版本,您可以使用以下用户定义的函数来获得相同的功能:
Note, that the hsv2rgb
function is defined only since 5.0. For earlier version you can use the following user-defined function to get the same functionality:
rgb2int(r,g,b) = int(255*r)*2**16 + int(255*g)*2**8 + int(255*b)
hsv2rgb(h,s,v) = (s == 0 ? rgb2int(v,v,v) : (HSV_h = h*6.0, HSV_i = int(floor(HSV_h)), HSV_f = HSV_h - HSV_i, HSV_p = v*(1.0 - s), HSV_q = v*(1.0-s*HSV_f), HSV_t = v*(1.0-s*(1.0-HSV_f)), (HSV_i%6 == 0 ? rgb2int(v,HSV_t,HSV_p) : (HSV_i%6 == 1 ? rgb2int(HSV_q,v,HSV_p) : (HSV_i%6 == 2 ? rgb2int(HSV_p,v,HSV_t) : (HSV_i%6 == 3 ? rgb2int(HSV_p,HSV_q,v) : (HSV_i%6 == 4 ? rgb2int(HSV_t,HSV_p,v) : rgb2int(v,HSV_p,HSV_q))))))))
让你更容易,你可以把这个代码放到一个配置文件或第三个脚本 hsv2rgb.gp
并包含 load'hsv2rgb.gp'
To make it easier, you could put this code into a configuration file, or a third script hsv2rgb.gp
and include it with load 'hsv2rgb.gp'
before using the function.
使用4.6.3版本的输出是:
Output with 4.6.3 is:
这篇关于Gnuplot在rowstack直方图中重复颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!