如何使用GNU Plot绘制径向(极坐标)图?

10

我想要使用 gnuplot 制作一个径向(极坐标)图(即在圆形坐标系(r,theta)中)。

这里我使用了以下数值:

Theta Max-strain
0     3400
60    5300
120   4700
180   3800
240   4100
300   3100
360   3400

如何使用 GNU-plot 获取这样的图形?


3
由于0°已经包含在360°中,您可能希望在图表中删除360°,因为它是多余的。 - Woltan
2个回答

30

我试图重现你问题的情节,以下是我的成果:


unset border
set polar
set angles degrees #set gnuplot on degrees instead of radians

set style line 10 lt 1 lc 0 lw 0.3 #redefine a new line style for the grid

set grid polar 60 #set the grid to be displayed every 60 degrees
set grid ls 10

set xrange [-6000:6000] #make gnuplot to go until 6000
set yrange [-6000:6000]

set xtics axis #disply the xtics on the axis instead of on the border
set ytics axis

set xtics scale 0 #"remove" the tics so that only the y tics are displayed
set xtics ("" 1000, "" 2000, "" 3000, "" 4000, "" 5000, "" 6000) #set the xtics only go from 0 to 6000 with increment of1000 but do not display anything. This has to be done otherwise the grid will not be displayed correctly.
set ytics 0, 1000, 6000 #make the ytics go from the center (0) to 6000 with incrment of 1000

set size square 

set key lmargin

set_label(x, text) = sprintf("set label '%s' at (6500*cos(%f)), (6500*sin(%f))     center", text, x, x) #this places a label on the outside

#here all labels are created
eval set_label(0, "0")
eval set_label(60, "60")
eval set_label(120, "120")
eval set_label(180, "180")
eval set_label(240, "240")
eval set_label(300, "300")


set style line 11 lt 1 lw 2 pt 2 ps 2 #set the line style for the plot

#and finally the plot
plot "-" u 1:2 t "Max strain" w lp ls 11
0 3400
60 5300
120 4700
180 3800
240 4100
300 3100
360 3400
e

上述脚本的图形

正如您所看到的,主要区别在于角度0不在顶部而在右侧(这在数学上是正确的)。但是可以通过修改绘图中的减速度和set_label函数来更改它。

正如您在脚本中看到的,不是所有事情都很精细和闪亮。如果有人发现改进,请让我知道!

最后的“建议”:并非总是合理地尝试使用gnuplot从某些工具重现绘图。通常,gnuplot的优势在于以最简单的方式绘制数据,以便轻松复制。也许您可以从上面的脚本中去掉一些行,并仍然对其感到满意。


非常感谢,这很有帮助。我尝试按照您上面提到的方式使用set_label,但是出现了错误。如果没有标签,它可以正常工作。另外,如果存在负值,比如-3400、-5300等等...那么在上面的图中,y轴应该从0到-6000向内延伸,而不是从6000到0。就像在MS Excel中得到的图一样。如何获得这样的图? - Dolly
@Dolly,“set_label”宏在我的机器上运行正常。错误信息是什么?至于负值:在极坐标图中,您不能有负值,因为该值或多或少是半径,而半径不能为负。如果您有负值,也许您不应该使用极坐标图,或者可以使用“exp”和“log”进行映射! - Woltan
1
当我使用set_label时,图形没有被创建。当我不使用set_label时,图形被创建了。这个选项在旧的gnu-plot版本中不可用吗?我在哪里可以下载新版本? - Dolly
1
@Dolly 我不知道你需要什么版本的gnuplot才能使宏起作用。但是拥有最新版本总是一个好主意。你可以从这里获取它们。 - Woltan
1
@Dolly:将字符串 "-" 替换为包含值的文件名。就像这样:plot "Data.dat" u 1:2 ... - Woltan
显示剩余2条评论

6

2
谢谢。我已经尝试使用set grid polar。但是我无法在其中显示角度,而且我必须指定x和y,得到的图与我想要的不符。我现在重新构思了我的问题。希望这次我清楚了。 - Dolly
尝试使用“用线绘制数据...”进行绘图。 - osgx
set grid polar 30 将添加每隔 30 度的网格线。 - osgx

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接