'프로그램 사용/gnuplot'에 해당되는 글 2건

  1. 2023.06.07 gnuplot 예제
  2. 2022.06.13 gnuplot

gnuplot이 논문 등에서 그래프 그리는 용도로 많이 언급되는데 써보는건 첨인듯..

 

인터프리터(?)에서 아래와 같이 명령을 주면 된다고 한다.

gnuplot:> splot [2:-1] [-1:2] 3*x**2 + 2y**2

[링크 : https://namu.wiki/w/gnuplot]

 

혹시나 해서 gnuplot-qt를 깔았는데 저 gui가 qt 기반인건가?

$ gnuplot

G N U P L O T
Version 5.4 patchlevel 2    last modified 2021-06-01 

Copyright (C) 1986-1993, 1998, 2004, 2007-2021
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')

Terminal type is now 'qt'
gnuplot> splot [2:-1] [-1:2] 3*x**2 + 2y**2
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.

gnuplot> splot [2:-1] [-1:2] 3*x**2 + 2y**2
                                       ^
         unexpected or unrecognized token: y

gnuplot> quit

 

아무튼 이쁘게 잘 그려준다.

 

csv 파일을 그리려면 ,를 구분자로 설정해주면 되고

set datafile separator ','
plot "test.csv" using 0:1 with lines

[링크 : https://raymii.org/s/tutorials/GNUplot_tips_for_nice_looking_charts_from_a_CSV_file.html]

[링크 : https://stackoverflow.com/questions/48885697/gnuplot-graph-csv]

 

using 뒤에 숫자는 X 축과 Y축에 대해서 설정하는 것이고, 기본적으로 1 열에 대해서만 그래프를 그려준다.

using 1:3 파일에 있는 1열(X축)과 3열(Y축)을 사용하겠음

[링크 : https://m.blog.naver.com/gfeel323/40201727680]

 

여러 열을 한 그래프에 그리고 싶으면 아래와 같이  , "" 하고 using 구문을 추가해도 되고, for 문을 이용해서 반복해도 된다.

> plot "tt.csv" using 0:1 with lines, "" using 0:2 with lines
> plot for [col=1:4] 'file' using 0:col with lines

[링크 : https://stackoverflow.com/questions/16073232/gnuplot-plotting-a-file-with-4-columns-all-on-y-axis]

[링크 : https://raymii.org/s/tutorials/GNUplot_tips_for_nice_looking_charts_from_a_CSV_file.html]

 

만약 csv 파일에 일련번호로 쓸 내용이 없다면(대개는 시간이 있긴 하지만)

아래의 명령을 이용하여 x 축에 pseudocolumns를 추가해줄 수 있다고 한다.

가장 편한건 x축 지정하지 않는 using n이 무난한 듯.

plot "file.dat" using (column(0)):3

You can even use plot "file.dat" using 0:3
Or, as pointed out in the other answer, even plot "file.dat" using 3

[링크 : https://stackoverflow.com/questions/9664472/having-automatic-x]

 

stackoverflow에 내용을 참조해서 도움말을 보니 column("컬럼명") 혹은 column("컬럼 번호") 로 쓰는데

인덱스는 0부터가 아니라 1부터 시작되는 듯

gnuplot> help plot datafile using
// 생략
 if the data file contains
       Height    Weight    Age
       val1      val1      val1
       ...       ...       ...
 then the following plot commands are all equivalent
       plot 'datafile' using 3:1, '' using 3:2
       plot 'datafile' using (column("Age")):(column(1)), \
                    '' using (column("Age")):(column(2))
       plot 'datafile' using "Age":"Height", '' using "Age":"Weight"

 

그렇기에 (column(0)) 을 해주면 되는데 column(0)에러 난다.(!)

gnuplot> help plot datafile using pseudocolumns
 Expressions in the `using` clause of a plot statement can refer to additional
 bookkeeping values in addition to the actual data values contained in the input
 file. These are contained in "pseudocolumns".
       column(0)   The sequential order of each point within a data set.
                   The counter starts at 0, increments on each non-blank,
                   non-comment line, and is reset by two sequential blank
                   records.  The shorthand form $0 is available.
       column(-1)  This counter starts at 0, increments on a single blank line,
                   and is reset by two sequential blank lines.
                   This corresponds to the data line in array or grid data.
                   It can also be used to distinguish separate line segments
                   or polygons within a data set.
       column(-2)  Starts at 0 and increments on two sequential blank lines.
                   This is the index number of the current data set within a
                   file that contains multiple data sets.  See `index`.
       column($#)  The special symbol $# evaluates to the total number of
                   columns available, so column($#) refers to the last
                   (rightmost) field in the current input line.
                   column($# - 1) would refer to the last-but-one column, etc.

 

터미널 변경은 set terminal을 쓰면 된다.

$ gnuplot

G N U P L O T
Version 5.4 patchlevel 2    last modified 2021-06-01 

Copyright (C) 1986-1993, 1998, 2004, 2007-2021
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')

Terminal type is now 'qt'

gnuplot> set terminal dumb
Terminal type is now 'dumb'
Options are 'feed  size 79, 24 aspect 2, 1 mono'

[링크 : https://www.postgresql.kr/blog/gnuplot_dumb_terminal.html]

 

같은 그래프를 dump과

 

qt로 설정해서 출력한 모양

 

qt 에서 휠 드래그로 중심이동은 안되고

ctrl - wheel로 x축, y축 확대

ctrl - shift- wheel은 x 축 확대

shift - wheel 혹은 alt -wheel 로 x축 이동

wheel 로 y 축 이동이 기본 값으로 지정된다.

'프로그램 사용 > gnuplot' 카테고리의 다른 글

gnuplot  (0) 2022.06.13
Posted by 구차니
프로그램 사용/gnuplot2022. 6. 13. 19:12

그래프 그리는 유틸리티. 써본적이 있던가?

 

$ gnuplot

Command 'gnuplot' not found, but can be installed with:

sudo apt install gnuplot-nox
sudo apt install gnuplot-qt
sudo apt install gnuplot-x11

 

[링크 : https://alvinalexander.com/technology/gnuplot-charts-graphs-examples/]

[링크 : https://stackoverflow.com/questions/30315114/]

'프로그램 사용 > gnuplot' 카테고리의 다른 글

gnuplot 예제  (0) 2023.06.07
Posted by 구차니