Reputation: 21
I'm busy with a system for generating some plots from a big csv formatted data file.
So far, I can to do this task with gnuplot, but I like also to read some text strings from the data file, to adapt a bit and use them for labelling and/or other text boxes on the graphs. Up to now I'm not able to do this within the gnuplot command system.
Extra requirement: Should be able to run the code on windows.
This is my code so far:
# The BigDataFile.csv files starts with some lines information
# (string texts about the matrix contense). After this info block,
# all the matrix data for the plots.
dataFileName="BigDataFile.csv"
set datafile separator "\t"
# Read one text string at line number 'textInfoRow' from column
# number 'textInfoColumn'
textInfoRow = 5
textInfoColumn = 10
# Now try to capture the string at some location in the info block.
set terminal unknown
plot dataFileName every ::textRow::textRow using (textVar=stringcolumn(textColumn)) # How can we do this ????
print textVar
Question: How can we read within 'gnuplot' a single text string at a specified location in a data file?
Upvotes: 2
Views: 3065
Reputation: 26198
The issues with your code are:
textInfoRow
and textInfoColumn
and later textRow
and textColumn
.unknown
.
Simply change your expression to (textVar=stringcolumn(textInfoColumn),0)
. It is assigning a value to the variable but plotting 0
. Check help operators binary
. The expression (a,b)
is serial evaluation. Also keep in mind that gnuplot starts counting rows from 0
.
Data: "BigDataFile.csv"
(make sure separators are TABs, StackOverflow converted them to SPACE)
# "Big" data with some header
# another header line
1.000 2.000 3.000 4.000 5.000 6.000 7.000 8.000 9.000 10.00
2.000 0.982 0.755 0.526 0.684 0.090 0.221 0.402 0.594 0.331
3.000 0.119 0.904 0.938 0.960 0.067 0.607 0.368 0.540 0.317
4.000 0.782 0.060 0.163 0.446 0.826 0.503 0.096 0.494 0.949
5.000 0.930 0.703 0.294 0.990 0.919 0.038 0.550 0.467 HERE
6.000 0.346 0.830 0.920 0.285 0.575 0.878 0.747 0.532 0.222
7.000 0.207 0.120 0.709 0.194 0.854 0.501 0.241 0.505 0.123
8.000 0.862 0.479 0.531 0.640 0.259 0.673 0.708 0.559 0.516
9.000 0.979 0.581 0.611 0.664 0.369 0.775 0.808 0.522 0.294
10.00 0.514 0.516 0.780 0.232 0.407 0.718 0.140 0.568 0.619
You can extract a text "cell" by the following code. I'm not sure whether this is the fastest and most efficient way, but at least it is gnuplot-only and therefore platform independent and should run smoothly under Linux, MacOS and Windows.
Code:
### extract one "cell" of data
reset session
dataFileName="BigDataFile.csv"
set datafile separator "\t"
textInfoRow = 5
textInfoColumn = 10
set terminal unknown
plot dataFileName every ::textInfoRow-1::textInfoRow-1 using (textVar=stringcolumn(textInfoColumn),0)
print textVar
### end of code
Result:
HERE
Upvotes: 1