I have 2 files with points
C:\1.txt
C:\2.txt
I'm trying to plot both of them into the same plot.
set style line 1 lc rgb '#0060ad' lt 2 lw 2 pt 0 ps 1.5
plot 'C:\1.txt' with linespoints ls 1 , 'C:\2.txt' with linespoints ls 1
How to set 2 different y-axis range for them ([0:6000] and [0:150] for example)?
link to documentation
i've got it.
set yrange [0:6000]
set y2range [0:150]
set xrange [0:5]
set x2range [0:5]
set y2tics
plot 'C:\1.txt' axes x1y1 with lines , 'C:\2.txt' axes x2y2 with line
Related
i want to plot a path of lines on a splot of a function in one graph.
My code:
reset
#set output 'potential_tr_pfad3.tex'
set terminal tikz color size 18cm, 8cm
unset key
set view map
set samples 80, 80
set isosamples 80, 80
plot 'tr_path.dat' with circles lc rgb "#90EE90" fs transparent solid 0.15 border,\
'tr_path.dat' u 1:2 with linespoints lw 2 lc rgb "#000000"
set xr [x=-4:4]
set yr [y=-11:2]
potential(x,y) = 5*(x**2+y**2+8*x+6*y)**2+5*(x**2+y**2-6*x+8*y)**2+1000*y
set contour base
set cntrparam bspline
set cntrparam levels discrete 20000,10000,2500,0,-2500,-5000, -6000,-7000
do for [t=1:8] {
set linetype t lc rgb "#888888"
}
set xlabel "X"
set ylabel "Y"
set zlabel '{/Symbol P}' enhanced
set zlabel offset character 7, 9, 0
potential(x,y) = 5*(x**2+y**2+8*x+6*y)**2+5*(x**2+y**2-6*x+8*y)**2+1000*y
set xr [x=-4:4]
set yr [y=-10:1]
set style textbox opaque margins 0.5, 0.5 fc bgnd noborder linewidth 1.0
set cntrlabel start 0 format "%16.0f" font ",6" interval 100
unset surface
splot potential(x,y) with lines lc rgb "#000000",\
potential(x,y) with labels boxed notitle
with the data file:
0.00000000e+000 0.00000000e+000 1.0000000
0.00000000e+000 -1.00000000e+000 2.0000000
-7.21690590e-002 -2.37121212e+000 4.0000000
My solution until now was to combine the two tikz-pictures in LaTeX. But there must be a better way without getting in trouble with graph boundaries. Any ideas?
Greetings and Thank You in advance!
I guess, the problem here is that splot with contour and plot with circles cannot be used together.
One solution would be to plot the contour data into a table and then plot it together with one plot command.
I've rearranged or rewritten your code a bit. I guess this should come close what you want to achieve and can be tweaked further. Output below created with gnuplot 5.2.6 and wxt terminal.
Code:
### plot contour data together with something else
reset session
unset key
set view map
set samples 80, 80
set isosamples 80, 80
set xr [x=-4:4]
set yr [y=-11:2]
potential(x,y) = 5*(x**2+y**2+8*x+6*y)**2+5*(x**2+y**2-6*x+8*y)**2+1000*y
set contour base
set cntrparam bspline
set cntrparam levels discrete 20000,10000,2500,0,-2500,-5000, -6000,-7000
unset surface
# write contour data to table
set table $Potential
splot potential(x,y)
unset table
set xlabel "X"
set ylabel "Y"
set zlabel '{/Symbol P}' enhanced
set zlabel offset character 7, 9, 0
set style textbox opaque margins 0.5, 0.5 fc bgnd noborder linewidth 1.0
plot $Potential u 1:2 w l lc rgb "#888888",\
'' every 100 w labels boxed font ",6" notitle, \
'MyData.dat' u 1:2:3 w circles lc rgb "#90EE90",\
'' u 1:2:3 w lp lw 2 lc rgb "#000000"
### end of code
MyData.dat
0.00000000e+000 0.00000000e+000 1.0000000
0.00000000e+000 -1.00000000e+000 2.0000000
-7.21690590e-002 -2.37121212e+000 4.0000000
Result:
I have the following image using the code
set terminal png
set output 'plot.png'
set xlabel "GC (%)"
set ylabel "Proportion of genome"
set sample 1000
set xrange[0:100]
set yrange[0:]
set boxwidth 1
set style fill solid
set key off
set style line 1 lt 1 lc rgb "#0000FF" lw 3
set style line 2 lt 2 lc rgb "#32CD32" lw 3
Cauchy(x,xo,wi) = (1./pi) * wi / ((x - xo)**2 + wi**2)
plot 'compositionGC.txt' w boxes, 0.368187*Cauchy(x, 41.4226,1.72758) + 0.631813*Cauchy(x, 51.8272, 0.464711) ls 2
set yrange[0:GPVAL_Y_MAX]
set arrow from 47.2,0 to 47.2,GPVAL_Y_MAX front ls 1
replot
I have everything I need except that I want a vertical blue arrow separating the two peaks at 47.2 in the x-axis in the front. I cannot get it to work.
Do not change the yrange and replot.
Use this arrow command before the initial plot:
set arrow 1 from 47.2, graph 0 to 47.2, graph 1 front lc "blue"
My data file looks like:
0 12.6 303.1 3.4577387486
120 10.5 278.9 2.8814489572
...
640 9.45 301.3 2.5933040615
My code looks like:
set xlabel "Tiempo (min)"
set ylabel "Corriente en el anillo (mA)"
set y2label "Flujo (fotones/s)"
set ytics nomirror
set y2tics
set tics out
set autoscale y
set autoscale y2
plot 'tan_time_curr_flux.dat' using 1:3 lc rgb 'black' pt 6 lw 2 w lp axes x1y1 title "Corriente", 'tan_time_curr_flux.dat' using 1:4 lc rgb 'blue' pt 5 lw 2 w lp axes x2y2 title "Flujo"
My plot looks like:
As you can see, there is a little offset, in x, between respective data points. It is more clear as x grows. For example the actual last point for flux (flujo) is 640,2.59. But the plot shows that point at 700, 2.59. How can I tell gnuplot not to add any offset to the second (blue) line?
Thanks a lot! :)
Ps If I plot time (col. 1) vs either flux (col. 4) or current (col. 3)...
The values for x stay normal. (i.e. There is no offset)
I guess that's a bug.
However, simply use axes x1y2 for your second plot, since you only have one x-value.
I seem to be having some difficulty finding the answer to this question online. The title is the basic question, but to be more specific I would like to have two x axes, one at the top of the figure that is dependent on the one at the bottom. However, this is not a simple relationship, i.e. x2!=5*x1 or something like that. The relationship is given by the data file itself. So to be more specific I have a file that looks something like this:
V T P
2.0 15.0 0.586
3.0 17.4 0.798
4.0 25.3 1.023
5.0 28.9 1.124
6.0 30.2 1.456
I would like to make a plot of T with respect to (wrt) P on the x1y1 axes and have T wrt V on the x2y1 axes. So the x1 axis would display the P range and x2 would display the V range in the corresponding places of x1, i.e. 0.586 on x1 axis would have 2.0 on x2 axis at the same place. Is this actually possible in Gnuplot or do I have to have a relationship with the two x axes to do this? Any help would be greatly appreciated. Thank you in advance.
Here is how you can achieve this. I first show you the script and the result, and later explain the steps:
reset
set xtics nomirror
set x2tics
set autoscale xfix
set autoscale x2fix
set xlabel 'P'
set ylabel 'T'
set x2label 'V'
plot 'data.txt' using 3:2 with linespoints ps 2 lw 2 title 'T wrt P', \
'' using 3:2:x2tic(1) axes x2y1 with points ps 2 lw 2 title 'T wrt V'
I first plot T wrt P on x1y1. Afterwards I plot T wrt V on x2y1 and use for this the range and tic positions of P, but use the V values as tic labels for the x2 axis. This gives a linear scale for P and adapts V accordingly.
In order for this to work you must use set autoscale xfix and set autoscale x2fix. This uses the exact ranges and does not expand an axis to the next major tics, which would be done only for the x axis, but not for the x2 axis, which has custom tics.
You could of course also reverse the process and use a linear scale for V and adapt the P tics. In any case, for the custom tics, which are placed with xtic() or x2tic, the numbers are used like they are formatted in the data file.
reset
set xtics nomirror
set x2tics 1
set autoscale xfix
set autoscale x2fix
set xlabel 'P'
set ylabel 'T'
set x2label 'V'
plot 'data.txt' using 1:2:xtic(3) with linespoints ps 2 lw 2 title 'T wrt P', \
'' using 1:2 axes x2y1 with points ps 2 lw 2 title 'T wrt V'
Here, the points are shown for both plot lines, to demonstrate, that they really coincide.
In order to have the one command only generating the xtics, one can use NaN for the y-value. And if only some of the custom tics should be labels, one needs an appropriate check in the x2tic call. Here, I set labels only for all even rows $0 is the current row number, starting from 0):
reset
set xtics nomirror
set x2tics
set autoscale xfix
set autoscale x2fix
set xlabel 'P'
set ylabel 'T'
set x2label 'V'
plot 'data.txt' using 3:2 with linespoints ps 2 lw 2 title 'T wrt P', \
'' using 3:(NaN):x2tic((int($0) % 2) ? '' : stringcolumn(1)) axes x2y1 t ''
With the result:
The best way: Plot your data as usual on the x1 and y1 axes, but place additional labels on the x2-axis with x2tic(column_number):
set x2tics
set xtics nomirror
plot 'data.txt' using 3:2:x2tic(1) w lp
see: Plot y1 in x1 with respect to x2 axis
As the title says, I want to find a way to control the xtics in multiplot mode. The output is the following
The plots shown in the first two rows are OK. However, the following three suffer from the very same problem. The numbers on the x axes are very close to each other and in some cases overlapping. So, is there a way to fix this? All input is read from external data files and I cannot know beforehand what is the maximum value of t so as to set xrange [0:max] in every plot and then control the xtics. By the way, is it possible in gnuplot to read the external data file before the plot stage and define the maximum value of t in each plot?
Many thanks in advance.
EDIT
The script used to produce the above output is the following:
reset
set term postscript eps enhanced "Helvetica" 20 size 7in, 11in
set output 'plots.eps'
set size 1,1
set multiplot layout 4, 2
unset key
# plotting the time-evolution of the mLCN
set xrange [*:*]
set xlabel 't'
set ylabel 'mLCN'
plot "hh.rli" u 1:3 w l lc rgb 'black'
# plotting the time-evolution of the RLI
set xrange [*:*]
set xlabel 't'
set ylabel 'log(RLI)'
plot "hh.rli" u 1:(log10($2)) w l lc rgb 'black'
# plotting the time-evolution of the FLI
set xrange [*:*]
set xlabel 't'
set ylabel 'log(FLI)'
plot "hh.fli" u 1:(log10($2)) w l lc rgb 'black'
# plotting the time-evolution of the OFLI
set xrange [*:*]
set xlabel 't'
set ylabel 'log(OFLI)'
plot "hh.fli" u 1:(log10($3)) w l lc rgb 'black'
# plotting the time-evolution of the SALI
set xrange [*:*]
set xlabel 't'
set ylabel 'log(SALI)'
plot "hh.sali" u 1:(log10($2)) w l lc rgb 'black'
# plotting the time-evolution of the GALIs
set xrange [*:*]
set xlabel 't'
set ylabel 'log(GALIs)'
plot "hh.gali" u 1:(log10($2)) w l lt 1 lc rgb 'green',\
"hh.gali" u 1:(log10($3)) w l lt 1 lc rgb 'red',\
"hh.gali" u 1:(log10($4)) w l lt 1 lc rgb 'blue'
# plotting the time-evolution of the MEGNO
set xrange [*:*]
set xlabel 't'
set ylabel 'MEGNO'
plot "hh.megno" u 1:2 w l lc rgb 'black'
# plotting the time-evolution of the Spectral Distance (D)
set xrange [*:*]
set yrange [-0.1:4]
set xlabel 't'
set ylabel 'D'
plot "hh.sd" u 1:2 w l lc rgb 'black'
unset multiplot
reset
set terminal windows
quit
You can tell gnuplot to rotate the tick labels with:
set xtics rotate
That'll take more vertical space, though. You can probably find a compromise solution by picking an angle less than 90 degrees with:
set xtics rotate by 45
or whatever angle looks best.
You can try increasing the distance between individual tics. For example, in the bottom left corner plot, instead of showing every 500th tic, you may show every 1000th. This can be easily achieved by using
set xtics 1000