Including solid and dashed contours in gnuplot - gnuplot

i have the following in a gnuplot script:
set pm3d
unset surface
set pm3d map
set style line 1 lt 1 lc rgb "white"
set style line 2 lt 1 lc rgb "white"
set style line 3 lt 1 lc rgb "white"
set style line 4 lt 1 lc rgb "red"
set style line 5 lt 1 lc rgb "blue"
set style line 6 lt 2 lc rgb "white"
set style line 7 lt 2 lc rgb "white"
set style line 8 lt 2 lc rgb "white"
set style line 9 lt 2 lc rgb "white"
set style increment userstyles
set contour base
set cntrparam levels 8
set cntrparam levels discrete -8*0.0004946, -6*0.0004946, -4*0.0004946, -2*0.0004946, -2*0.0004946, 4*0.0004946, 6*0.0004946, 8*0.0004946
set nokey
splot '/data/ltl21/Data/PDB/HDFNI/BlindSurvey/imageresults/spectrum/HDF1map:189.20135-62.20442' u 1:2:3
Such that, i would like to have dashed contours for negative values, and solid contours for positive values. I can change the colour of contours with the above fine, though i want them to all be white, but it doesn't seem to use lt at all, it just picks its own line style and uses that..
Does anyone know how to specify the linetype for individual contours?
Cheers

Same question just appeared to me. Here is a nice workaround I found at http://www.gnuplot.info/faq/faq.html :
gnuplot> # An example. Place your definition in the following line:
gnuplot> f(x,y) = y - x**2 / tan(y)
gnuplot> set contour base
gnuplot> set cntrparam levels discrete 0.0
gnuplot> unset surface
gnuplot> set table ’curve.dat’
gnuplot> splot f(x,y)
gnuplot> unset table
gnuplot> plot ’curve.dat’ w l
Use splot with your standard options. You can save more than one contour in one file. Each contour in the same file will be plotted in the same style.
You can set your plot options as usual: linestyle, linetype etc. That's how I used it:
gnuplot> set cntrparam levels discrete 0,1,2,3
gnuplot> set style line 1 lt 2 lw 4 lc rgb "cyan"
gnuplot> set table 'mycontours.dat'
gnuplot> splot 'mydata.dat' matrix
gnuplot> unset table
gnuplot> plot 'mycontours.dat' ls 1
It returned 4 dashed cyan contours in epslatex. It seems you need to save to different files for different contour styles (or edit the file by hand).

multiplot may be used to address this issue:
set pm3d
unset surface
set pm3d map
set view map
set key center rmargin
set dgrid3d 15,31
set hidden3d
set contour base
set nosurface
set grid lw 1 lc rgb 'gray'
f(x,y) = x*y
set nokey
set cntrparam levels discrete 2, 4, 6, 8
set linetype 1 lc rgb '#0042ad' lw 1.3
set linetype 2 lc rgb '#0060ad' lw 3.1
set linetype 3 lc rgb '#007cad' lw 31
set linetype 4 lc rgb '#0099ad' lw 0.31
set cntrlabel start 25 interval -1 font 'arial, 1'
set style textbox noborder
set multiplot
splot f(x,y) w l title ''
unset pm3d
set linetype 1 lc rgb '#00ada4' lw 2 dashtype 2
# notice how changing 'lw' or 'dashtype' does not have any effect after first use:
set linetype 2 lc rgb '#00ad88' lw 1 dashtype 1
set linetype 3 lc rgb '#00ad6b' lw 3 dashtype 4
set linetype 4 lc rgb '#eeeeee' lw 4 dashtype 3
set cntrparam levels discrete -8, -6, -4, -2
splot f(x,y) w l
unset multiplot
Unsetting pm3d is crucial or it will draw over the lines from the first splot command.

Related

How to make xtics label color variable in box plot in GNUPlot?

This is my attempt at making the xtics label color match the line color in a box plot in gnuplot:
$DATA << EOD
1 1
2 2
3 3
EOD
set linetype 1 linecolor rgb "red"
set linetype 2 linecolor rgb "green"
set linetype 3 linecolor rgb "blue"
set key off
set boxwidth 0.5
set style fill solid 0.5
set xrange [0:4]
set yrange [0:4]
set xtics ("1" 1) textcolor rgb "red"
set xtics add ("2" 2) textcolor rgb "green"
set xtics add ("3" 3) textcolor rgb "blue"
plot $DATA using 1:2:1 with boxes linecolor variable
But it does not work:
Any idea? Thanks!
I'm not sure whether you can set xtics individually in different colors. So, the following solution sets the xtics as empty lines and you plot your xtics with labels with a certain offset. The disadvantage is that you have to set the y-position here: (0) with offset 0,-1. I hope there are better solutions.
Code:
### "xtic labels" in different colors
reset session
$Data << EOD
1 1
2 2
3 3
EOD
set linetype 1 lc "red"
set linetype 2 lc "green"
set linetype 3 lc "blue"
set key off
set boxwidth 0.5
set style fill solid 0.5
set xrange [0:4]
set yrange [0:4]
set format x "\n" # xtic label empty line
plot $Data u 1:2:1 w boxes lc var, \
'' u 1:(0):1:1 w labels tc var offset 0,-1
### end of code
Alternatively, you could use an offset relative to the graph:
plot $Data u 1:2:1 w boxes lc var, \
'' u 1:(0):1:1 w labels tc var offset 0, graph -0.05
Result:

GNUPLOT: First data row not shown in barchar [duplicate]

Am using gnuplot 5.0. with the following as pereamble to each script:
set terminal epslatex 8 color standalone colortext
The issue is that gnuplot is skipping the first row. To my knowledge 4.6 version addressed a similar issue.
Any idea on the problem please?
Example of data file points.dat
4 4
4 -4
-4 4
-4 -4
The first line (4, 4) is skipped. So instead of four points, only three are displayed by gnuplot. Herewith the command am using
#!/bin/bash
set terminal epslatex 8 color standalone colortext
set output outputFileName
set size .55,.55
set pointsize 3.0
##############
# Line styles
##############
set linestyle 1 lt 5 lw 1 #
set linestyle 2 lt 2 lw 1.5
set linestyle 3 lt 6 lw 1 #
set linestyle 4 lt 3 lw 1
set linestyle 5 lt 2 lw 2 #
set linestyle 6 lt 1 lw 2
##################
# Titles
##################
set title 'Image'
set xlabel '$x$' offset 0,0.5
set ylabel '$y$' offset 2,0
set macros
filename_init = sprintf("%s/image_init.dat",dataFileDirectory)
set key autotitle columnhead
set key horiz
set multiplot
plot
filename_init u 1:2 with points lt 0 pt 1 lw 5 lc rgb "magenta" notitle 'initial'
On trick to bypass the issue is to duplicate the first row. Bu this is not practical.
With set key autotitle columnheader gnuplot uses the entries in the first row as key entries, even though for the plot you have specified notitle.
To demonstrate this, consider the following script, using the four data points in points.dat, which you posted:
set terminal pngcairo
set output 'foobar.png'
set offsets 1,1,1,1
set key autotitle columnhead
filename_init = 'points.dat'
set multiplot layout 1,2
plot filename_init u 1:2 with points lt 0 pt 1 lw 5 lc rgb "magenta"
set key noautotitle
plot filename_init u 1:2 with points lt 0 pt 1 lw 5 lc rgb "magenta" title 'initial'
unset multiplot
The result is
So, just remove the line set key autotitle columnhead from your script, and use plot ... title 'initial'. That gives you the expected result.

gnuplot: first row of data skipped

Am using gnuplot 5.0. with the following as pereamble to each script:
set terminal epslatex 8 color standalone colortext
The issue is that gnuplot is skipping the first row. To my knowledge 4.6 version addressed a similar issue.
Any idea on the problem please?
Example of data file points.dat
4 4
4 -4
-4 4
-4 -4
The first line (4, 4) is skipped. So instead of four points, only three are displayed by gnuplot. Herewith the command am using
#!/bin/bash
set terminal epslatex 8 color standalone colortext
set output outputFileName
set size .55,.55
set pointsize 3.0
##############
# Line styles
##############
set linestyle 1 lt 5 lw 1 #
set linestyle 2 lt 2 lw 1.5
set linestyle 3 lt 6 lw 1 #
set linestyle 4 lt 3 lw 1
set linestyle 5 lt 2 lw 2 #
set linestyle 6 lt 1 lw 2
##################
# Titles
##################
set title 'Image'
set xlabel '$x$' offset 0,0.5
set ylabel '$y$' offset 2,0
set macros
filename_init = sprintf("%s/image_init.dat",dataFileDirectory)
set key autotitle columnhead
set key horiz
set multiplot
plot
filename_init u 1:2 with points lt 0 pt 1 lw 5 lc rgb "magenta" notitle 'initial'
On trick to bypass the issue is to duplicate the first row. Bu this is not practical.
With set key autotitle columnheader gnuplot uses the entries in the first row as key entries, even though for the plot you have specified notitle.
To demonstrate this, consider the following script, using the four data points in points.dat, which you posted:
set terminal pngcairo
set output 'foobar.png'
set offsets 1,1,1,1
set key autotitle columnhead
filename_init = 'points.dat'
set multiplot layout 1,2
plot filename_init u 1:2 with points lt 0 pt 1 lw 5 lc rgb "magenta"
set key noautotitle
plot filename_init u 1:2 with points lt 0 pt 1 lw 5 lc rgb "magenta" title 'initial'
unset multiplot
The result is
So, just remove the line set key autotitle columnhead from your script, and use plot ... title 'initial'. That gives you the expected result.

Gnuplot not filling the lines in 3D graphics

I'm ploting with gnuplot but in the 3D graphics some areas are not completed, empty.
The question is simple: how to force it to fill the empty areas ?
Commands that I'm using:
fit (a**-(x**(y**b))) './Tabela_perda_01_MOS_70ms_com_sameq_GOP_30_2_Foot.txt' using 1:2:3:(1) via a,b
set clabel '%8.2f'
set key right
set xlabel "X"
set ylabel "Y"
set zlabel "Z"
set xrange [0:1]
set yrange [2:20]
set zrange [0:1]
set isosample 11,20
set pointsize 0.5
set style line 1 lt 1 lw 2 pt 3 lc rgb "black"
set style line 2 lt 1 lw 1 pt 3 lc rgb "black"
splot "./Tabela_perda_01_MOS_70ms_com_sameq_GOP_30_2_Foot.txt" using 1:2:3 notitle w points ls 1, (a**-(x**(y**b))) w l ls 2

Drawing axis-aligned bounding box (AABB) in gnuplot

I have plotted two vectors (3,3,2), (2,2,1) and want to add an AABB to the first one
to show that the second vector is within the bounds of the first.
Adding set object rectangle from screen 0,0 to screen 3,3 front is not working.
So how can I draw the AABB (or a cuboid with a=3, b=3 and c=2)?
Also how can I put the the scale of the y-axis on the left side.
Still open:
Limit scale of y-axis to left side, and scale of x-axis to bottom front
Add arrows to x-, y- and z-axis
Delete the second x- and y- axis so that there is just one of each left
Gnuscript resource_vec_aabb
set xyplane 0
set grid
set xrange [0:5]
set yrange [0:5]
set zrange [0:5]
splot 'resource_vec_aabb.dat' with vectors filled head lw 2
Data resource_vec_aabb.dat
# Gnuplot .dat file for vectors
0 0 0 3 3 2
0 0 0 2 2 1
UPDATE
set termoption dashed #Needs to be set to draw dashed lines
set border 19 #To set axis (1 + 2 + 16). See: set border help
set xyplane 0
set grid
unset key
my_range = 4
set xrange [0:my_range]
set yrange [0:my_range]
set zrange [0:my_range]
set arrow from graph 0,0,0 to graph 1.05,0,0 size screen 0.025,15,60 \
filled ls 1 linecolor rgb "black"
set arrow from graph 0,0,0 to graph 0,1.05,0 size screen 0.025,15,60 \
filled ls 1 linecolor rgb "black"
set arrow from graph 0,0,0 to graph 0,0,1.05 size screen 0.025,15,60 \
filled ls 1 linecolor rgb "black"
set xtic 1
set ytic 1
set ztic 1
# AABB for 3,3,2
set arrow from 3,0,0 to 3,3,0 nohead linetype 2 linecolor rgb "green"
set arrow from 3,3,0 to 3,3,2 nohead linetype 2 linecolor rgb "green"
set arrow from 0,3,0 to 3,3,0 nohead linetype 2 linecolor rgb "green"
set arrow from 0,3,2 to 3,3,2 nohead linetype 2 linecolor rgb "green"
set arrow from 0,3,0 to 0,3,2 nohead linetype 2 linecolor rgb "green"
set arrow from 0,0,2 to 0,3,2 nohead linetype 2 linecolor rgb "green"
set arrow from 0,0,2 to 3,0,2 nohead linetype 2 linecolor rgb "green"
set arrow from 3,0,0 to 3,0,2 nohead linetype 2 linecolor rgb "green"
set arrow from 3,0,2 to 3,3,2 nohead linetype 2 linecolor rgb "green"
# 2,2,1
set arrow from 2,0,0 to 2,2,0 nohead linetype 2 linecolor rgb "blue"
set arrow from 0,2,0 to 2,2,0 nohead linetype 2 linecolor rgb "blue"
set arrow from 2,2,0 to 2,2,1 nohead linetype 2 linecolor rgb "blue"
set arrow from 0,0,1 to 2,0,1 nohead linetype 2 linecolor rgb "blue"
set arrow from 0,0,1 to 0,2,1 nohead linetype 2 linecolor rgb "blue"
set arrow from 0,2,1 to 2,2,1 nohead linetype 2 linecolor rgb "blue"
set arrow from 2,0,1 to 2,2,1 nohead linetype 2 linecolor rgb "blue"
set arrow from 2,0,0 to 2,0,1 nohead linetype 2 linecolor rgb "blue"
set arrow from 0,2,0 to 0,2,1 nohead linetype 2 linecolor rgb "blue"
set view 40,44,1
splot 'resource_vec_aabb.dat' with vectors filled head lw 2
new output
Here is a suggestion to draw your bounding box with vectors and tic labels at the back y-axis. The bounding boxes are plotted instead of tediously drawn by arrows. There is still room for fine tuning.
Data: SO17363018.dat
# Gnuplot .dat file for vectors
0 0 0 3 3 2
0 0 0 2 2 1
Script: (works for gnuplot>= 4.6.0, March 2012)
### draw bounding box of vectors
reset
FILE = "SO17363018.dat"
set termoption dashed # required for gnuplot4.6 for dashed lines
set xlabel "x-axis" rotate parallel
set ylabel "y-axis" rotate parallel
set xyplane 0
set grid x,y
set xrange [0:5]
set yrange [0:5]
set border 19
set xtics 1 nomirror
set ytics axis
set for [i=1:3] arrow i from graph 0,0,0 to \
graph (1.12*(i==1)), (1.12*(i==2)), (1.12*(i==3)) \
size screen 0.025,15,60 filled ls 1 lc rgb "black"
x0(i,j,k) = ((i==0 ? 0 : i==1 ? k : j)*3+1)
y0(i,j,k) = ((i==0 ? j : i==1 ? 0 : k)*3+2)
z0(i,j,k) = ((i==0 ? k : i==1 ? j : 0)*3+3)
set key noautotitle
set view 61,49, 1.1
splot FILE u 1:2:3:($4-$1):($5-$2):($6-$3) w vec lc rgb "red" lw 2, \
for [c=0:1] for [i=0:2] for [j=0:1] for [k=0:1] FILE \
u (column(x0(i,j,k))):(column(y0(i,j,k))):(column(z0(i,j,k))): \
((i==0)*($4-$1)):((i==1)*($5-$2)):((i==2)*($6-$3)) \
every ::c::c w vec nohead ls 2 lw 1.5 lc c+2
### end of script
For current gnuplot versions 5.x, the script needs to be adapted slightly and you can be shorten the plot command a bit:
dashtype can be specified directly via dt 2, not via ls 2
one for loop less because in 4.6 lc variable doesn't seem to work together with ls 2.
splot FILE u 1:2:3:($4-$1):($5-$2):($6-$3) w vec lc rgb "red" lw 2, \
for [i=0:2] for [j=0:1] for [k=0:1] FILE \
u (column(x0(i,j,k))):(column(y0(i,j,k))):(column(z0(i,j,k))): \
((i==0)*($4-$1)):((i==1)*($5-$2)):((i==2)*($6-$3)):($0+1) \
w vec nohead lw 1.5 dt 2 lc var
Result: (created with gnuplot 4.6.0)

Resources