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.
Related
I am trying to plot a simple graph, x and y coordinates, however how my axis labels are not quite as I wish.
How can I change the '1e+08' and so on to their true value, 100000000
How can I shift the labels of the xtics down so they don't obscure the graph?
Can I print the coordinates in the graph of certian points, for example the dip between 2014-05-10-04-00 and 2014-05-10-08-00?
How can one add more intervals in the labels of the x axis?
Here is the input I'm using:
reset
clear
set output "BytesOverTime.png"
set title "Evolution of Bytes over Time"
set ylabel 'Bytes'
set xlabel 'Time'
set key off
set term png
set xdata time
set timefmt "%Y-%m-%d-%H-%M"
set format x "%Y-%m-%d-%H-%M"
set xtics rotate by 90 nomirror
set datafile separator ' '
set logscale y
plot "timeBytesAverage.out" using 1:2
And the file if its needed to test:
http://pastebin.com/raw.php?i=qqpeJj4V
How can I change the '1e+08' and so on to their true value, 100000000
set format y "%f"
or, as this will give you decimal numbers:
set format y "%.0f"
You may also have a look at
set format y "%.0s%cByte"
which will create MByte, GByte, ... (See right y-axis in my plot)
However, this will be to the base of 1000, not 1024.
How can I shift the labels of the xtics down so they don't obscure the graph?
set xtics rotate by 90 nomirror right
will right-align (left-flush) the tic marks
Can I print the coordinates in the graph of certian points, for example the dip between 2014-05-10-04-00 and 2014-05-10-08-00?
If you know the coordinates, yes:
set xtics add ("high" "2014-05-09-23-30", "low" "2014-05-10-22-30" )
The general syntax is:
set xtics add ( <label1> <position1>, <label2> <position2> , ...)
This will add the list of labels to the automatically generated labels. If you omit the word add, there will be no automatically generated labels, just those in your list.
How can one add more intervals in the labels of the x axis?
set xtics 3600
will generate a label every 3600 seconds, i.e. every hour. This does not work for log scale axes.
set mxtics 2
will cause the gap between two major (labeled) tics being divided into two smaller gaps, i.e. one minor tic mark between two major ones. (However, it seems not to be necessary here, as gnuplot decides to use 2 on it's own)
And here is the result:
Note that I also added
set y2tics
set y2range[1E8:1E12]
set format y2 "%.0s%cByte"
set logscale y2
to demonstrate this special format on the right y-axis.
And by the way: The format of the labels on the y-axis is independent from the format in the data file.
set timefmt "%Y-%m-%d-%H-%M" defines the format inside the file
set format x "%Y-%m-%d-%H-%M defines the format in the plot. So ou may do something like set format x "%Y-%m-%d %H:%M which is more readable.
I have non-contiguous date/time data (eg weekend data are missing - I don't have rows in data file for them) and I'd like to not to draw them. Graphically, it would be like cutting out a vertical slice of a plot. I'm aware that the X scale would not be linear and am perfectly happy with this.
Here it is what I want to get rid of:
The gnuplot script is auto-generated so it doesn't have to be very neat if it can't be. Currently I'm doing:
set xdata time
set timefmt "%d/%m/%Y-%H:%M:%S"
unset mx2tics
unset mxtics
set xtics border in scale 1,0.5 nomirror rotate font "Times-Roman,12" "$time_min", $xtics, "$time_max"
set xrange ["$time_minb" : "$time_maxb"]
set grid xtics back
Where obviously $var is a proper value of some variable $var. What I'd like to retain: some small (1-2 candles) margin on the left and on the right (between box border and data), labeled ticks every 10 candles.
Ideally all ticks at the borders of time intervals that would be put together in X axis would be marked. Also in the perfect world those labels would be slightly drawn aside to not to overlap each other. But I'm not very picky, I could bear even overlapping of the 2 labels on the joint of 2 intervals if only "empty piece" of a plot is removed.
BTW: I have gnuplot 4.6 but can update to 5.0 if it's necessary.
As I understand the question, it is not about breaking the axis. This would also be possible but might get complicated if you have more than one break.
Actually, there are later questions about the similar topic, e.g.: Remove weekend gaps in gnuplot for candlestick chart
The basic idea is to plot the data against the row index (pseudocolumn 0) instead of time (column 1) in order to make discontinuous data "continuous" and "manually" add the xtic labels.
The accepted solution to the above question, however, is using xticlabels and defines a function which shows, e.g. every 5th xticlabel. This looks OK for the illustrated case. However, although, only every Nth ticlabel will be shown, a tic will be created nevertheless at every data entry which will not look good for data with larger time range.
Hence, another approach would be plotting the data twice: first time for the data and the second time plotting NaN, i.e. nothing but the tics, where you can easily select the spacing via every (check help every). Although the data looks continuous, it might useful to indicate the breaks somehow, e.g. with extra tics or vertical lines. Alternatively, depending on the data, each start of a "continuous" subset could be marked with a date label followed by regular minor tics without labels.
Script: (works with gnuplot>=5.2.0, with some adaptions probably with earlier versions).
### plot dis-continuous time "continuous"
reset session
# create some random test data
set table $Data
myTimeFmt = "%Y-%m-%d"
t0 = time(0)
y0 = 100
f(t) = strftime(myTimeFmt,t1=t0+$0*3600*24)
plot '+' u (f(0)):(y0=y0+rand(0)*2-1) w table
t0 = t1 + (rand(0)*30+30)*3600*24
replot
t0 = t1 + (rand(0)*50+50)*3600*24
replot
unset table
set format x "%Y\n%m-%d" timedate
set grid x,y
set ytics 2
set key noautotitle
set multiplot layout 2,1
plot $Data u (timecolumn(1,myTimeFmt)):2 w l lc "red"
myXTic(col) = strftime("%Y\n%m-%d",timecolumn(col,myTimeFmt))
N = 30
plot $Data u 0:2 w l lc "web-green", \
'' u ($0*N):(NaN):xtic(myXTic(1)) every N
unset multiplot
### end of script
Result:
I want my yrange to be between -100 and 0, and here is my plot in gnuplot
I want the y axis to be from -100 increasing up to 0!
what should I do?!
BTW:
My plot is histogram!
when I set it to [-100:0] my plot is upside down, the bars are from up to down!!
set style data histogram
set yrange [-100:0]
set style fill solid 0.3
set bars front
plot 'mean.rssi' using 2:xticlabels(1) title columnheader
above is my code, histogram is plotted from 0 to -100, but I want to be from -100 to 0!
The file mean.rssi contains two columns, for example
Dlink -93
That isn't directly supported, histograms always have their base line at 0, positive values give boxes oriented upwards, negative values downwards.
Since your range is known, you should convert the range [-100:0] to the range [0:100] and relabel the y-axis:
set style data histogram
set yrange [0:100]
set ytics ('-100' 0)
set for [i=-100:0:20] ytics add (sprintf('%d', i) i + 100)
plot 'mean.rssi' using ($2 + 100):xticlabels(1)
Other solutions would use the boxes plotting style. If you could use this depends on whether you need the stacking features of the histogram style.
You can specify ranges with square brackes. For example, to specify both X and Y ranges you could do:
plot [-20:20][-50:50] sin(x)
which would set the X-range to [-20,20] and the Y-range to [-50,50].
To only set the Y-range, you can set the X-range to the empty brackets [], e.g.
plot [][-50:50] sin(x)
To only set the X-range you can do something similar, or just omit the Y-range completely:
plot [-20:20] sin(x)
I'm using gnuplot in a bash script to draw several things.
For this special graphic, I need to print the amount of matrices (y axis) with the matrix size as the x-axis.
As the distribution can be pretty sparsed, I want to use a logscale for x and y. It works great with y, but gnuplot tells me I can't have a logscale for the x-axis when I'm using histogram style.
Any ideas to debug this? or on how to present the results using a similar way?
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set logscale xy
plot '$res/histo-$ld-$lr-$e-$r' using 2:xtic(1) title 'Run'
The error is :
line 0: Log scale on X is incompatible with histogram plots
Thanks in advance.
Edit : btw, I was using gnuplot 4.4 patchlevel 4 and just updated to the newest version (i.e. 4.6 patchlevel 5)
Gnuplot histograms work a bit differently from what you might think. The x-axis isn't numeric. In your case the value in the first row, second column is placed at an x-value of 0 with the y-value taken from the second column and a manual label taken from the first column, first row. The values of the second row are placed at x=1 etc.
You can try using the boxes plotting style, which is used with a 'conventional' x-axis and supports a logscale in x:
set logscale xy
set offset 0,0,1,1
set boxwidth 0.9 relative
set style fill solid noborder
plot 'data.dat' with boxes
With the data file data.dat
1 1000
2 300
5 150
20 10
135 3
this gives the result (with 4.6.5):
In order to have a fixed boxwidth and a varying box distance, you can use a third column to specify a box width as percentage of the x-value:
set logscale xy
set offset 0,0,1,1
set style fill solid noborder
plot 'data.dat' using 1:2:($1*0.5) with boxes
Putting the actual values on the x-axis works as follows:
set logscale xy
set offset 0,0,1,1
set style fill solid noborder
plot 'data.dat' using 1:2:($1*0.5):xtic(1) with boxes
I'm making some 3D surface plots in Gnuplot and it would be very useful to have tic marks along each border of my plot. In the attached sample plot, there are no tic marks along the top left or top right horizontal borders (borders 256 and 512). In order for vertical grid lines to be drawn on the back vertical planes, I need to have tic marks on these borders. How can I achieve this?
I have not found a way to solve this using the grid and border. However, there is a relatively simple workaround, which is useful only if you do not change your ranges every time you plot your data.
Basically you plot a constant surfaces on the back walls matching the line type and number and position of the grid lines in the x-y plane.
First, set up the ranges. I labeled them, because we will need the numbers later.
xmin=0 ; xmax = 100
ymin=0.01 ; ymax=1000
zmin=0 ; zmax=990
set xrange [xmin:xmax]
set yrange [ymin:ymax]
set zrange [zmin:zmax]
Setting the z axis intersection with x-y plane (ticslevel) and I guessed a view angle to visually match your example. We want to set these before multiplot.
set ticslevel 0.0
set view 60,45,1
Now comes the fun. For this part you have to know the number of grid lines in your x-y plane (same as number of major tics on x and y axes). We will plot the back grid walls first, so they are behind your data/function at the end. Also, I switch off the grid and border for this part, but they should exactly overlap if you leave them in.
set multiplot
unset grid
set border 0
Even though the y-axis has logarithmic scale, the grid is separated linearly (equidistant grid lines). So at this point I want linear scale on y axis. (If you set logscale y before this point, comment it out.) I don't want linear labels on the y-axis, because they are different on logarithmic scale, so I set the format accordingly.
set format y ""
set isosamples 6,9 # - set this to number of tics on y-axis,z-axis
Here is the only manual setting that might change when you plot on a different range. You need to set the numbers of isosamples to the numbers of tics on y-axis,z-axis.
To control how many lines gnuplot is going to use for each surface, we need to set both the isosamples (done above) and the ranges of dummy variables u,v. Notice the line type 0, which is the grid line type.
I plot my first wall at x = xmin:
set parametric
set urange [ymax:ymin]
set vrange [zmax:zmin]
splot xmin,u,v w lines lt 0
Similarly, we do the other wall at y = ymax.
set urange [xmin:xmax]
set vrange [zmin:zmax]
splot u,ymax,v w lines lt 0
unset parametric
Now that I have the walls, I can plot what you already have in the picture. Setting borders, tics, re-enable the y-axis label we disabled before, set the log-scale on y axis (now is a good time) and reset isosamples to the default values.
set xtics mirror
set ytics mirror
set ztics mirror
set grid ytics xtics back
set logscale y
set format y " %g"
set isosamples 10,10
And plot your data/function as you are used to.
splot 'data.txt' w lines
unset multiplot
And we are done....
Possible necessary modification:
I guess your x and y axes will be different from mine, since the reverse is easily achievable by something like view 60,135,1. This also switches x and y though. Your surfaces will then change coordinates.
You can try setting tics there using x2tics and y2tics.
Here is the documentation of Xtics.