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.
Related
I plot with gnuplot the following:
$Data <<EOD
time_,value
1-23:59:58,1
1-23:59:59,2
2-00:00:00,3
2-00:00:01,4
2-00:00:02,5
EOD
set term png size 800,600
set output "ask.png"
set datafile separator comma
set grid
set xdata time
set timefmt "%d-%H:%M:%S"
set format x "%H:%M:%S"
set xtics nomirror
set autoscale xfix
set autoscale x2fix
startnumber=1
xticdata=2
mxticdata=2
set xtics xticdata rotate
set mxtics mxticdata
set x2data
set x2tics startnumber, xticdata rotate
set mx2tics mxticdata
set link x2 via x+1 inverse x-1
plot $Data using 1:2 title columnheader(2)
set output
Data of the column 2 which contains nearly 50,000 records is value of a parameter. set link has to be used to align x-axis and x2-axis. And I want to show x2tic labels for counter/index which must be related to the time(column 1).
The output is alright, but you can see from the attached figure that the labels on x2-axis are big numbers, which is not what I want. I want to get labels like "1,3,5...".
So what's wrong with my code? And how to correct it? Thanks.
If the idea is that the x2 axis should be labeled with the content of column 2 regardless of its numerical relationship to column 1, then you can use:
set xdata time
set timefmt "%d-%H:%M:%S"
set format x "%H:%M:%S"
set xtics nomirror
set x2tics nomirror
set link x2
plot $Data using 1:2:x2ticlabels( int($0+1)%2 ? strcol(2) : "" ) title columnheader(2)
This creates one x2 axis tick label for every data point. The even-numbered ones to blank and the odd-numbered ones are set to whatever is in column 2.
the quickest fix would be
set link x2 via x-86397 inverse x+86397
But it depends what timesteps you have and what numbers you have in column 2. If your time step it is strictly regular and 1 second, and column 2 just counts up, then column 2 is redundant.
Timedata is handled internally as seconds from 01.01.1970 00:00:00.
One day has 86400 seconds. Check help time/date.
I'm trying to put dates on my x-axis. My data is plotted and correctly scaled but the x-axis only shows dates (correctly formatted) in a small range of August 1970. Here are the statements I'm using to set up the axis:
set format x "%Y%m%d"
set xrange [ '19400101' : '20200101' ] noreverse nowriteback
set xtics time
set xtics format "%m/%d/%Y"
set xtics border out scale 3.5,1.5 nomirror rotate by 45 offset character -5.5, -2.75
set xtics '19400101', 3.1536e+004, '20200101' norangelimit font "arial,10"
set xlabel "ASDF" # <===== just a test--works fine
set xlabel offset character 0, 0, 0 font "" textcolor lt -1 norotate
If I type show xrange I get [ 1.94001e+007 : 2.02001e+007 ]. Shouldn't I
be getting seconds from 01/01/1970?
What am I missing?
Al Chakrin
there are several things:
first, one needs to make Gnuplot aware that the x-data is indeed time data with set xdata time
further, one should specify the input format of the time data. In this particular case, it would be set timefmt "%Y%m%d" (the commands set format x etc. only control how the date/time data is displayed not how it should be parsed)
in your plot, the tics spacing is specified as 3.1536e+004 (seconds). This will most likely result in warning: Too many axis ticks requested. If this number should represent one year, it should be set to 3.1536e+007 = 365*24*60*60 since the date/time data is internally indeed represented in terms of Unix timestamps (you can check this when you load your script by typing print GPVAL_X_MAX - this gives a value of 1577836800.0 which corresponds to the specified date of 1. 1. 2020)
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 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.
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.