I plot a time-series of datas (images, throughput), using this:
set term postscript color eps enhanced 22
set encoding utf8
set output "tput.eps"
load "../styles.inc"
set size 1,0.6
set bmargin 4.5
set tmargin 2.5
set lmargin 9
set rmargin 8
set title "{/bold Images updated and generated network traffic}" offset 0,0
set ylabel "#Images" offset 0,0
set y2label "Throughput [GB/day]" offset -2,0
set ytics 0,100,800
set ytics nomirror
set y2tics 0,100,600
set y2tics nomirror
set xtics time
set format x '%d/%m/%Y'
set grid y
set yrange[0:800]
set y2range [0:]
set xtics rotate by 45 right font "Arial, 18" nomirror
set key vertical sample 1.0 maxrows 1 width -0.6 at graph 1,1.13 font "Arial, 18"
set datafile separator ","
plot "datecount_sorted.csv" using (timecolumn(1, "%Y-%m-%d")):($2) with lines ls 5001 title "Uploaded images",\
"datecount_sorted.csv" using (timecolumn(1, "%Y-%m-%d")):($3/(1024*1024*1024)) axis x1y2 ls 5002 title "Upload Throughput",\
!epstopdf "tput.eps"
!rm "tput.eps"
quit
The input data looks like this:
2016-04-12,1,0
2016-05-02,2,0
2016-05-05,2,0
2016-05-06,1,0
2016-05-11,2,0
2016-05-13,3,0
2016-05-25,2,0
2016-06-01,3,541204241
2016-06-06,1,0
2016-06-13,1,471311979
2016-06-14,1,6329289
2016-06-17,1,137972881
2016-06-24,1,319050239
2016-06-27,1,138193384
The output is correct, it looks like this:
The problem is that when I try to set an xrange, the plot breaks completely (does not render).
This syntax in particular seems to be wrong:
set xrange ["2020-01-01":"2020-06-17"]
And similarly wrong is the one using the same timefmt that is used in the plot:
set xrange ["01/01/2020":"17/06/2020"]
So..what is the correct syntax ?
What you are missing is set xdata time and set timefmt <format string> to tell gnuplot how read the dates from the data, the xrange is set using the format specified in timefmt, which doesn't have to be the same as the format you give to the axis, the plot breaks because it can't decode the dates from the xrange.
In your case adding this should suffice
set xdata time
set timefmt "%Y/%m/%d"
I tested it with set xrange ["2016/04/12":"2016/05/03"] on the example data file you posted.
You must explicitely parse the time strings passed to the range settings:
set xtics time
FMT="%Y-%m-%d"
set format x "%d/%m/%Y"
set xrange [strptime(FMT, "2016-01-01"):strptime(FMT, "2016-06-17")]
set datafile separator commna
plot "datecount_sorted.csv" using (timecolumn(1, FMT)):2 with lines title "Uploaded images"
Related
I have problems changing the font size of my ytics (xtics as well) in an epslatex gnuplot.
I tried set format y '\tiny{%g}'
It is only working for the first of the two plots.
This is my code:
set terminal epslatex
set output "w_alt_nsyB_multi.tex"
set multiplot layout 1,1
set xrange [-0.5:17]
set yrange [0:110]
set xlabel "days"
set ylabel "Survival (\\%)" offset 2.5
set key reverse
set xtics font 'Arial,4' s
et style histogram errorbars gap 2 lw 1
set style data histogram
set style fill solid 1 border lt -1
set boxwidth 0.8
plot 'w_alt_nsyB.dat' every ::::7 using 2:3:xticlabels(1) title 'w1118' lt rgb "#000000",\
'w_alt_nsyB.dat' every ::::7 using 4:5 title 'wtSYN' lt rgb "#FF0000",\
'w_alt_elav_endoG.dat' every ::::7 using 6:7 title '38085' lt rgb "#9400D3"
set origin 0.5, 0.25
set size 0.5, 0.5
set xrange [-0.5:6]
set yrange [0:110]
set xlabel "\\tiny{Time of $Mn^{2+}$ treatment}"
set ytics ('10'10,'50'50,'100'100) nomirror
unset border
set xtics nomirror
unset ylabel
unset key
plot 'w_alt_nsyB_100.dat' using 2:3:xticlabels(1) lt rgb "#000000",\
'w_alt_nsyB_100.dat' using 4:5:xticlabels(1) lt rgb "#FF0000",\
'w_alt_nsyB_100.dat' using 6:7:xticlabels(1) lt rgb "#9400D3"
unset multiplot
Can anyone help me please?
The format given in set format ... isn't applied if you give an explicit manual label like you do with
set ytics ('10'10,'50'50,'100'100)
You must either just give the locations of the labels
set format y '\tiny %g'
set ytics (10, 50, 100)
or include the font macro in every manual label
set ytics ('\tiny 10' 10, '\tiny 50' 50, '\tiny 100' 100)
Note also, that your syntax \tiny{%g} is wrong, \tiny is only a switch and doesn't take any arguments. In this case it doesn't matter, because every label is wrapped in an individual LaTeX box, but in other situations it makes a big difference. To wrap the tiny font you would usually need {\tiny %g}.
The same happens for the explicit labels which are set with xticlabel. Also here, the format from set format x doesn't apply. Instead of giving a column number to xticlabel (like xticlabel(1) in your example), you must give the complete label string including the macro:
xl(c) = sprintf('\tiny %s', strcol(c))
plot 'file.dat' using 2:3:xticlabel(xl(1))
Next time, please give a minimal example which allows others to reproduce your problem. We don't have your data files to run the script. And your problem isn't related to you specific data file, so you can as well construct an example using functions, which possibly leads you itself to the solution...
I'd like to show the values of a function of 2 variables, say x+y, as a "bitmap" image. So I tried this, based on http://gnuplot.sourceforge.net/demo/heatmaps.html:
# Color runs from white to green
set palette rgbformula -7,2,-7
set cbrange [-5:5]
set cblabel "Value"
unset cbtics
set xrange [-4.5:4.5]
set yrange [-4.5:4.5]
set view map
splot x+y with image
... but I get nothing:
$ gnuplot -persist test.gp
"test.gp", line 45: warning: Image grid must be at least 2 x 2.
So how can I get the "pixel" at, say, x=-2, y=-2 to be colored according to x+y=-4 on the cbrange?
Edit: got that:
set palette rgbformula -7,2,-7
set cbrange [-5:5]
set cblabel "Value"
unset cbtics
set xrange [-4.5:4.5]
set yrange [-4.5:4.5]
set pm3d
unset surface
set view map
splot x+y
Outputs:
But - say I want the gradient in this range, exported as "smooth" gradient (no axes, ticks, marks of any kind) on a big PNG, say 3000x2000 pixels; what would be the best way to achieve that?
Starting from your edit: You just to deactivate every thing. Meaning:
unset colorbox
unset xtics
unset ytics
set border 0
Then id you create the command list:
set palette rgbformula -7,2,-7
set cbrange [-5:5]
unset cblabel
unset cbtics
set xrange [-4.5:4.5]
set yrange [-4.5:4.5]
set pm3d
unset surface
set view map
unset colorbox
unset xtics
unset ytics
set border 0
splot x+y
You get only the gradient
EDIT: In order to improve the gradient step and create a smoother image you need to use pm3d's interpolate.
set pm3d interpolate 4,4
Is there a way I can hide these overlayed lines in the back of my plot? I tried to use the hidden3d option, but it doesn't work as I expected.
set encoding utf8
set key right top
set xrange[0:1]
set yrange[0:1]
set grid
set ztics 0.01
set palette rgbformulae -5,-12,-30
set xlabel "x" font "Helvetica, 20"
set ylabel "y" font "Helvetica, 20"
set zlabel "z" font "Helvetica, 20"
set terminal postscript eps enhanced color font "Helvetica, 20"
set output "approx_jacobi.eps"
ue(x,y) = sin(pi*x)*sin(pi*y)/(2*pi**2);
#set hidden3d front
set dgrid3d 31, 31 qnorm 2
splot 'results.dat' with pm3d notitle,\
ue(x,y) w l lw 2 t 'Exact'
The result I'm currently getting is
Using set hidden3d front works fine for me. I had to increase the isosamples a bit to avoid intersections of the lines with the surface due to the linear interpolation. Also you don't need to use set dgrid3d since you already have a regular grid.
set pm3d
set hidden3d front
set ticslevel 0
set isosamples 40
set palette rgbformulae -5,-12,-30
ue(x,y) = sin(pi*x)*sin(pi*y)/(2*pi**2)
splot 'results.dat' with pm3d, ue(x,y) w l
The result with 4.6.5 is:
Based on this post (I am using gnuplot gnuplot 4.6 patchlevel 1):
gnuplot: max and min values in a range
I am trying to use set yr [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX] in my .pg script that plots data from this .dat file:
100 2
200 4
300 9
But I get:
undefined variable: GPVAL_DATA_Y_MIN
This is my script:
set terminal png
set output 'img.png'
set xlabel 'x-label'
set ylabel 'y-label'
set boxwidth 0.5
set style fill solid
set yrange [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX]
plot 'sample.dat' with boxes title ""
Any ideas?
The gnuplot-defined variables are available only after a plot command (In the question you linked to, a replot is used to plot again).
Basically you have different options:
First plot to terminal unknown, and then change to the real terminal, set the range (now the variables are available), and replot:
set xlabel 'x-label'
set ylabel 'y-label'
set boxwidth 0.5 relative
set style fill solid
set terminal unknown
plot 'sample.dat' with boxes title ""
set terminal pngcairo
set output 'img.png'
set yrange [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX]
replot
Note, that I used the pngcairo terminal, which gives much better results, than the png terminal. And I used set boxwidth 0.5 relative.
Use set autoscale to fix the ranges instead of setting an explicit yrange. You can use set offset to specify a margin based on the autoscaled values:
set autoscale yfix
# set offset 0,0,0.5,0.5
plot 'sample.dat' with boxes title ''
Use the stats command to extract the minimum and maximum values:
stats 'sample.dat' using 1:2
set yrange[STATS_min_y:STATS_max_y]
plot 'sample.dat' with boxes title ''
I have put up a raspberry pi to measure temperature and call a Gnuplot script to place a graph on a webpage.
Now i want to make a couple of graphs that display 1hour backwards in time/1day backwards in time.
Does anyone know how i specify the X-range to start at "current time - 1 day" or "current time - 1 hour"?
Thanx!
This won't work everywhere, but if your gnuplot supports pipes and your system has the date command ...
TIMEFMT = "%Y:%m:%d:%H:%M:%S"
#now = "`date +%Y:%m:%d:%H:%M:%S`" #Use this line in production
now = '2013:01:24:20:49:30' #Hard-code this for the sake of the example ...
now_secs = strptime(TIMEFMT,now)
one_hour_past = now_secs - 3600.0
set xdata time
#set timefmt TIMEFMT #This doesn't parse correctly ... Not sure why...
eval(sprintf('set timefmt "%s"',TIMEFMT))
print strftime(TIMEFMT,one_hour_past)
#set xrange [strftime(TIMEFMT,one_hour_past):] #This doesn't seem to work
#set xrange ["2013:01:24:20:49:30":] #This works, but is declared statically -- Yuck.
eval(sprintf('set xrange ["%s":]',strftime(TIMEFMT,one_hour_past)))
plot '-' u 1:2 w l
2013:01:24:10:00:00 2.5
2013:01:24:21:00:00 2
2013:01:24:22:00:00 3
e
THe code i have used is as follows. Im running it on a Raspberry Pi with Rasbian OS. Any sudgestions? Thanx!
#!/usr/bin/gnuplot
reset
set terminal png size 1250,700
set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb"#E6E6FA" behind
set output '/var/www/bild.png'
set multiplot
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%H:%M\n%d/%m"
set xlabel "Timme/datum"
set ylabel "Inomhustemperatur"
set yrange [15:28]
set y2label "Utomhustemperatur"
set y2range [-20:10]
set y2tics nomirror
set y2tics
set title "Temperatur"
set key reverse Left outside
set grid
set style data lines
plot "logg.txt" using 1:3 axes x1y1 lw 3 title "inomhus", "" using 1:4 axes x1y2 lw 3 title "utomhus"#