GnuPlot :: Plotting 3D recorded in an unconventional format - csv

I would like to prepare a script file to draw a 3D plot of some kinetic spectroscopy results. In the experiment the absorption spectrum of a solution is measured sequentially at increasing times from t0 to tf with a constant increase in time Δt.
The plot will show the variation of absorbamce (Z) with wavelength and time.
The data are recorded using a UV-VIS spectrometer and saved as a CSV text file.
The file contains a table in which the first column are the wavelengths of the spectra. Afterwards, a column is added for each the measured spectra, and a number of columns depends on the total time and the time interval between measuerments. The time for each spectra appears in the headers line.
I wonder if the data can be plotted directly witha minimum of preformatting and without the need to rewrite the data in a more estandar XYZ format.
The structure of the data file is something like this
Title; espectroscopia UV-Vis
Comment;
Date; 23/10/2018 16:41:12
Operator; laboratorios
System Name; Undefined
Wavelength (nm); 0 Min; 0,1 Min; 0,2 Min; 0,3 Min; ... 28,5 Min
400,5551; 1,491613E-03; 1,810312E-03; 2,01891E-03; ... 4,755786E-03
... ... ... ... ... ...
799,2119; -5,509266E-04; 3,26314E-04; -4,319865E-04; ... -5,087912E-04
(EOF)
A copy of a sample data is included in this file kinetic_spectroscopy.csv.
Thanks.

Your data is in an acceptable form for gnuplot, but persuading the program to plot this as one line per wavelength rather than a gridded surface is more difficult. First let's establish that the file can be read and plotted. The following commands should read in the x/y coordinates (x = first row, y = first column) and the z values to construct a surface.
DATA = 'espectros cinetica.csv'
set datafile separator ';' # csv file with semicolon
# Your data uses , as a decimal point.
set decimal locale # The program can handle this if your locale is correct.
show decimal # confirm this by inspecting the output from "show".
set title DATA
set ylabel "Wavelength"
set xlabel "Time (min)"
set xyplane 0
set style data lines
splot DATA matrix nonuniform using 1:2:3 lc palette
This actually looks OK with your data. For a smaller number of scans it is probably not what you would want. In order to plot separate lines, one per scan, we could break this up into a sequence of line plots rather than a single surface plot:
DATA = 'espectros cinetica.csv'
set datafile separator ";"
set decimal locale
unset key
set title DATA
set style data lines
set ylabel "Wavelength"
set xlabel "Time (min)"
set xtics offset 0,-1 # move labels away from axis
splot for [row=0:*] DATA matrix nonuniform every :::row::row using 1:2:3
This is what I get for the first 100 rows of your data file. The row data is colored sequentially by gnuplot linetypes. Other coloring schemes are possible.

Related

reverse tail for gnuplot

I would like to display data in a repeated online diagram with:
plot "tail -140 logging.dat | tac -r" with lines
I get an error message file cannot be opened, however in CLI it gives the reverse list of data as expected. Could anyone help me with the correct syntax, please?
Just for the records, here is a gnuplot-only, hence platform-independent solution. Check via stats the total number of lines. If there are less than N lines (here: 140), all lines will be plotted, otherwise only the 140 last ones.
Remark: if you do plot ... with lines, gnuplot will plot column 1 as x and column 2 as y per default. However, the output graph will look the same whether you reverse the data or not. So, I don't see why reversing the data would be necessary, unless you want to plot something what you haven't shown here or e.g. list a reversed table as text.
Script:
### plot N last lines of a file
reset session
FILE = "SO55221113.dat"
# create some random test data
set table FILE
set samples 1000
y0 = rand(0)
plot '+' u 1:(y0=y0+rand(0)-0.5)
unset table
N = 140
stats FILE u 0 nooutput # get total number of lines into STATS_records
M = STATS_records<=N ? STATS_records : STATS_records-N
plot FILE u 1:2 w l lc rgb "green" ti "all values", \
'' u 1:2 every ::M w l lc rgb "red" ti sprintf("last %d values",N)
### end of script
Result:

Reading from csv and plotting Date on x

I am new to gnuplot and got stuck in plotting two trend lines. The file is tracking how investiments of two profiles: low and high risk. Now I want to plot a trend line, as in the below R base plot, but using gnuplot. My data file looks like:
date,investpercent,expenses,savings,low,high,objective
2015-09-25,5.0,1.0,2.0,1,2,2.0
2016-09-25,6.0,1.0,2.0,1,2,2.0
2017-09-26,6.0,1.0,2.0,2,4,2.0
2018-09-27,5.0,40.0,60.0,10,40,-49904.0
2018-09-27,5.0,40.0,60.0,20,50,-169960.0
set key autotitle columnhead
plot '~/Downloads/finances.csv' using 1:5
I am using autotitle because of the header in the first line, it removes an error, but obviously sets a title, which I don't need. It would be nice to know how to ignore the headers too.
My question is:
How can I plot the trend using the values on columns 5 and 6 in y using dates as the x axis using gnuplot?
You could try this:
set key autotitle columnhead
set key top left
set datafile separator ","
set timefmt '%Y-%m-%d'
set xdata time
plot 'test.txt' using 1:5 w l t 'low', 'test.txt' using 1:6 w l t 'high'
which yields:

Plot csv file with multiple rows using gnuplot

I have a csv file which contains 500 rows and 100 columns.
I want to plot the data in the way that:
Each row represent a curve on the graph. Every column represents a
value on the curve (100 values).
500 such curves on the graph.
The code:
set xrange [0:100]
set yrange [0:20]
set term png
set output 'output.png'
set datafile separator ','
plot 'myplot.csv'
But this does not seem to work.
How can I configue gnuplot to achieve that?
Edit:
The data is in this format (Shortened):
7.898632397,7.834565295,8.114238484,7.636553599,7.759415909,7.829112422
7.898632397,8.379427648,8.418542273,7.921914453,7.558814684,7.237529826
7.898632397,7.862492565,8.132579657,8.419279034,8.350564183,8.578430051
7.898632397,7.613394134,7.213820144,7.42985323,7.74212712,7.144952258
7.898632397,7.736819889,8.14247944,8.025533212,8.256498438,8.133741173
7.898632397,7.906868959,8.032605101,8.308540463,8.238641673,8.143985756
set datafile separator comma
plot for [row=0:*] 'myplot.csv' matrix every :::row::row with lines
However I suspect that with 500 lines the plot will be too crowded to interpret.

json data appears in a single line

I have a badly formatted json file
R˜{"xData":{"x":[7872,7904,...4670]}} R˜{"xData":{"x":[7904,7904,...8000]}} ...
That is, there is only one line, whereas each new data record should start with a new line starting from the character R. Also, the character ~ after R is unwanted. Since the file is about 1GB, it is impossible to manually insert a new line just before each R. Each x is a vector of the same number of data points, say 5000. If the total number of lines are 100000, i.e. 1e5 occurences of the character R, then how to obtain a separate output file containing only the matrix of x values in that output file? This matrix will be 5000 columns by 100000 rows.

How to use Gnuplot to create histogram from binned data from CSV file?

I have a CSV file which is generated by a process that outputs the data in pre-defined bins (say from -100 to +100 in steps of 10). So, each line looks somewhat like this:
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
i.e. 20 comma separated values, the first representing the frequency in the range -100 to -90, while the last represents the frequency between 90 to 100.
The problem is, Gnuplot seems to require the raw data for it to be able to generate a histogram, whereas I have only the frequency distribution. How do I proceed in this case? I'm looking for the simplest possible histogram, that perhaps displays the data using vertical bars.
You already have histogram data, so you mustn't use "set histogram".
Generate the x-values from the linenumbers, and do a simple boxplot
plot dataf using (($0-10)*10):$1 with boxes