極坐標作圖(上)


        極坐標作圖不像直角坐標作圖那么容易,所以極坐標作圖有專門的軟件,比如EMCAR和Polar Chart, 前者是開源的,有興趣的伙伴們可以去sourceforge下載: Antenna Measurement Range Using LinuxCNC, 但是目前版本比較低,至今依然是 2015-10-09 上傳emcar-0.1.tar, 可能還是對一些特定問題進行處理;后者是收費軟件,圖形界面比較美觀,但是從它的輸入界面來看,貌似只能對有規律的函數做圖,有點像給教學演示做的數學軟件。一般搞科研工作者或工程師面對的實際上具有極坐標性質的數據集,但是形態各異,情況復雜。Gnuplot就具有這樣強大的功能,例如:

   

上面三個圖的輸入文件分別是:

set polar
unset tics
set rtics 0.2 format ""
set border 0 lt 0    
set grid polar pi/12
set term pngcairo enh font "Arial,20" size 500,500
set out "polar_filledcurves.png"
set size ratio -1
set rrange [0:1]
set samp 200
plot cos(2.5*t)**2 w filledc above r=0.15 lc rgb "magenta"

 和

set polar
set border 0 lt 0
unset tics
set rtics 0.2 format ""
set grid polar
set term pngcairo enh font "Arial,20" size 500,500
set out "polar_impulses.png"
set size ratio -1
set rrange [0:1]
plot cos(2.5*t)**2 w imp  lw 2 

 以及

set polar
unset tics
set rtics format ""
set grid polar
set border 0 lt 0        
set term pngcairo enh font "Arial,20" size 500,500
set out "polar_alpha.png"
set size ratio -1
set samp 200
set title "Version 4.6 patchlevel 2" font ",20"
plot cos(2.5*t)**2 w filledc lc rgb "green", \
     sin(2.5*t)**2 w filledc lc rgb "#80cc0099"

你會發現,這些圖依然缺少什么,對了,就是坐標標注,像下面這樣的:

 他們的繪圖語句集分別為

set polar
set grid polar 
unset xtics
unset ytics
set border 0.9 lt 2
set term pngcairo enh font "Arial,20" size 500,500
set out "polar_fig1.png"
set style fill solid 0.5
set rrange [0.1 : 4]
set size square
set key title "bounding radius 2.5"
# set key outside top right samplen 0.7
plot 3.+sin(t)*cos(5*t) with filledcurve above r=2.5 notitle,\
     3.+sin(t)*cos(5*t) with line

 和

set ter pngcairo enh lw 1.2 color size 600,550
set output 'polar.png'
set title "Angle labels (ttics) for polar plots" offset 0,1
set polar
set ttics 0,30 format "%g".GPVAL_DEGREE_SIGN font ":Italic"
set mttics 3
set grid r polar 60
unset xtics
unset ytics
set border 0
set size square
unset key
set rrange [0:6.1]
if (GPVAL_ENCODING eq "utf8") {
    set ttics add ("π" 180, "π/2" 90, "3π/2" 270)
} else {
    set ttics add ("pi" 180, "pi/2" 90, "3pi/2" 270)
}
plot t lt 3 lw 2, -t lt 4 lw 2
set title "Polar plot with border and rotated labels for ttics"
set ttics rotate
set rrange [0:6.5]
set border polar
replot

但是,這種圖依舊不盡人意:首先是坐標網格基本看不見,其次坐標標注的字體很難隨意改動。大多數伙伴都認為繼續優化上面的代碼估計就可以做出非常美觀的圖片了,其實不然,比如上面左圖的代碼去掉,你會發現圖像比例嚴重失調。其實上面第一排圖的第三個嚴格上使用gnuplot的4.7版本做的,4.6就有些勉為其難了。而第二排圖的第一個是在5.0版本中做的(gnuplot version gnuplot 5.0 patchlevel 5)第二個本應該在5.4版本中做的(gnuplot version gnuplot 5.4.rc0 patchlevel rc0),它們在4.6版本中是實現不了的,我是在5.2版本中做的(北京超算雲D分區-BSCC-D):

    G N U P L O T
    Version 5.2 patchlevel 7    last modified 2019-05-29 

    Copyright (C) 1986-1993, 1998, 2004, 2007-2018
    Thomas Williams, Colin Kelley and many others

    gnuplot home:     http://www.gnuplot.info
    faq, bugs, etc:   type "help FAQ"
    immediate help:   type "help"  (plot window: hit 'h')

因此,從應用便捷程度來說,gnuplot的強大功能在極坐標情形下已經不怎么靈活了,而且不能總是遇到一種新的情況就升級一下軟件的。所以,下一個目錄先展示一種在gnuplot低版本中可以靈活處理但比較繁瑣的方式,再來探討下怎么利用Matlab來實現想要的效果。

 

參考鏈接:

[1] A new and improved Emacs gnuplot DSL;Enhanced Machine Controller Antenna Range (EMCAR)

[2] gnuplot demo script: ttics.dem;gnuplot demo script-polar.dem;2次元極座標系;Polar Chart

[3] Generated on 08-Jan-2020 20:52:28 by html_compare_plot_demos with GNU Octave 6.0.0

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM