【问题标题】:Gnuplot: Graphing and Defining Variables in Polar CoordinatesGnuplot:在极坐标中绘制和定义变量
【发布时间】:2013-09-12 15:04:14
【问题描述】:

我是 Gnuplot 的新手,在试图弄清楚如何在极坐标中为学校作业绘制图表时遇到了问题。困扰我的是,我们根本没有为 Gnuplot 研究其他坐标系,如 Polar 或 Parametric,而且我发现的互联网教程似乎假设了一些基本知识,只是告诉我做“设置极坐标”。

这是我要解决的问题:

以原点为中心的特定分子周围的电子密度描述为

n(r,theta) = [cos(r)]^2 * {1+[cos(theta)]^2} * exp(-r^2/25)

其中 r 和 theta 是通常的极坐标 [例如,(x,y) = (r*cos(theta),r*sin(theta))]。

编写一个 gnuplot 脚本 elec.gpl,在 x=-5..5 和 y=-5..5 的域上生成此函数的曲面图。设置你的脚本,以便

gnuplot> elec.gpl

将绘图生成为名为“elec.ps”的后记文件

由于我完全不熟悉在极坐标中绘制 Gnuplot,所以我很难过。我尝试了一些不同的方法,包括以下内容:

    set terminal png enhanced
    set output 'elec.ps'
    set polar
    set angle degrees
    set title 'Electron Density Around Molecule'
    set xrange[-5:5]
    set yrange[-5:5]
    set grid
    set grid polar
    plot (cos(x))^2 *(1+(cos(y))^2)*exp(-x^2/25)
    quit

我尝试将 x 更改为 r,将 y 更改为 t,将 y 更改为 theta,等等。我根本无法弄清楚 Gnuplot 想要我如何定义极坐标输入。有没有办法将 x 重新定义为 r*cos(theta) 并将 y 重新定义为 r*sin(theta),然后让我为 r 和 theta 设置输入和范围?

感谢您的帮助! :)

【问题讨论】:

    标签: unix graph coordinates gnuplot


    【解决方案1】:

    polar 模式允许您根据单个参数 t 绘制函数,该参数用作角度,参见例如gnuplot polar demo。因此,您可以为固定半径绘制一条“轨迹”。

    当您想可视化密度分布时,我认为您最好使用热图。我建议使用parametric 模式,你一个虚拟变量用作半径,另一个用作角度theta。为了更好的可读性,我相应地命名了虚拟变量(使用set dummy ...),但对于范围,您必须坚持使用原始虚拟名称uv。所以这里是一个例子:

    reset
    set terminal pngcairo size 900,800
    set output 'elec.png'
    
    set title 'Electron Density Around Molecule'
    
    set parametric
    set dummy r, theta # instead of u,v
    set urange[0:1.5*pi] # r
    set vrange[0:2*pi]   # theta
    set isosamples 200
    
    set size ratio 1
    set autoscale fix
    set pm3d map
    set palette defined (0 'white', 1 'red')
    
    splot r*cos(theta), r*sin(theta), \
          cos(r)**2 + (1 + cos(theta)**2)*exp(-r**2/25) with pm3d t ''
    

    parametric 模式下,您必须为splot 指定三个函数,具体取决于以逗号分隔的虚拟变量(此处为rtheta)。

    结果是:

    现在您可以根据需要继续并增强情节。

    【讨论】:

    • 这非常有帮助。非常感谢。无论我处理的是什么类型的方程,我现在对使用哪种模式有了更好的了解。
    猜你喜欢
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 2020-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多