填充 gnuplot 中两条曲线之间的区域
Fill the area between two curves in gnuplot
我两个函数:
f(x) = x**2
g(x) = -(x-4)*x
我需要计算这两条曲线之间的面积,为此我想要可视化。 WolframAlpha 正是我想要的:https://www.wolframalpha.com/input/?i=area+between+the+curves+y%3Dx%5E2+and+y%3D-x%5E2%2B4x,但是,我需要在 gnuplot 中制作图形。到目前为止,这是我的代码:
set border linewidth 1
set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 1
set style line 2 linecolor rgb '#dd181f' linetype 1 linewidth 1
set key at 6.1,1.3
set xlabel 'x'
set ylabel 'y'
set xrange [-0.5:3]
set yrange [0:5]
set xtics 2
set ytics 2
set tics scale 2
f(x) = x**2
g(x) = -(x-4)*x
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"
set grid xtics lt 0 lw 1 lc rgb "#bbbbbb"
plot f(x) title 'f(x)' with lines linestyle 1, \
g(x) title 'g(x)' with lines linestyle 2
它产生这个输出:
有没有什么方法可以像在 WolframAlpha 中那样高亮显示这两条曲线之间的区域?假设我们知道它们相交的位置(0 和 2),除非 gnuplot 可以自己做到这一点。
如果普通 gnuplot 无法做到这一点,我深表歉意,在这种情况下,我们将不胜感激一些指向可以做到这一点的资源的指针。
这可以使用 filledcurves
实现(参见文档:http://gnuplot.sourceforge.net/docs_4.2/node245.html)。您只需要使用 below
选项来确保 仅 两条曲线之间的区域 被填充。
举个例子,试试这个:
plot '+' using 1:(f()):(g()) title '' with filledcurves below lc rgb 'green', \
f(x) title 'f(x)' with lines linestyle 1, \
g(x) title 'g(x)' with lines linestyle 2
这基于其在常见问题解答中描述的两条曲线的方式:http://www.gnuplot.info/faq/#x1-460005.3
我两个函数:
f(x) = x**2
g(x) = -(x-4)*x
我需要计算这两条曲线之间的面积,为此我想要可视化。 WolframAlpha 正是我想要的:https://www.wolframalpha.com/input/?i=area+between+the+curves+y%3Dx%5E2+and+y%3D-x%5E2%2B4x,但是,我需要在 gnuplot 中制作图形。到目前为止,这是我的代码:
set border linewidth 1
set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 1
set style line 2 linecolor rgb '#dd181f' linetype 1 linewidth 1
set key at 6.1,1.3
set xlabel 'x'
set ylabel 'y'
set xrange [-0.5:3]
set yrange [0:5]
set xtics 2
set ytics 2
set tics scale 2
f(x) = x**2
g(x) = -(x-4)*x
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"
set grid xtics lt 0 lw 1 lc rgb "#bbbbbb"
plot f(x) title 'f(x)' with lines linestyle 1, \
g(x) title 'g(x)' with lines linestyle 2
它产生这个输出:
有没有什么方法可以像在 WolframAlpha 中那样高亮显示这两条曲线之间的区域?假设我们知道它们相交的位置(0 和 2),除非 gnuplot 可以自己做到这一点。
如果普通 gnuplot 无法做到这一点,我深表歉意,在这种情况下,我们将不胜感激一些指向可以做到这一点的资源的指针。
这可以使用 filledcurves
实现(参见文档:http://gnuplot.sourceforge.net/docs_4.2/node245.html)。您只需要使用 below
选项来确保 仅 两条曲线之间的区域 被填充。
举个例子,试试这个:
plot '+' using 1:(f()):(g()) title '' with filledcurves below lc rgb 'green', \
f(x) title 'f(x)' with lines linestyle 1, \
g(x) title 'g(x)' with lines linestyle 2
这基于其在常见问题解答中描述的两条曲线的方式:http://www.gnuplot.info/faq/#x1-460005.3