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
Related
Can we plot both points with smooth csplines in one legend? If we plot them separately two legends generates with separate point and line.
I expect both point and smooth line in one legend as in case of linepoints
If you have a current gnuplot (version 5.4), use keyentry to generate a custom entry for the plot legend.
plot FOO with points lt 2 notitle, \
FOO smooth csplines with lines lt 2 notitle, \
keyentry with linespoints lt 2 title "points + lines"
UPDATE
So apparently, the order of options does matter. Wasn't aware of that. Still,
rowi=1
rowf=7
colour=0
plot for [i=0:rowf-rowi+3] filename.'.csv' u ($0+i):2:3:(colour=colour+1):xtic(1) every ::i+1::i+1 w errorbars pt 7 lc var notitle
will start re-using colour after the eight entry where I want a different colour for each of the 10 points plotted.
How do I do that?
In gnuplot, the lc (linecolor) and pt (pointtype) parameters belong to the w (with) clause (see help plot with), so putting notitle between pt 7 and lc var doesn't work. If you move the notitle clause to the end of the plot command line, this will fix the error you are getting. Like this:
plot for [i=0:rowf-rowi+3] filename.'.csv' u ($0+i):2:3:xtic(1) every ::i+1::i+1 w errorbars pt 7 lc var notitle
Without lc var, by default the colours will eventually repeat but you can set the palette to anything you like. See: Gnuplot repeats colors in rowstack histograms
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"
is there a way to have a curve with two colors, well i have many curves in my plot. But I like to add a specific characteristic, i want the curve 1 to be simple line in[a,b] interval, and dotted line in interval [b,c].
an example of my graph:
plot exp(-x**2 / 2), sin(x)
can we make sin(x) plotted in dotted line from[0,5]
thanks in advance.
You can specify the line type on a certain interval with the linetype keyword to the plot command. I don't think there is a way to make linetype a function of interval without doing it manually. For example:
plot exp(-x**2/2), [0:5] sin(x) lt 1 lc rgb 'green', [5:] sin(x) lt 2 lc rgb 'green'
gives
How do you plot bar charts in gnuplot with text labels?
Simple bar graph:
set boxwidth 0.5
set style fill solid
plot "data.dat" using 1:3:xtic(2) with boxes
data.dat:
0 label 100
1 label2 450
2 "bar label" 75
If you want to style your bars differently, you can do something like:
set style line 1 lc rgb "red"
set style line 2 lc rgb "blue"
set style fill solid
set boxwidth 0.5
plot "data.dat" every ::0::0 using 1:3:xtic(2) with boxes ls 1, \
"data.dat" every ::1::2 using 1:3:xtic(2) with boxes ls 2
If you want to do multiple bars for each entry:
data.dat:
0 5
0.5 6
1.5 3
2 7
3 8
3.5 1
gnuplot:
set xtics ("label" 0.25, "label2" 1.75, "bar label" 3.25,)
set boxwidth 0.5
set style fill solid
plot 'data.dat' every 2 using 1:2 with boxes ls 1,\
'data.dat' every 2::1 using 1:2 with boxes ls 2
If you want to be tricky and use some neat gnuplot tricks:
Gnuplot has psuedo-columns that can be used as the index to color:
plot 'data.dat' using 1:2:0 with boxes lc variable
Further you can use a function to pick the colors you want:
mycolor(x) = ((x*11244898) + 2851770)
plot 'data.dat' using 1:2:(mycolor($0)) with boxes lc rgb variable
Note: you will have to add a couple other basic commands to get the same effect as the sample images.
plot "data.dat" using 2: xtic(1) with histogram
Here data.dat contains data of the form
title 1
title2 3
"long title" 5
I would just like to expand upon the top answer, which uses GNUPlot to create a bar graph, for absolute beginners because I read the answer and was still confused from the deluge of syntax.
We begin by writing a text file of GNUplot commands. Lets call it commands.txt:
set term png
set output "graph.png"
set boxwidth 0.5
set style fill solid
plot "data.dat" using 1:3:xtic(2) with boxes
set term png will set GNUplot to output a .png file and set output "graph.png" is the name of the file it will output to.
The next two lines are rather self explanatory. The fifth line contains a lot of syntax.
plot "data.dat" using 1:3:xtic(2) with boxes
"data.dat" is the data file we are operating on. 1:3 indicates we will be using column 1 of data.dat for the x-coordinates and column 3 of data.dat for the y-coordinates. xtic() is a function that is responsible for numbering/labeling the x-axis. xtic(2), therefore, indicates that we will be using column 2 of data.dat for labels.
"data.dat" looks like this:
0 label 100
1 label2 450
2 "bar label" 75
To plot the graph, enter gnuplot commands.txt in terminal.
I recommend Derek Bruening's bar graph generator Perl script. Available at http://www.burningcutlery.com/derek/bargraph/
You can directly use the style histograms provide by gnuplot. This is an example if you have two file in output:
set style data histograms
set style fill solid
set boxwidth 0.5
plot "file1.dat" using 5 title "Total1" lt rgb "#406090",\
"file2.dat" using 5 title "Total2" lt rgb "#40FF00"