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:
My data is in polar coordinates and when i plot them and try to add the polar grid it will be complete circles but my data is only from 0-60 degrees.
How can i limit the grid only from 0-60 degrees only, and not a complete circle?
I am not aware of a built-in feature for this. However, as a workaround, one might use the multiplot in order to draw the grid lines manually.
For example:
set term pngcairo enhanced size 800,800
set output 'fig.png'
set angles degrees
set multiplot
set lmargin at screen 0.1
set tmargin at screen 0.9
set rmargin at screen 0.9
set bmargin at screen 0.1
set samples 1000
unset border
R_max = 1
dR = 0.2
phi_max = 60.
dphi = 15
set xr [0:R_max]
set yr [0:R_max]
set xtics out nomirror
unset ytics
set style line 42 lc rgb '#666666' dt 3
unset key
plot \
for [i=0:phi_max/dphi] (x>=0&&x<=R_max*cos(i*dphi))?tan(i*dphi)*x:1/0 w l ls 42
set polar
set trange [0:phi_max]
unset raxis
unset rtics
plot \
for [i=1:ceil(R_max/dR)] i*dR<=R_max?i*dR:1/0 w l ls 42
unset raxis
unset rtics
plot cos(t) w l lw 2 lc rgb 'dark-red'
produces:
Having a data file I want to add labels to my bar plot, but unfortunately the labels overlay above the first bar and I could not figure out how to add an offset to each label:
set xrange[0:30]
set y2tics font "Arial,8" mirror
#set y2tics rotate # rotating the y2ticks alongside with the y-axis
set xtics font "Arial,6"
#set datafile separator "\t"
set boxwidth 0.5 absolute # balkengroesse
set bmargin 0.6
set tmargin 0
set lmargin 0.9
set rmargin 0
set title "RTF History Analysis" font"Arial,9"
set ylabel "Max RTF" font"Arial,9" noenhanced
#set xlabel "Timestamp" font"Arial,9" noenhanced
#set xtics rotate 90 # turn the text to the vertical position
set style data boxes # boxplot
set style fill solid 0.5 noborder
set multiplot layout 3,1 # 3x vertical 1x horizontal
set grid xtics y2tics
set logscale y
set grid my2tics
set yrange[0.001:6500]
set logscale y2
set my2tics 10
unset ytics
set format "10^{%L}"
set xtics rotate by 50 offset -4.5,-3.00
set format y
plot "history_file.txt" u 7:xticlabels(2) w boxes lc rgb"blue" notitle, \
"history_file.txt" u 7:2:3 w labels rotate left font "Arial,6" lc rgb"blue" notitle
Part of data file:
recipe.rcp 14-03-2017-12:10 top 0.00656997498323 0.0074438616489 rx 0.00791297772894
recipe.rcp 14-03-2017-15:55 cibasic 0.00665396222124 0.00770821200216 tx 0.00938002006172
recipe.rcp 14-03-2017-16:27 cibasic 0.00654659192121 0.00791088142395 tx/tx_ 0.010395539525
recipe.rcp 15-03-2017-14:44 ci 0.0106795993772 0.0114679721169 top 0.0128018372288
recipe.rcp 15-03-2017-14:58 sens 0.0101868323628 0.011261329309 tx 0.0131594769347
Try
plot 'data' u 7:xticlabels(2) w boxes, '' u (column(0)):(.5):3 with labels
to place the labels with the boxes, all at the same height (y = 0.5).
To have the labels follow the box height, try
plot 'data' u 7:xticlabels(2) w boxes, '' u (column(0)):(0.01 +$7):3 with labels
I have a simple data I want to plot as 3D plot (3 columns divided by a comma):
33.26,0.0000001,1
67.02,0.0000010,2
101.64,0.0000100,3
137.53,0.0001000,4
175.06,0.0010000,5
214.59,0.0100000,6
256.47,0.1000000,7
301.09,1.0000000,8
348.78,10.0000000,9
399.92,100.0000000,10
454.87,1000.0000000,11
513.99,10000.0000000,12
577.65,10000.0000000,13
646.22,10000.0000000,14
720.05,10000.0000000,15
799.51,10000.0000000,16
884.96,10000.0000000,17
976.77,10000.0000000,18
1075.29,10000.0000000,19
1180.89,10000.0000000,20
1293.92,10000.0000000,21
1414.77,10000.0000000,22
1431.83,10000.0000000,23
1449.15,10000.0000000,24
1466.97,10000.0000000,25
1485.79,10000.0000000,26
1505.97,10000.0000000,27
1527.88,10000.0000000,28
1551.87,10000.0000000,29
1578.3,10000.0000000,30
1607.56,10000.0000000,31
1639.98,10000.0000000,32
1675.95,10000.0000000,33
1715.82,10000.0000000,34
1759.96,10000.0000000,35
1808.72,10000.0000000,36
1862.49,10000.0000000,37
1921.6,10000.0000000,38
1986.44,10000.0000000,39
2057.35,10000.0000000,40
2134.71,10000.0000000,41
2218.87,10000.0000000,42
2310.2,10000.0000000,43
2409.06,10000.0000000,44
2515.83,10000.0000000,45
I wrote a simple script to plot the above data:
#!/usr/bin/gnuplot
set palette rgbformulae 33,13,10
set datafile separator ","
set terminal postscript eps size 10.5, 5.62 enhanced color font 'Helvetica,20' linewidth 2
set output 'test.eps'
set xlabel "time [s] (no operation)" offset -4, 0, 0
set xtics left offset 0,-0.3 rotate by 45 right
set xrange [0:400]
set ylabel "ranges" offset 2, 0, 0
set ytics left offset 0,-0.5
set zlabel "devices" offset -4, 0, 0
set zrange [0:50]
set autoscale
set title " "
set key inside left top;
set dgrid3d 30,30
set hidden3d
set style line 1 linecolor rgb '00FF00' linetype 4 linewidth 1
splot "data.csv" u 1:2:3 title "" with lines palette
And my output:
As you all can see, the output image (or, I should say), the x,y and z ticks on axis x,y, and z are not enough detailed. It is hard to say that the output image was plotted with this data.
Is there a way that would let me manipulate the x,y, and z ticks, to be taken from file, in some elegant way?
I also would like the image to be more readable with new x,y, and z ticks, so I think that the 10000.0000000 value should appear only once, when it appeared for the first time in data file.
Thank you.
Not exactly an answer to your question, and it is my personal opinion, but you might be interested in the ideas:
The data seems not to be grid data, so I would not use a surface plot of any kind.
Plotting only the datapoints in 3d does not give a useful picture, it is only a single line somewhere in space. I would try to use a 2D plot which contains the height information as color.
I would use a logscale for the y-axis.
This leads to the following script:
set terminal pngcairo
set output 'test.png'
set datafile separator ","
set palette rgbformulae 33,13,10
# Set margins to keep colorbox label inside the picture
set lmargin screen 0.12
set rmargin screen 0.85
set xlabel "time [s] (no operation)"
set ylabel "ranges"
set cblabel "devices"
unset key
set yrange [1e-8:1e5]
set ytics format "1e%+T"
set logscale y
set view map
set cbrange [0:50]
set zrange [0:50]
splot "data.csv" u 1:2:3 w p pt 7 palette ,\
"data.csv" every 5::4 u ($1+0):($2/3):(0):($3 != 30 ? 3 : "") with labels
It also prints the z-labels of some datapoints, skipping 30 for spacing reasons.
This is the result:
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.