gnuplot:用X和Y线注释图

时间:2014-06-19 18:58:56

标签: gnuplot

我想绘制y = xe ^ x的倒数,用虚线指向该点(-exp(-1), - 1)

set parametric
set style arrow 1 head filled size char 1.5,20,50 

set arrow 1 from -4.1,0 to 4.1,0 heads  
set arrow 2 from 0,-4.1 to 0,4.1 heads

set trange[-4:4]
set xrange[-4:4]
set yrange[-4:4]

set xlabel "x"
set ylabel "y"

unset border

set xtics axis format " "
set ytics axis format " "

plot [-4:0.999] log(1-t)/t, t

plot [-4:4] t*exp(t), t lt rgb "black" title '',  -exp(-1),t lt rgb "black", t, -1 lt rgb "black" 

我想将垂直线限制为从y = -1到y = 0,以及从x = -exp(-1)到x = 0的水平线。怎么办呢?

此外,是否有更简单的方法为所有绘图设置线条颜色,而不是为每个绘图指定它?

example

1 个答案:

答案 0 :(得分:0)

我知道,如果我理解正确,你基本上需要用虚线注释你的图形,所以为什么你也不使用箭头。

例如:

# I'm using pngcairo dashed terminal
set terminal pngcairo dashed
set output 'graph.png'

set parametric
set style arrow 1 head filled size char 1.5,20,50 

set arrow 1 from -4.1,0 to 4.1,0 heads  
set arrow 2 from 0,-4.1 to 0,4.1 heads

#set trange[-4:4]
set xrange[-4:4]
set yrange[-4:4]

set xlabel "x"
set ylabel "y"

unset border

set xtics axis format " "
set ytics axis format " "

#plot [-4:0.999] log(1-t)/t, t

set arrow from -exp(-1),-1 to -exp(-1),0 nohead lt 3
set arrow from -exp(-1),-1 to 0,-1 nohead lt 3

plot [-4:4] t*exp(t),t  lt rgb "black" title ''

enter image description here

就您对线颜色的问题而言,它还取决于您使用的终端类型。例如,对于pngcairo终端,Gnuplot本身会为绘图分配不同的linestyles。如果你想要特定的颜色,那么你必须说明它们。看看this link。您可以通过简单搜索Gnuplot的linestyles/linecolour/linetypes等找到大量信息。