I am trying to populate graph with some fixed values on X-axis and corresponding values on Y-axis. With my below script, no values are labelled on X-axis and value on Y-axis are labelled with powers.
How to make xtics data(1000, 10000, 100000, 1000000, 10000000) appear on X-axis ?
How to get rid of powers on Y-axis ? (Example : I want 4000000 on Y-axis instead of 4x10^6
set xrange [0:]
set output "macs.png"
set ylabel "Flows/sec"
set xlabel "MACS per Switch"
set grid
set xtics (1000, 10000, 100000, 1000000, 10000000)
set style line 2 lt 1 lw 2 pt 1 linecolor 1
plot "macs.data" using :1 with linespoints linestyle 0 title "Floodlight" // Using ":1" as X-axis data is supplied in xtics
Here is my data file :
# Not Supplying X-axis data here as it is supplied through xtics
400
60000
700000
800000
900000
I want my populated graph with only one line to looks like this :
You have supply x and y value for each point. Fortunately, gnuplot supports some special column numbers like column 0, which is a counter of valid data sets, i.e. here a line number ignoring comments. It starts at zero.
Next, your x-axis uses a log scale, so you should do it, too. The formula to convert line number to correct x-value is 10(colum_0) + 3. which translates to 10**($0+3) in gnuplot.
Here is the code:
# Logarithmic scale for x axis
set log x
# get rid of scientific formatting of numbers,
# plain format also for large numbers
set format x "%.0f"
# If you don't like the small ticks between the large ones
set mxtics 1
# put the key (legend) outside, right of the plot area,
# vertically centered (as in your picture)
set key outside right center
# only horizontal grid lines
set grid y
plot "macs.data" using (10**($0+3)):1 title "foo" with linespoints
And here the result:
Alternative:
Your approach plots the data as if it were given like
0 400
1 60000
2 700000
3 800000
4 900000
In this case, you need to label the x-axis on your own, the correct syntax is
set xtics("1000" 0, "10000" 1, "100000" 2, "1000000" 3, "10000000" 4)
This will not draw any automatic labels, but it will put e.g. your string 10000 at x=1
Related
i'm having a csv like this
2021-10-31;20:30:26
2021-10-31;20:32:15
2021-10-31;20:39:17
2021-10-31;20:40:15
2021-10-31;20:42:13
2021-11-01;08:37:15
...
i would like to calculate the entries within a 10 minute interval and display it in an bar graph. In the example above there are from 20:30 till 20:40 there are 3 hits, from 20:40 till 20:50 there ar 2 hits, and so on.
Is there any way to ge this done with gnuplot? Or do i've to prepare the data?
Thank you, Martin
You can try the smooth frequency option like this:
reset
# formatting of output data (graph)
set format x "%Y-%m-%d\n%H:%M" timedate
# y-axis, bar graph should start at 0
set yrange [0:*]
set ylabel "Occurences"
set ytics 1
# make some space for large x axis labels
set rmargin at screen 0.95
# put input values into bins/time intervals
binwidth=10*60 # 10 minutes in seconds
bin(val) = binwidth * floor(val/binwidth)
# configure bar graph
set boxwidth binwidth
# final plot command
plot "a.dat" using (bin(timecolumn(1, "%Y-%m-%d;%H:%M:%S"))):(1) smooth freq with boxes fs solid 0.25 notitle
Documentation from help smooth freq:
The `frequency` option makes the data monotonic in x; points with the same
x-value are replaced by a single point having the summed y-values.
To plot a histogram of the number of data values in equal size bins,
set the y-value to 1.0 so that the sum is a count of occurances in that bin:
Example:
binwidth = <something> # set width of x values in each bin
bin(val) = binwidth * floor(val/binwidth)
plot "datafile" using (bin(column(1))):(1.0) smooth frequency
You have time data, so column must be replaced by timecolumn, see
help timecolumn for details.
The command set boxwidth is used by the boxes plotting style, see help plotting styles boxes for details.
This is the result:
I'm sorry if this has already been asked, I couldn't find it anywhere, but I have an image plot on gnuplot of a three-columned data file for a y range [0:24] and I can't figure out how to use gnuplot to rearrange the image graph so my y axis runs from 16:24 and then 0:16 (in that order and on the same axis). The command I've been using is "plot [] [0:24] '/Users/eleanor/PycharmProjects/attempt2.gray' u 1:2:3 w image" but I don't know what command to use so that hour 16 is at the very bottom instead of 0, and then when y reaches 23:59 y goes to 0 next and then continues increasing up to 15:59 at the very top of the axis. I'm not sure if that makes sense or not, and I've already tried changing the y range to [16:15] and that did nothing except give me an error lol. Any tips would be very much appreciated! :)
a piece of the file im using is below (with the first column being the day of year, the second being the time in decimal hours, and the third being the data):
20 0.0 7.327484247409568
20 0.002777777777777778 8.304658863945411
20 0.005555555555555556 11.641408500506405
20 0.008333333333333333 6.543382279013497
20 0.011111111111111112 13.922090817182697
20 0.013888888888888888 10.696406455987988
20 0.016666666666666666 12.537636516165243
20 0.019444444444444445 11.816216763447612
20 0.022222222222222223 8.914413125514413
20 0.025 5.8225423124691496
20 0.027777777777777776 10.896730484548698
20 0.030555555555555555 9.097140108173859
As currently implemented, with image treats the entire block of data as a single entity. You can't chop it up into pieces within a single plot command. However if your data is dense enough, it may be that you can approximate the same effect by plotting each pixel as a colored square:
set xrange [*:*] noextend
set yrange [0:24]
plot 'datafile' using 1:(($2>16.)? ($2-16.) : ($2+8.)):3 with points pt 5 lc palette
I strongly recommend not making the range limits part of the plot command. Set them beforehand using set xrange and set yrange.
If necessary, you can adjust the size of the individual square "pixels" by using set pointsize P where P is a scale factor. It probably looks best if you make the points just large enough (or small enough) to touch each other. I think the default ones in the image I show are too large.
You can also use the boxxyerror plotting style instead of the image plotting style. Well, here's what the help for boxxyerror says
gnuplot> ? boxxyerror
The `boxxyerror` plot style is only relevant to 2D data plotting.
It is similar to the `xyerrorbars` style except that it draws rectangular areas
rather than crosses. It uses either 4 or 6 basic columns of input data.
Additional input columns may be used to provide information such as
variable line or fill color (see `rgbcolor variable`).
4 columns: x y xdelta ydelta
6 columns: x y xlow xhigh ylow yhigh
....
If you adopt the four-column plotting style above, you must specify xdelta and ydelta in addition to x and y to specify the rectangle. The xdelta and ydelta should be the half-width and half-height of each pixel. From your data, let's say xdelta is half of 1 and ydelta is half of 0.002777777777777778 hours.
Our final script will look like this.
In this script, the second column of "using" is the same as Ethan's answer.
dx = 1.0/2.0
dy = 0.002777777777777778/2.0
set xrange [-1:32]
set yrange [0:24]
set ytics ("16" 0, "20" 4, "0" 8, "4" 12, "8" 16, "12" 20, "16" 24)
set palette defined (0 "green", 0.5 "yellow", 1 "red")
unset key
plot "datafile" using 1:($2>16?($2-16):($2+8)):(dx):(dy):3 \
with boxxy palette
Say we got this data 'file.dat':
0.1 2
0.5 1
0.7 3
1.3 23
1.4 20
2.7 2
2.3 6
5.3 50
5.2 50
I wish to plot this as follows:
2D plot (lines is fine), like normal.
Except: xtics label shows the following names instead: "small", "medium", "big" marked exactly at x values 0, 3 and 5, respectively.
Q: How to achieve this?
Permissible actions:
I can modify existing or create new 'file.dat' files.
I can modify gnuplot commands.
set xtics ("small" 0, "medium" 3, "big" 5)
plot 'file.dat' with lines lw 2 lc rgb "black"
should work.
For more information type help xtics:
The explicit ("" , ...) form allows arbitrary tic
positions or non-numeric tic labels. In this form, the tics do not
need to be listed in numerical order. Each tic has a position,
optionally with a label. Note that the label is a string enclosed by
quotes. It may be a constant string, such as "hello", may contain
formatting information for converting the position into its label,
such as "%3f clients", or may be empty, "". See set format for more
information. If no string is given, the default label (numerical) is
used.
An explicit tic mark has a third parameter, the level. The default
is level 0, a major tic. Level 1 generates a minor tic. Labels are
never printed for minor tics. Major and minor tics may be
auto-generated by the program or specified explicitly by the user.
Tics with level 2 and higher must be explicitly specified by the user,
and take priority over auto-generated tics. The size of tics marks
at each level is controlled by the command set tics scale.
Examples:
set xtics ("low" 0, "medium" 50, "high" 100)
set xtics (1,2,4,8,16,32,64,128,256,512,1024)
set ytics ("bottom" 0, "" 10, "top" 20)
set ytics ("bottom" 0, "" 10 1, "top" 20)
I want to plot a big file of matrix organized data (200 rows by 6000 columns in the file).
Data is the output of an FFT on radio signal across 18 to 24 MHz, 6000 bins of 1KHz each.
The file contains also header information for rows and columns: 1 top row with the list of the 6000 frequencies and one date-time at start of each row for the acquisition timestamp.
The resulting plot is the following:
obtained in gnuplot with these statements:
set datafile separator ","
set ticslevel 0
plot 'test3.mat' matrix rowheaders columnheaders using 1:2:3 with image
For my planned usage I need to have it horizontally oriented like the following, but only the data gets rotated while all rows and columns tics are now on the wrong axis.
data rotation obtained changing the plot statement in this way:
plot 'test3.mat' matrix rowheaders columnheaders using 2:1:3 with image
Is there a way to:
"rotate" also the tics to have them on the correct axis (frequencies on y and time on x)
and reduce the number of tics used on the chart to avoid the ugly overlap of text
Additional tests did using info from the comments:
TEST 1
with this one I see the tics but NO heatmap at all (+ this msg: "warning: Image grid must be at least 2 x 2" )
plot 'test3.mat' matrix nonuniform using 2:1:3 with image
TEST 2
with new file (no header/timestamps) i almost get the desired result. The x axis is still wrong and i would like an easier way to produce the tics values.
set datafile separator ","
set ticslevel 0
set timefmt '%Y-%m-%d %H:%M:%S'
set xdata time
set format x "%H:%M:%S"
set format y "%.1s"
set autoscale xfix
set autoscale yfix
plot 'test3-nohead.mat' matrix using ("2015-12-03 15:08:39"+0.05*$2):(18000000.0+1000.0*$1):3 with image
I have a data row with lots of dots, plotted as markers. X-axis values range between 0 and 80 ms, and Y-values take discrete values of 1,2,..5. There are about 50000 points, so if I just plot them as usual, the Y-value changing dynamics is not clear, as you see for example a solid line forming at Y value 5, with a few dropouts at 3 and 4. I would like to modify my plot to zoom in the first millisecond - the half of the X-axis should be occupied by the range 0-1ms, and the rest 1-80ms. Any idea how to achieve this?
Use this:
set yrange [-1:1.3]
set xrange [0:12]
set x2range [40:150]
set xtics 0,1,5
set x2tics 100,10,150 mirror offset 0,-21.6
plot (x<5?sin(x):0/0) axis x1y1 tit "f(x)", (x>100?cos(x):0/0) axis x2y1 tit "g(x)"
Constant -21.6 is setting up xtics labels for second part but according to x2 (upper) axis... So you must fit this constant according to graph height and used terminal. Also you have to change range and tics settings to obtain continuous x axis.