I set-up a multiplot like this:
set terminal wxt size 1500,900
set format x "%d%m%y %H:%M:%S"
set xdata time
set timefmt x "%Y%m%dT%H%M%S"
set key font ",6"
set lmargin 10
set rmargin 10
set multiplot layout 2,1
plot "output.txt" u 1:2 w lines axes x1y1, \
"output.txt" u 1:3 w lines axes x1y2
plot "output.txt" u 1:40 w lines axes x1y1, \
"output.txt" u 1:39 w lines axes x1y2
set y2tics border
unset multiplot
Which works, and gives me 2 plots, one above the other.
But pressing the "replot" button (or using zoom) causes the second plot to fill the window - completely hiding the first plot.
Yes, that's how replot behaves. The documentation says: „Note that in multiplot mode, replot can only reproduce the most recent component plot, not the full set.“.
So, what you can do is to put the whole set multiplot ... unset multiplot stuff in an external file, load it, and then load it again. Or put that stuff in a string and eval it several times.
I had the same issue. Solved it with a loop:
set term wxt enh
do for [IDX = 0:1] {
if (IDX==1) {
set terminal png enhanced
set output 'temp.png'
}
set multiplot
set size 1,1
set origin 0,0
plot sin(x)
set size 0.5,0.35
set origin 0.13,0.63
plot cos(x)
unset multiplot
}
set output
set term wxt enh
Here is another workaround. It does not answer the question directly, but it could give idea to other similar issues. Put header, and a footer 'reread', then two context could be choosen for a similar multiplot (done twice)
if (exists("rehearse")) rehearse=1+rehearse; set term x11
if (!exists("rehearse")) rehearse=0; set term png; set output sprintf("test_palette_%s.png", system("date +\"%F\""))
pr "rehearse=".rehearse; show term #<= comment printing
set samples 100; set isosample 100,100
set xrange [0:1]; set yrange [0:1]
set palette defined (0 "white", 1 "red")
set autoscale cbfix; unset colorbox; unset key
set multiplot layout 2,2
plot '++' using 1:2:1 with image
plot '++' using 1:2:2 with image
plot '++' using 1:2:(-$1) with image
plot '++' using 1:2:(-$2) with image
unset multiplot
if(rehearse < 1) reread
Related
my gnuplot script plot bar graphs in the following 2D format:
using the following sctipt:
set term pngcairo size 800,600
set termoption noenhanced
set title "$file_name" font "Century,22" textcolor "#b8860b"
set tics font "Helvetica,10"
#set xtics noenhanced
set ylabel "Fraction, %"
set xlabel "H-bond donor/aceptor, residue"
set yrange [0:1]
set ytics 0.1
set grid y
set key off
set boxwidth 0.9
set style fill solid 0.5
plot '<cat' using 2:xtic(1) with boxes
In order to add values above the bars, I've tried to modify it to
plot '<cat' using 0:2:xtic(1) with boxes, '' u 0:2:2 w labels offset 0,1
but the values were not added to the bars, with the following warning
"/dev/fd/63" line 17: warning: Skipping data file with no valid points
I can only test for Windows, but I assume cat under Linux is the equivalent for type under Windows.
So, what is your filename? I would say your filename is simply missing. Check help piped-data.
Something like the following should work:
plot '<cat myDataFile.dat' using 0:2:xtic(1) with boxes, '' u 0:2:2 w labels offset 0,1
But then, what is the difference to using directly the filename?
plot 'myDataFile.dat' using 0:2:xtic(1) with boxes, '' u 0:2:2 w labels offset 0,1
I am trying to create a graphic using gnuplot 5.0 with two scales in the same x axis. I have managed to create one using the multiplot option with the following code:
reset
set terminal pngcairo
set output "test.png"
unset key
set ylabel "Temperature (C)"
set ytics nomirror
set yrange[0:7]
set multiplot layout 1,2
set xrange [0:5.99] #Avoid plotting the last xtics in the first graphic
set xlabel "Heating time (minutes)"
set rmargin at screen 0.7
plot x
set xrange [0:4]
set xlabel "Seconds after stop"
set rmargin
set lmargin at screen 0.7
set xtics 1
unset ylabel
unset ytics
set y2tics nomirror
set format y2 ''
f(x) = a * exp (-x*b)
a=6
b=1
plot f(x)
With this result:
I want to generate several images like this one and add them in a multiplot arrangement, but I am not sure if using nested multiplots will be easy. Is there an easier way to obtain each of the images without using multiplot, like splitting the xaxis in two components?
Thanks in advance.
Just in case this still might be of interest to the OP or somebody else... You don't explicitly write whether you want to plot functions or data from a datafile. In your examples you use functions.
You can do something without "nested" multiplots, which would certainly be possible as well, but probably getting a bit confusing.
So, maybe the following might be easier. You basically set the xtics "manually". In order to avoid typing the same code several times you can use macros (check help macros).
Code:
### multiplot graph with different x-axis scales
reset session
# define functions
Temperature(x) = x<t0 ? x*a/t0 : a*exp(-(x-t0)*b)
myColor(col) = column(col)<t0 ? 0xff0000 : 0x0000ff
myTic(x,t) = sprintf("%g", x<=t ? x : x-t)
# define macro
myPlot = "\
set xrange[0:t0+t1]; \
set arrow 1 from first t0, graph 0 to first t0, graph 1 nohead; \
set label 1 'heating' center at first t0/2., graph 0 offset 0,-2; \
set label 2 'cooling' center at first (t0+t1/2.), graph 0 offset 0,-2; \
set xtics (); \
do for [i=0:int(t0/dt1)] { set xtics add (myTic(i*dt1,t0) i*dt1) }; \
do for [i=0:int(t1/dt2)] { set xtics add (myTic(i*dt2,t1) i*dt2+t0) }; \
plot '+' u 1:(Temperature($1)):(myColor(1)) w l lc rgb var "
set samples 200
set key noautotitle
set bmargin 3
set ylabel "Temperature"
set grid x,y
set multiplot layout 2,2
t0=6; t1=4; dt1=1; dt2=1; a=6; b=1
#myPlot
t0=4; t1=10; dt1=1; dt2=2; a=4; b=0.5
#myPlot
t0=20; t1=30; dt1=5; dt2=10; a=2; b=0.1
#myPlot
t0=4; t1=4; dt1=1; dt2=1; a=10; b=1
#myPlot
unset multiplot
### end of code
Result:
When plotting an X,Y,Z data set as color map I need to smoothen the plot a bit. The data are sparse and I need some sort of gaussian blur applied to the result.
Using following code :
reset
#set zrange [2:6]
set contour
unset surface
set cntrparam levels incr 2.0,0.5,8.0
set view map
set xrange [0:2184]
set yrange [0:1472]
set dgrid3d 100,100,4
set table "ap130_base_contour.txt"
splot 'ap130_base.dat' using 11:12:14
unset table
unset contour
set surface
set table "ap130_base_dgrid.txt"
splot 'ap130_base.dat' using 11:12:14
unset table
reset
set pm3d map
unset key
set palette defined (0 '#352a87', 1 '#0363e1',2 '#1485d4', 3 '#06a7c6', 4 '#38b99e', 5 '#92bf73', 6 '#d9ba56', 7 '#fcce2e', 8 '#f9fb0e')
set autoscale fix
set grid
set terminal png size 2184,1472 enhanced font "Helvetica,20"
set output 'ap130_base.png'
splot 'ap130_base_dgrid.txt' w pm3d, 'ap130_base_contour.txt' w l lc rgb "black"
set output
set terminal X11
The plot looks like this;
Is there a way to make this less 'spotty'?
Your input is much appreciated.
Gert.
I am trying to plot two overlaping figures (one "big" and another smaller "zoomed-in"). The thing is I can't have a solid background on the entire "small" figure, meaning including labels, ticks labels, etc.
Does anyone have an idea ?
Here is a SWE of my problem (EDITED being closer to my problem):
reset
set multiplot
plot sin(x)/x ls -1
set size 0.4,0.4
set origin 0.6,0.5
set object 1 rectangle from graph 0,0 to graph 1,1 behind fc rgb "#04AA40"
plot sin(x)/x ls -1
unset multiplot
It looks like you could use almost exactly the same code as you posted, but change the multiplot commands and the coordinates so that the rectangle you make overlaps the labels of the figure as well:
reset
set multiplot title "Plot 1"
set object 1 rectangle from graph 0.45,0.45 to graph 1.1,1.1 front fc rgb "#04AA40"
plot sin(x)/x ls -1
unset object 1
set size 0.5,0.5
set origin 0.45,0.45
plot sin(x)/x ls -1
unset multiplot
If that doesn't work, can you explain why you can't have a background on the entire small figure, as you say?
I answer to my own question by this code which is the closest thing I am looking for, but still not happy with it. If anybody has an idea of how I can get the computed margins automatically, this answer could be the one...
reset
set multiplot title "Plot 1"
plot sin(x)/x ls -1
xorig_sub=.1
yorig_sub=.5
width_sub=.35
height_sub=.35
lmarg_sub=0.09
bmarg_sub=0.06
rmarg_sub=0.025
tmarg_sub=0.02
xmin=xorig_sub
xmax=xorig_sub+width_sub+rmarg_sub+lmarg_sub
ymin=yorig_sub
ymax=yorig_sub+height_sub+tmarg_sub+bmarg_sub
set object 1 rectangle front from screen xmin,ymin to screen xmax,ymax fc rgb "#04AA40" fs solid
clear
replot
unset object 1
set lmargin at screen xmin+lmarg_sub
set rmargin at screen xmax-rmarg_sub
set bmargin at screen ymin+bmarg_sub
set tmargin at screen ymax-tmarg_sub
set size width_sub,height_sub # set the size of the second plot in plot units
set origin xorig_sub,yorig_sub # set the origin for the second plot in plot units
plot sin(x)/x ls -1
unset multiplot
I recently had the same issue and saw the post. It might be a bit late in the game, but for the sake of completeness:
reset
set multiplot
plot sin(x)/x ls -1
set size 0.4,0.4
set origin 0.6,0.5
set object 1 rectangle from graph 0,0 to graph 1,1 fc rgb "#04AA40" fillstyle solid 0.0 noborder
set ticks front
plot sin(x)/x ls -1
unset multiplot
Works with gnuplot 5.0.
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"#