Considering the data (in file, test.txt):
i x(volts) y(amp)
0 1 5
1 2 6
2 3 7
3 4 8
4 5 3
5 5 4
If I do:
set key autotitle columnheader
plot "test.txt" using 1:2
Then I get:
And, if I do:
set xlabel "x(volts)"
set ylabel "y(amp)"
plot "test.txt" using 1:2
Then I get
In the first case I read the label from file but it went into the legend. In the second case I set the x y labels but not reading from file.
How do I set x y labels reading from file?
You can use system command to get output of the external program into variable.
s=system('head -n 1 test.txt')
set xlabel word(s,2)
set ylabel word(s,3)
plot 'test.txt' u 1:2
Related
I'm new using gnuplot, today I learned a lot on stackoverflow for a problem that I had with a plot, but now for my research I need to do another one like the following image:
The data are of the same tipe, I collected them and isolate only the column that I need in a file.dat, and a sample is the following:
5.38e-51 1
2.75e-81 1
5.3e-67 1
8.71e-170 4
3.62e-59 3
2.98e-52 2
3.2e-31 1
2.98e-54 2
3.85e-29 2
5.38e-57 1
3.2e-33 2
2.75e-88 1
3.2e-34 1
9.89e-37 1
5.38e-59 2
3.2e-35 2
1.68e-168 1
1.81e-101 1
9.89e-39 1
2.98e-59 2
3.2e-39 1
1.07e-110 3
1.07e-111 2
1.81e-107 2
2.82e-40 4
2.6e-108 1
1.07e-115 1
My problem is that I would like on the x-axis that my x is the exponent, as 1E-x.
I tried using set format set format x '%.0f'.sprintf('e%d') but it doesn't work.
How can I do that?
thank you.
If you want to plot values which span many order of magnitudes you either plot it on logarithmic scale
or take log10() of your values and plot them in linear scale.
From your description without code and details, I'm guessing that you have
the data you've shown and want to create a histogram and display the negative log10 value on the x-axis.
NB: In your earlier data you had also 0.0, which will mess-up the smooth freq option together with the logarithmic bins. Note that set datafile missing "0.0" will only exclude 0.0 as text, i.e. 0, 0.00, or 0e-10 will not be excluded. So, make sure you don't have zeros in your data, this will not work with logarithmic scale.
Code:
### plot histogram with logarithmic bins
reset session
$Data <<EOD
5.38e-51 1
2.75e-81 1
5.3e-67 1
8.71e-170 4
3.62e-59 3
2.98e-52 2
3.2e-31 1
2.98e-54 2
3.85e-29 2
5.38e-57 1
3.2e-33 2
2.75e-88 1
3.2e-34 1
9.89e-37 1
5.38e-59 2
3.2e-35 2
1.68e-168 1
1.81e-101 1
9.89e-39 1
2.98e-59 2
3.2e-39 1
1.07e-110 3
1.07e-111 2
1.81e-107 2
2.82e-40 4
2.6e-108 1
1.07e-115 1
EOD
set xlabel "-log_{10}(x)"
set xrange[-15:200]
set xtics 10 out
set ylabel "Sequences"
set yrange [0:]
set key noautotitle
# Histogram with logarithmic bins
BinWidth = 10
Bin(x) = floor(-log10(x)/BinWidth)*BinWidth + BinWidth*0.5
set boxwidth BinWidth
set style fill solid 0.3
set offset 1,1,1,0
set grid x,y
set datafile missing "0.0" # exclude zero, otherwise it will mess up "smooth freq"
plot $Data u (Bin($1)):2 smooth freq with boxes lc "red"
### end of code
Result:
I want to do a vector field plot with the vector arrows also depicted at the bottom just like in a surface contour plot using "set pm3d at b".
My file is given in the following format:
x y y dx dy dz
1 0 2 4 3 1
2 3 4 2 6 3
2 4 6 1 9 2
. . . . . .
I have used this gnuplot script:
set style arrow 1
set xrange[0.7:0.0]
set yrange[-0.4:0.4]
set zrange[-0.4:1.0]
set xtics (-0.7,-0.5,-0.33,-0.15,0.0,0.15,0.33,0.5,0.7) font "Times-Roman,18"
set ytics (-0.7,-0.5,-0.33,-0.15,0.0,0.15,0.33,0.5,0.7) font "Times-Roman,18"
unset ztics
set palette rgbformulae 30,31,32
set ticslevel 0
unset key
scale = 0.4
splot 'file.dat' u 1:2:3:($4*scale):($5*scale):($6*scale) w vectors arrowstyle 1
I also attached two 3d vector field plots with different views. What I actually want is a combination of both so that the contour of the plotted vectors should appear at the bottom (just like a top view using "set view 0,180" which is represented by the second image (top view) incorporated into the (side view) plot.
Vector_field_3d_plot_side_view
Vector_field_3d_plot_top_view
Since I havenĀ“t seen any gnuplot example for such a plot, I am not sure even if it is capable of doing it. If not, which software (Matlab, matplotlib,...) would you recommend me to use instead?
Thanks in advance!
I really appreciate any help!
Best wishes,
DaveS
Since you know the zrange, you can simply do the projection yourself and set z to the minimum value of the z-axis and dz to zero:
set style arrow 1
set xrange[0.7:0.0]
set yrange[-0.4:0.4]
set zrange[-0.4:1.0]
set xtics (-0.7,-0.5,-0.33,-0.15,0.0,0.15,0.33,0.5,0.7) font "Times-Roman,18"
set ytics (-0.7,-0.5,-0.33,-0.15,0.0,0.15,0.33,0.5,0.7) font "Times-Roman,18"
unset ztics
set palette rgbformulae 30,31,32
set ticslevel 0
unset key
scale = 0.4
splot 'file.dat' u 1:2:3:($4*scale):($5*scale):($6*scale) w vectors arrowstyle 1,\
'' u 1:2:(-0.4):($4*scale):($5*scale):(0) w vectors as 1
I would like to plot these data
1 2
2 3
3 5
4 5
5 6
with this code
set ter pdfcairo enhanced color solid
set out "test.pdf"
set xrange [-.5:4.5]
set yrange [.5:6.5]
unset key
plot "test.txt" u 0:1,"" u 0:2, "" u 0:1:(0):($2-$1) with vectors nohead lw 0.5
The line width command seems to work, but it seems not to work with a line width smaller than 1.
this plot is with line width 5:
this plot is with line width 1
this plot is with line width 0.2
as one may notice, there is no difference between the latter two plots. How can I force gnuplot to use a line width smaller than 1?
I have a file that I need to plot in a graph that looks similar to this:
gnuplot sample graph
Here is my file that I am trying to plot:
441.81 823.36 192765 3044.68 4242.61
X 2609.3 4901.96 8306.6 12058.18
1632.27 4098.15 9299.14 16295.19 24665.59
I can do a simple plot, but changing the line types and using a file is what I am having trouble with. I'm not sure how to get the data from the file into the plot and make it formatted like the sample image.
You probably should dig a little deeper into gnuplot. A good start is this article on plotting data.
Anyway, let's define three distinct line styles:
set style line 1 lc 'blue' lt 1 lw 2 pt 6 ps 1.5
set style line 2 lc 'red' lt 1 lw 2 pt 6 ps 1.5
set style line 3 lc 'green' lt 1 lw 2 pt 6 ps 1.5
Then, we can call the plot function on our inputFile:
plot 'inptFile' u 1:2 w lp ls 1, '' u 1:3 w lp ls 2, '' u 1:4 w lp ls 3
(u 1:2 stands for using 1:2 and means that we use the value in the first column as x-coordinate and the value in the second column as the y-coordinate. )
Note that our inputFile looks like this (i.e., each line contains a point's x and y-coordinate):
-1 2 3 4
0 1 2 4
1 2 4 16
2 3 16 8
Output:
I have a datafile that looks like this:
1 2 3 0.5
2 8 9 0.2
3 4 78 0.4
6 5 7 0.01
9 9 9 0.3
10 12 18 0.9
6 8 4 1
I would like to do a graph like this
http://2.bp.blogspot.com/-378_rAaSSVU/UzU0gnGcr9I/AAAAAAAABnU/P1GwP9RKBkM/s1600/gnuplot.png
Where the 4th column is the color.
I tried - obviously incorrect because I do not use the fourth column but I failed to find anything in the documentation:
set dgrid3d 30,30
set view 60,45
set hidden3d
dataFile='prova.dat'
set palette defined (0 "blue", 0.5 "white", 1 "pink")
set pm3d
splot dataFile u 1:2:3 with pm3d
Is somethings like that possible?
Using only pm3d you can use a fourth column to select a color independent of the z-value. Together with dgrid3d this is not directly possible, because the gridding is not performed on the color column.
You can use a workaround: First you plot the gridded z-value to one file, then the gridded color values to a second file and as last point you disable dgrid3d, merge the two temporary files on-the-fly and plot their values:
set dgrid3d 30,30
dataFile='prova.dat'
set table dataFile.'.grid'
splot dataFile u 1:2:3
unset table
set table dataFile.'.color'
splot dataFile u 1:2:4
unset table
set view 60,45
set hidden3d
set palette defined (0 "blue", 0.5 "white", 1 "pink")
set autoscale cbfix
set pm3d
unset dgrid3d
set ticslevel 0
splot sprintf('< paste %s.grid %s.color', dataFile, dataFile) u 1:2:3:7 with pm3d notitle
Note, that paste is a command line tool for Unix-like operation systems. For a similar solution for windows, you can e.g. write a small Python script paste.py (see my answer to Get ratio from 2 files in gnuplot for a possible implementation). Then you must run the wgnuplot_pipes.exe binary file and the splot command becomes
splot sprintf('< python paste.py %s.grid %s.color', dataFile, dataFile) u 1:2:3:7 with pm3d notitle
Of course, for this you must have python installed and the python binary must be available via the PATH environment variable.