Hilmi Egemen Ciritoglu Personal Webpage


Let’s assume you have text file like that:

# Results.dat
# Months 6months 1year
# ——————————————

3 27 10
4 52 50
5 61 89
7 78 92
8 82 112
9 120 118
10 124 125

And you want to plot line chart but you don’t want to use excel or any other spreadsheet application. By the way I am kind of person who loves Microsoft tools they are make our life easier. (Like I am writing this blogpost on Word) But sometimes especially when I tried change something in chart. I always lost myself inside complex GUI even though they are good about simplifying GUI either. Nowadays, because I had to write article. My mentor recommended to me use GNU Plot. First I thought what is why we can’t use Excel. But now I really liked GNU PLOT, it is super cool.

Let’s back to our subject after talking about details…

Installation GNUPLOT

I think it’s straight for Linux environment. But if you’re MAC user like me for now. It’s bit harder than Linux to install, you need to install gnuplot_qt. You can install like that:

brew cask install xquartz

brew install gnuplot –with-x11

Now we are in fun part.

I am assuming your data named as a Results.dat also you’re in same directory with your data file.

For creating chart

plot ‘Results.dat’ u 1:2 w lp t ‘6 months’ -> It will create chart for only first data column

For adding another line to chart:
plot ‘Results.dat’ u 1:2 w lp t ‘6 months’,’Results.dat’ u 1:3 w lp t ’12 months’

Furthermore, you can use point instead of lines. For doing that just change lp top.

plot ‘Results.dat’ u 1:2 w lp t ‘6 months’,’Results.dat’ u 1:3 w p t ’12 months’

But we can customize our charts:

For changing x-axis label font -> set xlabel “Time” font “Helvetica,18”

Or y-axis label font pretty much same only need to use ylabel instead of xlabel.

Let’s change x axis label’s -> set xtics font “Helvetica,12”

Then maybe we would like to change line thickness -> just add to lw 2

End of your plot command as argument so it’s look like this:

plot ‘Results.dat’ u 1:2 w lp t ‘6 months’ lw 2

For changing line colour: lc 1 # or some other number

For changing dash type: dashtype 2 # or some other number

That’s all from now. This blogpost mostly about introducing GNU Plot. I should say I really liked it. It saved me from Excel’s GUI. I would prefer to write one more word or even line rather than trying to remember where it was in GUI.