Gnuplot - coloring a plot according to x-value

℡╲_俬逩灬. 提交于 2019-12-20 07:28:28

问题


I would like to change the color of a plot according to the x-value, for a function plot (i.e. not from a data file).
For example, I define a palette as follows:
set palette defined ( 0 'purple', 1 'blue', 2 'green', 3 'yellow', 4 'orange', 5 'red' )
and I wish to use the color the function sin(x) using my palette according to the x value for the range [0:5].
How can this be done?


回答1:


You can use linecolor palette for this purpose, which requires the specification of an additional column that contains the color information. For a function plot you can use the special filename '+' to have the full versatility of the using command at your disposal:

set palette defined ( 0 'purple', 1 'blue', 2 'green', 3 'yellow', 4 'orange', 5 'red' )
set xrange [0:5]
plot '+' using 1:(sin($1)):1 with lines linewidth 3 linecolor palette



来源:https://stackoverflow.com/questions/49825712/gnuplot-coloring-a-plot-according-to-x-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!