GNUPlot add labels to scatterplot - gnuplot

I am making several graphs at once with a perl script which runs gnuplot and outputs png images.
My data looks like:
3.57 3.13 2.88 3.38 A1H1'-A1H8
4.95 4.53 4.17 4.89
3.91 3.37 3.11 3.64
3.98 4.22 3.88 4.55 A1H2'-A2H1'
...
columns are x, y, y low error, and point label.
GNUPlot input is:
set xlabel 'X-Ray Distance (Angstrom)'
set ylabel 'NOESY Distance (Angstrom)'
set title 'r(AAAA) A-Form Correlation'
set terminal png size 1200, 900
set xrange[2:9]
set yrange[2:9]
set output 'correlation_AAAA.png'
plot x title 'NMR = X-Ray', \
'correlation_AAAA.dat' title 'NMR' with yerrorbars
My question is, how can I get the 5th column to show as a label for some points (not all)?
This link: http://newsgroups.derkeiler.com/Archive/Comp/comp.graphics.apps.gnuplot/2008-02/msg00094.html says it is very difficult (nigh on impossible)

I got lost in all of the GNUPlot documentation. My own fault.
Here is the minimal working solution:
set label " A4H8-A3H3'" at 7.42, 2.98
set rmargin at screen 0.92
plot x title 'NMR = X-Ray', \
'correlation_AAAA.dat' title 'NMR' with yerrorbars
pause -1
the "set rmargin" is necessary so labels don't run off the screen edge.
Thanks for your kind help Christoph. I was confused when I tried to put "using labels with yerrorbars" which GNUPlot did not like.

Related

Why gnuplot rounds data in column of vertical axis?

My old script worked fine years ago.
set terminal png background "#ffffff" enhanced fontscale 2.0 size 1800, 1400
set output 'delete.png'
w=1
x=1
z = 60
y=2
plot 'plot.in.tmp' using (column(x)/z):(column(y)) axis x1y1 with lines
exit gnuplot
reset
Now result in graph with only rounded integer points in y(vertical) axe. I dont understand why.
Example data in file:
0 -0,00 0,5 570,2 11,98 -0,121 0,000 9,6
5 -0,00 0,7 570,2 11,97 -0,002 0,012 13,2
10 -0,00 0,9 570,3 11,98 -0,004 -0,000 16,1
15 0,24 35,9 570,4 11,96 0,001 0,000 18,4
20 0,56 87,0 570,1 11,99 -0,001 -0,000 20,5
25 1,03 173,5 570,4 11,97 -0,000 0,000 23,2
30 1,61 296,4 570,3 11,96 0,002 0,000 12,4
35 2,17 422,6 570,2 11,68 0,004 0,000 8,8
40 2,81 571,6 570,2 11,37 0,010 0,001 7,5
45 3,52 752,3 570,3 11,26 0,015 0,000 7,1
50 3,97 905,0 570,2 11,69 0,075 0,006 7,4
55 4,36 1048,4 570,1 11,36 0,081 0,001 8,6
60 4,59 1156,8 570,2 11,22 0,087 0,001 10,7
Result graph:
Welcome to StackOverflow! Maybe the local setting of your system (or something in gnuplot) has changed?
The following works for me with your data.
Add a line
set decimalsign locale "german"
or
set decimalsign locale "french"
Check help decimalsign.
Syntax:
set decimalsign {<value> | locale {"<locale>"}}
Correct typesetting in most European countries requires:
set decimalsign ','
Please note: If you set an explicit string, this affects only numbers
that are printed using gnuplot's gprintf() formatting routine,
including axis tics. It does not affect the format expected for input
data, and it does not affect numbers printed with the sprintf()
formatting routine.
The answer given by theozh is correct, but it does not point out the unfortunate lack of standardization about how different operating systems report the current locale setting. For linux machines the locale strings are less human-friendly. For example instead of using something generic like "french", they subdivide into "fr_FR.UTF-8" "fr_BE.UTF-8" "fr_LU.UTF-8" etc to account for slight differences in the conventions used in France, Belgium, Luxembourg, etc.
I cannot tell you the exact set of locale descriptions on your machine, but here is what works for me on a linux machine:
set decimalsign locale "fr_FR.UTF-8"
w=1
x=1
z = 60
y=2
plot 'plot.in.tmp' using (column(x)/z):(column(y)) axis x1y1 with lines

why only the first row of data was plotted [GNUPlot]

I have a data file data.txt, and data are as follows.
352 0.523240374 0.522909505 0.523471053
450 0.521095585 0.518197521 0.521120231
571 0.514979782 0.517518353 0.517105300
856 0.517216354 0.517600585 0.515035365
1259 0.514126520 0.514697120 0.514651830
2302 0.510628639 0.510990627 0.511418731
5276 0.507016704 0.507616124 0.505787979
And I wrote a gnuplot script plot.gpl, the code is
set term pdf enhanced font "Sans, 12"
set grid
set xlabel "Num of Cell"
set xrange [0:5500]
set ylabel "Numerical result"
set yrange [0.5:0.53]
set output "pic.pdf"
file = "data.txt"
plot file u 1:2 with linespoints ls 1 lw 0.1 ps 0.4 title "M11",\
file u 1:3 with linespoints ls 2 lw 0.1 ps 0.4 title "M22",\
file u 1:4 with linespoints ls 3 lw 0.1 ps 0.4 title "M33"
Then I typed the command gnuplot plot.gpl, a pdf file was generated, but only the first row of data.txt was plotted.
I tried to modify the format of data.txt, but failed.
Anyone can help me to solve this problem?
PS: Windows 10 Home, MSYS2: Mingw-w64 64 bit, gnuplot 5.2.0
For the sake of not letting this question appear unanswered. I guess according to SO "rules": no answers in comments.
Looks like you only have one line of data. Do you maybe have a text file which has been created on MacOS? Could you check your line end character? Is it \n (LF) (Linux) or \r\n (CR LF) (Windows) or \r (CR) (MacOs)? In the latter case you would get only the first row like you get.

Gnuplot only Plotting one Dot instead of all data

I am trying to plot time vs entropy of a data. When I run the script, it just produces a graph with one dot on y axis and no plot. Here is my script:
set terminal png
set output 'output.png'
set xdata time
set timefmt '"%Y-%m-%d %H:%M:%S"'
set format x '"%Y-%m-%d %H:%M:%S"'
set xrange ['"2008-01-01 00:00"':'"2008-03-20 00:00"']
set yrange [0.5:2.4]
set style data lines
set xlabel "Time"
set ylabel "Entropy"
plot "foobar-entropy.txt" using 1:2 w lp ls 4 lw 3
And here is the data:
"2008-01-01 02:13:38" 1.0
"2008-01-10 02:12:13" 1.5
"2008-01-20 02:11:55" 1.459
"2008-01-30 02:10:28" 1.811
"2008-02-10 02:09:44" 1.722
"2008-02-20 02:08:00" 1.65
"2008-02-28 02:07:00" 2.149
"2008-03-10 02:06:00" 2.18
"2008-03-20 02:04:00" 2.33
Any help would be appreciated.
Finally, found the mystery after #Christoph told about the line breaks. The issue was that the file had different line endings which gnuplot do not support.
When I opened the file with vi editor it appeared as follows:
"2008-01-01 02:13:38" 1.0^M
"2008-01-10 02:12:13" 1.5^M
"2008-01-20 02:13:55" 1.459^M
"2008-01-30 02:12:28" 1.811^M
"2008-02-10 02:12:44" 1.722^M
"2008-02-20 02:13:00" 1.65^M
"2008-02-28 02:13:00" 2.149^M
"2008-03-10 02:13:00" 2.18^M
"2008-03-20 02:13:00" 2.33^M
After running the command dos2unix on the file, it changed the old-style carriage-return characters to linefeeds and it works fine now.

Plot a list of matrices at heights in 3d scatter plot

I have a file with a number of matrices separated by a newline. I can plot any one of these matrices as a heatmap as shown in http://gnuplot.sourceforge.net/demo/heatmaps.html
However, now I would like to visualize all the matrices together on the same graph by plotting each matrix at increasing values of z, where each point is a coloured dot. I am trying to achieve something similar to the following question,
Plot 3D Grid Data as Heat Map using gnuplot
but without the cubes, as dots are sufficient.
This is the data for one matrix:
7.606193E-01 -2.706752E-01 1.605924E-01 9.973101E-01 6.646065E-01 -4.177295E-01 -5.101588E-01 -5.338852E-01 -9.443505E-01 6.273689E-01 4.401633E-01 9.428387E-01 -1.783963E-01 1.702644E-01 -9.304313E-01 3.995178E-01
-1.574189E-01 -3.911715E-01 -5.581077E-01 -3.719385E-02 7.144460E-01 -3.147125E-01 4.237802E-01 6.533050E-01 5.385187E-01 8.391651E-02 -5.773817E-01 1.456075E-01 6.028832E-01 5.313966E-01 3.894490E-01 7.329324E-01
8.147309E-01 -8.286917E-01 -9.708381E-01 -6.634787E-02 8.603123E-01 8.952920E-01 6.777392E-01 4.347730E-01 -9.271995E-01 8.899992E-01 5.525438E-01 -7.496139E-01 7.592094E-01 3.412833E-01 1.220876E-01 7.281239E-01
6.915789E-01 3.365000E-01 -4.771788E-01 7.674200E-01 8.059295E-01 3.545558E-01 2.764826E-01 3.801301E-01 -6.679796E-01 1.163551E-01 -5.292152E-01 -3.500514E-01 -8.614216E-01 -8.356531E-02 -8.391827E-01 7.258298E-01
1.219247E-01 5.344889E-01 8.977039E-01 -5.708083E-01 -6.809624E-01 -5.687558E-01 3.830947E-01 9.990373E-01 -6.038938E-01 9.162573E-01 -4.214753E-01 4.186414E-01 -4.224649E-01 -9.376176E-01 -1.170071E-01 3.825447E-01
-1.046988E-01 5.206562E-01 -9.832160E-01 -6.588389E-01 6.122716E-01 2.926736E-01 -8.736564E-01 9.977460E-01 8.937872E-01 -8.719974E-02 -7.742046E-01 -9.490100E-01 6.090313E-01 8.220433E-01 7.705420E-01 5.937839E-01
8.668659E-01 -5.811435E-01 -4.980876E-01 -5.458175E-02 -1.702000E-01 -9.681295E-01 -9.898823E-01 8.014537E-01 6.852101E-01 3.412942E-01 -4.313660E-01 6.886256E-01 -8.974125E-01 8.012120E-01 7.893018E-01 -1.869330E-01
-1.168977E-01 -8.988775E-01 -2.580437E-01 -8.019403E-02 4.935626E-01 3.774684E-01 5.609375E-02 8.018482E-01 -9.803250E-01 -8.223162E-01 -7.441623E-02 7.592162E-01 -3.084599E-01 2.728176E-01 -7.114622E-01 -4.335231E-01
9.071215E-01 7.551532E-01 1.640213E-02 -2.627113E-01 -1.102158E-01 -3.576760E-02 7.584369E-02 3.586933E-01 9.412469E-01 -7.919924E-01 -7.883645E-01 -4.693788E-01 -1.549372E-01 1.823575E-01 4.206510E-01 -4.489097E-01
2.449895E-01 -4.566137E-02 5.805491E-01 3.808071E-01 4.885185E-01 9.662528E-01 -9.306209E-02 2.467101E-02 2.380986E-01 -9.053143E-01 -3.499831E-01 -4.224079E-01 -2.420047E-01 1.568254E-01 -1.696076E-01 -2.344714E-01
-1.045739E-01 -2.254802E-01 -5.760012E-01 7.194423E-01 9.792110E-01 -7.514746E-01 -1.239218E-01 -3.922474E-01 -6.499553E-01 5.908898E-01 8.695512E-01 -6.576686E-01 7.101708E-01 6.389254E-01 -3.228182E-01 3.177363E-01
-7.059239E-01 -8.482834E-01 -1.630977E-01 -9.891499E-01 -5.450270E-01 -6.303106E-01 1.596098E-01 -2.695453E-01 1.340886E-01 -3.888265E-01 -4.888381E-02 1.609239E-01 3.058087E-01 7.288026E-01 9.176123E-01 2.593470E-02
-5.400585E-01 8.222967E-01 3.648388E-01 -6.635013E-01 -4.210275E-01 -2.741717E-01 1.431661E-01 -2.184412E-01 -6.006791E-01 -9.289613E-03 2.788451E-01 -2.769694E-01 -9.857075E-01 -5.143206E-01 -1.455316E-01 9.782214E-01
-7.254217E-01 -1.668047E-01 -7.403084E-01 5.606276E-01 1.713349E-01 8.025852E-01 -9.133063E-01 -3.648469E-01 9.402033E-01 -2.317766E-01 7.771178E-01 8.427679E-01 5.951350E-02 9.725678E-01 7.514953E-01 -2.132574E-02
3.962623E-01 -8.680837E-01 -6.393657E-01 7.831294E-01 -5.947012E-02 -9.781432E-01 -8.829182E-01 -9.939770E-01 7.487056E-02 -7.578757E-01 6.196460E-01 -7.909356E-01 -1.149577E-01 -2.736676E-01 2.013560E-01 5.961972E-02
7.165400E-01 -2.371667E-01 -7.857778E-01 7.715441E-01 5.449374E-01 2.804987E-02 -1.380231E-01 -5.877602E-01 3.679530E-01 3.016719E-01 -5.242305E-01 1.064826E-01 -6.910435E-02 7.062310E-01 8.472682E-02 -9.717143E-01
I am not sure if I understood correctly, but it seems that you want each matrix as a heatmap at a fixed (arbitrary) z-value.
As mentioned on the link you posted, making a plot like that one would require (at least to my knowledge) a lot of scrambling around on gnuplot. However, you could have a rough idea by doing:
set term png
set out "tmp.png"
set view 80,30
splot "tmp" matrix u 1:2:(2):3 w p pt 5 ps 0.75 pal,\
"tmp" matrix u 1:2:(1):3 w p pt 5 ps 0.75 pal,\
"tmp" matrix u 1:2:(0):3 w p pt 5 ps 0.75 pal
Which would give you:
Not pretty, but works. You'd have to play around with the labels, tics and view parameters depending on how many matrices you have. Hope it helps!
You could splot each matrix with image:
set ztics 1
set ticslevel 0
stats "data.dat" matrix nooutput
set xrange [-0.5:STATS_size_x - 0.5]
set yrange [-0.5:STATS_size_y - 0.5]
splot for [i=1:3] "data.dat" matrix using 1:2:(i):3 with image notitle
Or, depending on your need, you can also splot ... with pm3d:
set view 70,23
set ztics 1
set ticslevel 0
set pm3d interpolate 5,5
set autoscale xfix
set autoscale yfix
splot for [i=1:3] "data.dat" matrix using 1:2:(i):3 with pm3d notitle

How plot graph with missing data lines?

I have data recorded in time. But some data lines are missing and gnuplot replace them with long lines in these intervals.
How can i set gnuplot to draw nothing instead of draw lines in these intervals?
PS. I don't have free cells in these lines, I dont have these lines at all.
lines:
column 1 ... col 195
13:30:20.8 0.78061899
13:30:21.8 5.969546498
13:32:19.8 17.21257881
13:32:20.8 6.922475345
If you don't want to draw a line between two points you must insert an empty line in the data file between the two point entries, so that effectively you have
13:30:20.8 0.78061899
13:30:21.8 5.969546498
13:32:19.8 17.21257881
13:32:20.8 6.922475345
This cannot be done with gnuplot directly, but you can use e.g. awk to do the processing on-the-fly:
set timefmt '%H:%M:%S'
set xdata time
filename = 'data.txt'
plot 'awk ''{split($1,d,":"); t_prev = t; t = (d[1] * 60 + d[2])*60 + d[3]; if (t_prev && (t - t_prev > 10)) print ""; print }'' '.filename with lines
Here, the gap threshold is 10 seconds.
I suppose your miss data identifier is "NaN", then you can use the following command
plot "data" using 1:($2) with linespoints
instead of
plot "data" using 1:2 with linespoints
The former one will ignore the missing data and treat it as blank line and therefore not draw a connecting line across the gap while the latter one will draw continuous, unbroken line.
Just for the records: there are later questions about the same/similar issue.
Avoid connection of points when there is empty data
How to remove line between "jumping" values, in gnuplot?
Removing vertical lines due to sudden jumps in gnuplot
However, my solutions there require transparent color, which was not available in at the time of OP's question (gnuplot 4.6.5, Feb 2014). Nevertheless, there is a solution without external tools like awk or changing the data.
First solution for gnuplot 4.6.: Instead of a transparent line you use a white line which, however, will cover the grid lines, although it will be hardly visible.
Second solution for gnuplot 4.6 is using vectors. This really interrupts the line and will work for gnuplot 5.x as well.
Data:
00:00:00 0.406406
00:00:44 0.339779
00:01:28 0.986602
00:02:13 0.17746
00:02:57 0.0580277
00:03:42 0.586614
00:04:26 0.84247
00:05:11 0.597502
00:05:55 0.0394846
00:06:40 0.369416
00:13:20 0.527109
00:13:42 0.371411
00:14:04 0.851465
00:14:26 0.980312
00:14:48 0.431391
00:15:11 0.545491
00:15:33 0.708445
00:15:55 0.861669
00:16:17 0.277122
00:16:40 0.787273
Script:
### avoid showing a line across larger time gaps
reset
FILE = "SO26510245.dat"
myFmt = "%H:%M:%S"
tGap = 60 # 60 seconds
set format x "%H:%M"
set timefmt "%H:%M:%S"
set xdata time
set ytics 0.5
set key top center noautotitle
set grid x,y
set multiplot layout 3,1
plot FILE u 1:2 w l lc rgb "red" ti "data as is"
myColor(col) = (t0=t1, t1=timecolumn(1), t1-t0>tGap ? 0xffffff : 0x0000ff)
plot t1=NaN FILE u 1:2:(myColor(1)) w l lc rgb var ti "white line"
myGap(col) = (t1-t0>tGap ? NaN : y0)
plot t1=y1=NaN FILE u (t0=t1,t1=timecolumn(1),t0):(y0=y1,y1=$2,myGap(0)):(t1-t0):(y1-y0) \
w vec lc rgb "web-green" nohead ti "with vectors"
unset multiplot
### end of script
Result: (created with gnuplot 4.6.0, from March 2012)

Resources