my problem is the following, I have a text file like that:
#X,#Y
1,1.00182349
2,4.024570000000001
3,8.73499
What I want to get is a plot like that:
where, basically, each y value is plotted as distinct point and on the x-axis my label are N,L,H.
I made that picture with the plot command in octave, but I'm forced to do that with gnuplot.
Please, can someone tell me how to do that?
Thanks.
You can specify arbitrary label for the tic labels:
set datafile separator comma
set logscale y
set xtics ("N" 1, "L" 2, "H" 3)
plot "test.dat" using 1:2:1 notitle with points linecolor variable pointtype 5 pointsize 2
Related
I am trying to make a figure in gnuplot, similar to the bottom one on this page. Specifically, I only want an x- and y-axis on my figure at the places where there is data plotted.
For the y-axis, this works very well using the ytics rangelimited option. However, when I use xtics rangelimited on the x-axis, the x-axis border disappears:
Even more strangely, when I remove the set border option, there appears a diagonal line on my graph:
The minimal working example to make these figures is:
set terminal epslatex standalone size 8.0 cm, 8.0 cm
set output "test.tex"
# Define function
f(x) = abs(x)< 1 ? x**2 : NaN
set border 1+2 front #comment this out to get the diagonal line
set xrange [-1.5:1.5]
set xtics (-1.0,0,1.0) rangelimited nomirror
set yrange [-0.25: 1.25]
set ytics rangelimited nomirror
# plot line
plot f(x) with lines
I would like to get for the x-axis a similar result as for the y-axis. Does anyone know how to solve this problem?
As a side-question: I would like to have the 0 displayed on the y-axis as well. Is there any automatic way to do this? Or should I always explicitly tell gnuplot to put a tic at 0?
The rangelimited x axis is only drawn to span data points. You have no data points because you are plotting a function. In order to have the plot behave as a data plot rather than as a function plot you can use the following convention:
plot '+' using 1:(f($1)) with lines
See gnuplot documentation for "plot special-filenames"
I have the following gnu plot:
# automobile_input.txt
#
set term png
set output "automobile.png"
#
# Fields in each record are separated by commas.
#
set datafile separator ","
set title "Price versus Curb weight"
set xlabel "Price in dollars"
set ylabel "Curb weight in pounds"
set grid
plot 'x' using 1:2
quit
x is a file containing numbers such as
1,2
0.5,4
etc.
I would like to make a few changes to this plot.
At the top of the plot there is "x using 1:2" and I would like to remove that.
Finally, the most important thing: I would like to add another file, y, in the same format, which will be also plotted on the same plot, only with a different sign and color (instead of pluses in red), for example, blue triangles. I would rather also the pluses be circles.
Omit the data series title by using notitle in your plot line. Adding another curve would be done like this:
plot 'x' using 1:2 notitle, \
'y' using 1:2 notitle
The data series points will adjust automagically. To manually specify the format, you might plot with something like this:
plot 'x' using 1:2 with points pointtype 6 linecolor rgb 'red' title "Data X", \
'y' using 1:2 with points pointtype 8 linecolor rgb 'blue' title "Data Y"
You'll usually see scripts online that abbreviate these command to look like:
plot 'x' w p pt 6 lc rgb 'red' title "Data X", \
'y' w p pt 8 lc rgb 'blue' title "Data Y"
I'm new to gnuplot and I have a problem:
I have 2 different text files, the first one (file1.txt) is something like this:
Switch,Port,BPS
S1,1,5464091.33
S1,3,5465677.33
S2,2,5463298.00
S2,3,5462729.67
S3,1,5461340.67
S3,3,5461772.33
and I plot "file1.txt" with an histogram:
plot avg_file using 3:xticlabels(stringcolumn(1)."-".stringcolumn(2)) title columnheader
this works fine.
Now I have file2.txt which contains a single value:
AVG_BPS
4844714.81
I would like to plot this value as a constant horizontal line over the previous graph (histogram).
This is my complete script:
# Terminal definition (PNG image)
set term png
# Settings
set datafile separator ","
set output 'myplot.png'
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set boxwidth 1
# Graph and Axis titles
set title "BPS"
set xlabel "Switch-Port"
set ylabel "bits-per-second"
# Plot
plot "file1.txt" using 3:xticlabels(stringcolumn(1)."-".stringcolumn(2)) title columnheader
Here is myplot.png:
Thanks
probably the best is to do a stats:
stats 'file2.txt' u 1
hor_value=STATS_min
and then add to your plot:
plot "file1.txt" using 3:xticlabels(stringcolumn(1)."-".stringcolumn(2)) title columnheader, hor_value
or alternatively put a line on top (before the last plot):
set arrow nohead from graph 0, hor_value to graph 1, hor_value front
I am trying to plot some data and I noticed that the y-axis tick values were all the same. I tried to add more precision using y format, but it did not work. I am unsure what I may have done wrong.
I initially thought that the plots were reflective of the data, but I discovered that the values were all the same. What was initially confusing was that the y-axis just shows the same repeating value on the major tics.
There is another similar question on StackOverflow (Repeating y-axis tick labels), but the solutions there did not work for me, and I would like to understand why gnuplot does this (which is also not explained in the other question).
%> gnuplot -V
gnuplot 4.4 patchlevel 3
set term png font 'Liberation Sans,10' size 800,200
set output "data/plotid09-" . timestamp . ".png"
set style line 1 lt 1 lw 1 lc rgb "purple" pt -1
set xlabel "Time" font 'Liberation Sans,10'
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set xtics font 'Liberation Sans,10'
set ytics font 'Liberation Sans,10'
set format y "%8.4f"
set ylabel "Kelvin"
plot "data.txt" using 1:6 ls 1 smooth bezier with lines title "Temperature"
I found the problem. Thanks for the comments and feedback.
Changing the line
plot "data.txt" using 1:6 ls 1 smooth bezier with lines title "Temperature"
to
plot "data.txt" using 1:6 ls 1 with lines title "Temperature"
fixed the issue. The problem was the "smooth bezier" option. I removed it and the problem went away, I saw a flat line and appropriate numbering on the major ticks as seen below. The plot below is an example of what one of the fields look like now (similar data, same issue).
#
I am using Gnuplot to draw step functions from an input file:
plot 'myFile' using 1:2 with steps
I want to fill underneath the plot. something like
plot 'myFile' using 1:2 with filledcurves
But Gnuplot fill underneath the diagram by drawing a line between consecutive points.
How can I fill in underneath the step function?
Use the fillsteps plotting style, which is the same as steps, but the area between the curve and y=0 is filled:
set samples 11
set xrange [0:10]
plot '+' with fillsteps fs solid 0.3 noborder lt 1,\
'+' with steps lt 1 lw 4