Gnuplot的簡介與常用操作

Gnuplot

簡介

​ Gnuplot是一個命令行的交互式繪圖工具(command-driven interactive function plotting program)。

​ 用戶通過輸入命令,可以逐步設置或修改繪圖環境,並以圖形描述數據或函數,使我們可以藉由圖形做更進一步的分析。

​ Gnuplot是由Colin Kelly和Thomas Williams於1986年開始開發的科學繪圖工具,支持二維和三維圖形。它的功能是把數據資料和數學函數轉換爲容易觀察的平面或立體的圖形,它有兩種工作方式交互式方式批處理方式,它可以讓使用者很容易地讀入外部的數據結果,在屏幕上顯示圖形,並且可以選擇和修改圖形的畫法,明顯地表現出數據的特性。

概況

Gnuplot 4.6 中文手冊於2012-10-11 翻譯完成

CSDN參考網址:https://baike.so.com/doc/222231-235089.html:《gnuplot 4.6中文手冊》

Windows下的安裝

百度網盤鏈接:https://pan.baidu.com/s/1-xhnW1RlcmbVWAfyOABOaA下載

提取碼: 7678

然後安裝win64的exe安裝包,這裏我們的安裝路徑爲D:\gnuplot。

然後到這個目錄的下查找bin這個目錄,在bin目錄下有一個名爲wgnuplot.exe的文件,雙擊該文件,就出現了GUI界面的gnuplot

至此,你已經成功安裝了gnuplot.

Gnuplot的簡單操作

1.打開方式

打開方式1:在bin目錄下打開爲wgnuplot.exe的文件
在提示符下面輸入:

plot [-3.14:3.14] sin(x)

在這裏插入圖片描述
在提示符下面輸入:

plot [-3.14:3.14] sin(x)

然後就可以看到結果.

上面有橫軸有縱軸,還有圖例.

在這裏插入圖片描述
如果你不需要上面的圖例,你可以在運行:

unset key

plot[-3.14:3.14]sin(x)

在這裏插入圖片描述
如果要還原

 set key default
    
    plot[-3.14:3.14]sin(x)

然後再運行上面的繪圖命令就可以實現沒有圖例或者恢復圖例的效果了在這裏插入圖片描述
改變圖例的風格

set key top left

plot [-pi:pi] sin(x) title 'sin(x)' with linespoints pointtype 5

在這裏插入圖片描述
一般情況下使用gnuplot都是科學繪圖,因此很多都是放在文章裏面。一般優秀的科技文獻都是用latex來編寫的,所以gnuplot提供了直接輸出 tex文件的功能,只需要把output設置爲latex就可以了。

如果覺得線條顏色和類型不喜歡可以修改參數調整

plot sin(x) with line linetype 3 linewidth 2 或
plot sin(x) w l lt 3 lw 2
 #用線畫,線的類型(包括顏色與虛線的類型)是3,線的寬度是2,對函數sin(x)作圖

在這裏插入圖片描述

plot sin(x) with point pointtype 3 pointsize 2 或
plot sin(x) w p pt 3 ps 2    
#用點畫,點的類型(包括顏色與點的類型)是3,點的大小是2

在這裏插入圖片描述
其中with 之後的類型可以是以下這些類型中的一種

{ lines, points, linespoints, impulses, dots, steps, fsteps, histeps, errorbars, labels, xerrorbars,
yerrorbars, xyerrorbars, errorlines, xerrorlines, yerrorlines, xyerrorlines, boxes, histograms, filledcurves, boxerrorbars, boxxyerrorbars, financebars, candlesticks, vectors, image, rgbimage , pm3d}.
一些常用基本類型
with linespoints 畫點線
linestyle 連線風格(包括linetype,linewidth等)
linetype 連線種類
linewidth 連線粗細
linecolor 連線顏色
pointtype 點的種類
pointsize 點的大小

打開方式二:配置變量,在命令提示符窗口輸入gnuplot打開

爲了方便之後的使用,配置環境變量(D:\gnuplot\bin),使其在命令窗口調出使用
在這裏插入圖片描述

2.查看gnuplot的測試圖

test

在這裏插入圖片描述

3.對圖形進行命名和添加座標抽

set title 'figure 1'#圖形標題
set xlabel 'x'#命名x軸
set ylabel 'sin(x)'#命名y軸
plot sin(x)#畫出sin(x)的圖像

在這裏插入圖片描述

4.改變軸上的tic並設置網格

set title "figure 1"
set xrange [-pi:pi] 
set xtics ('0' 0, '90' pi/2, '-90' -pi/2, '45' pi/4,'-45' -pi/4,'135' 3*pi/4,'-135'-3*pi/4)
#使在橫座標值爲90度時,sin(x)恰好在pi/2處
set grid
set xlabel 'Angle, in degrees'
set ylabel 'sin(angle)'
plot sin(x)

在這裏插入圖片描述

5.一頁多圖的操作

set xrange [-pi:pi]

#gnuplot recommends setting the size and origin before going to multiplot mode
#This sets up bounding boxes and may be required on some terminals
set size 1,1
set origin 0,0

#Done interactively, this takes gnuplot into multiplot mode
set multiplot

#plot the first graph so that it takes a quarter of the screen
set size 0.5,0.5
set origin 0,0#(2,2,1)
plot sin(x)

#plot the second graph so that it takes a quarter of the screen
set size 0.5,0.5
set origin 0,0.5#(2,2,2)
plot cos(x)

#plot the third graph so that it takes a quarter of the screen
set size 0.5,0.5
set origin 0.5,0#(2,2,3)
plot 1/cos(x)

#plot the fourth graph so that it takes a quarter of the screen
set size 0.5,0.5
set origin 0.5,0.5#(2,2,4)
plot tan(x)

unset multiplot #close multiplot

在這裏插入圖片描述

6.更多操作說明可進入help plot中查看

help 

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章