gnuplot更改连接线的颜色 [英] gnuplot change color of the connecting lines

查看:582
本文介绍了gnuplot更改连接线的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用gnuplot为以下。我有n个方程,我想根据xaxis值绘制。下面是一个示例

I am using gnuplot for the following. I have n equations which I want to plot based on the xaxis value. Here is a sample

set xrange[0:25]
f1(x) = x
f2(x) = 3*x
f3(x) = 10*x
plot (x>0)&&(x<10)?f1(x):(x<20)?f2(x):f3(x)



我知道我们可以很容易地设置线的颜色通过使用下面。但它改变了整个颜色

I know that we can set the color of the line easily by using the below. But it changes the whole color

set style line 1 lt 1 lw 3 pt 3 lc rgb "blue"

但是我想要的是使连接线的颜色不同。即如果你绘制上面的图形,你将有5行。 3条原始线(来自功能)和2条线(几乎垂直线)连接它们。我想改变连接线的颜色。

But what I want is to make the connecting lines a different color. ie if you plot the above graph you will 5 lines. 3 original lines (from the function) and 2 lines (the almost vertical lines) connecting them. I want to change the color of the connecting lines.

注意1:这些函数是由程序自动生成的,函数的数量可能很大。

Note 1: These functions are automatically generated by a program, and the number of functions could be large. Even the exact plot command is automatically generated

注意2:我想要一种方法来区分我的原始行和插入的行连接我的原始行。

Note 2: I want a way to differentiate my original lines with the interpolated lines which joins my original lines.

任何帮助是值得赞赏的

推荐答案

你实际上有一行定义分段,

What you actually have is one line defined piecewise, and there isn't an easy way to define colors for line segments within a piecewise line in gnuplot.

我建议您创建如下的数据文件:

I would recommend making a data file looking like this:

# x y color
0   0   0
10  10  0
10  10  1
10  30  1
10  30  0
20  60  0
20  60  1
20  200 1
20  200 0
25  250 0

x = 10和x = 20。

Notice the double points at x=10 and x=20. This is so the line segments meet at the transitions.

现在用 linecolor变量绘制:

#!/usr/bin/env gnuplot

reset

set terminal pdfcairo enhanced color dashed rounded lw 5 size 3,2 font 'Arial,14'
set output 'output2.pdf'

set style data lines
set key top left
set tics scale 0.5 out nomirror

plot 'data.dat' u 1:2:3 lc variable

看起来像这样:

您可以更改调色板( set palette )来确定颜色,

You can change the palette (set palette) to determine the colors, and you can have more than 2 color values in the data file if you want.

您可以定义2n-1个单独的行并将它们连接起来:

You could define 2n-1 separate lines and connect them:

#!/usr/bin/env gnuplot

reset

set terminal pdfcairo enhanced color dashed rounded lw 5 size 3,2 font 'Arial,14'
set output 'output.pdf'

set style data lines
set key top left
set tics scale 0.5 out nomirror

# points every 0.001 units in the range 0:25
set samples 25001

# main lines
f1(x) = (x <= 9.999)                   ? x    : 1/0
f3(x) = (x >= 10.001) && (x <= 19.999) ? 3*x  : 1/0
f5(x) = (x >= 20.001)                  ? 10*x : 1/0

# define slopes and y-offsets of connecting lines
m2 = (f3(10.001)-f1(9.999))/0.002
b2 = (30.0-10.0)/2.0 + 10.0
m4 = (f5(20.001)-f3(19.999))/0.002
b4 = (200.0-60.0)/2.0 + 60.0

# connecting functions
f2(x) = (x >= 9.999) && (x <= 10.001)  ? m2*(x-10) + b2 : 1/0
f4(x) = (x >= 19.999) && (x <= 20.001) ? m4*(x-20) + b4 : 1/0

plot [0:25] f1(x), f2(x), f3(x), f4(x), f5(x)

这看起来像这样:

这篇关于gnuplot更改连接线的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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