2D countour in gnuplot - gnuplot

How to make countour in gnuplot?
I want to plot:
5.300000e+04 1.300000e+02 5.436518e+06
5.300000e+04 1.325000e+02 5.126855e+06
5.300000e+04 1.350000e+02 4.803566e+06
5.300000e+04 1.375000e+02 4.457970e+06
5.300000e+04 1.400000e+02 4.103957e+06
5.300000e+04 1.425000e+02 3.734172e+06
5.300000e+04 1.450000e+02 3.352012e+06
.....
.....
I tried
cd 'G:\'
set view map
set dgrid3d
set ytics font "Times New Roman,12"
set xtics font "Times New Roman,12"
unset key
set palette rgbformulae 30,31,32
set decimalsign ','
set format y "%5.1f"
set format x "%5.1f"
splot "mapa.txt" using 1:2:3 with pm3d
with result
enter image description here
How to edit the right side to see the numbers completly and how is the scale called to change the font?

You can adjust the width of the right margin with:
set rmargin at screen XXX
where XXX is a number from 0 to 1. Exactly the same for the top margin (tmargin), bottom margin (bmargin) and left margin (lmargin).
The color scale is called colorbox in gnuplot.
This more or less does what you want:
set view map
set dgrid3d
set ytics font "Times New Roman,12"
set xtics font "Times New Roman,12"
unset key
#Adjust the width of left and right margins so that the numbers fit
set lmargin at screen 0.1
set rmargin at screen 0.85
set palette rgbformulae 30,31,32
set decimalsign ','
set format y "%5.1f"
set format x "%5.1f"
# Change font of color scale
set cbtics font "Times New Roman,12"
splot "mapa.txt" using 1:2:3 with pm3d

Related

gnuplot: add values above bar graphs

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

Smooth gradient display of function of two (xy) variables in gnuplot?

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

Gnuplot: Hidden3D

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:

Gnuplot Candlesticks and boxwidth

Been working with candlesticks on real financial data. It works great unless I have gaps in the data, which there are plenty with historical financial data.
I have had "set boxwidth 1 relative" and it works ok, it gives me a proper "width" of the candlestick in most cases. But if there is no data between 2 points the candlestick will become fatter, i.e. it extends right to fill that gap. The visual is horrible, the extension to the right is really bad.
I have tried playing with set boxwidth x absolute, but I cannot come to terms in how it is displaying. I have narrowed it down to set boxwidth 37500 absolute and have no idea why that number works, even though it has even worse problems then the set boxwidth 1 relative.
The first image is what it looks like using set boxwidth 37500 absolute. There the dates goes from 01/31/13, 02/01/13, 02/03/13, 02/04/13, 02/05/13. There is no 02/02/13:
The absolute shows a proper gap between 02/01 and 02/02 but 02/03 and 02/04 overlap for reasons I cannot explain.
The second image uses set boxwidth 1 relative. This has it mostly the way I want it. The candlesticks are adjacent and mostly right. But the gap on 02/02/13 it fattens to the right. There is also a gap on 02/09/13 where it also fattens, or possibly the 2 on either side extend to fill the gap I do not know.
How can I configure this so that all the candlesticks are the same width adjacent and gaps in the data are empty?
I googled this like crazy and no one talks about it. The few examples of candlesticks that I have found do not use "dates" but integers, totally worthless. Candlestick charts require dates per the manual.
Running Gnuplot 4.6 patchlevel 0 on Windows 7.
Thank you
PS: I should have added data here goes.
basic.csv:
2013-01-15 00:00:00,93.879000,93.949000,92.874000,93.078000
2013-01-16 00:00:00,93.079000,93.672000,92.458000,92.800000
2013-01-17 00:00:00,92.799000,95.011000,92.629000,94.616000
2013-01-18 00:00:00,94.617000,94.872000,94.157000,94.662000
2013-01-20 17:00:00,94.649000,94.820000,93.965000,94.155000
2013-01-21 00:00:00,94.159000,94.938000,93.726000,94.009000
2013-01-22 00:00:00,94.011000,94.284000,93.147000,93.231000
2013-01-23 00:00:00,93.229000,94.024000,92.793000,93.649000
2013-01-24 00:00:00,93.650000,94.715000,93.559000,94.489000
2013-01-25 00:00:00,94.490000,95.083000,94.472000,94.749000
2013-01-27 17:00:00,94.819000,95.007000,94.652000,94.834000
2013-01-28 00:00:00,94.835000,94.968000,94.082000,94.809000
2013-01-29 00:00:00,94.803000,95.330000,94.370000,95.248000
2013-01-30 00:00:00,95.245000,95.450000,94.255000,94.365000
2013-01-31 00:00:00,94.372000,95.799000,94.328000,95.714000
2013-02-01 00:00:00,95.715000,96.718000,95.457000,96.597000
2013-02-03 17:00:00,96.716000,96.777000,96.370000,96.572000
2013-02-04 00:00:00,96.574000,97.064000,95.968000,96.044000
2013-02-05 00:00:00,96.043000,97.426000,95.945000,97.131000
2013-02-06 00:00:00,97.133000,97.284000,96.092000,96.395000
2013-02-07 00:00:00,96.396000,97.023000,95.813000,96.145000
2013-02-08 00:00:00,96.146000,96.182000,95.124000,95.625000
2013-02-10 17:00:00,95.623000,95.744000,95.210000,95.339000
2013-02-11 00:00:00,95.336000,96.877000,95.168000,96.537000
2013-02-12 00:00:00,96.536000,96.719000,95.776000,96.214000
2013-02-13 00:00:00,96.216000,96.890000,96.114000,96.775000
2013-02-14 00:00:00,96.771000,96.964000,95.609000,95.621000
2013-02-15 00:00:00,95.622000,96.676000,95.521000,96.351000
absolute.plt:
reset
set border linecolor rgbcolor "yellow"
set key textcolor rgbcolor "white"
set obj 1 rectangle behind from screen 0,0 to screen 1,1
set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "black"
set xdata time
set timefmt"%Y-%m-%d %H:%M:%S"
set xrange ["2013-01-15 00:00:00":"2013-02-15 23:59:59"]
set yrange [*:*]
set datafile separator ","
set palette defined (-1 'red', 1 'green')
set cbrange [-1:1]
unset colorbox
set style fill solid noborder
set boxwidth 37500 absolute
set title "AUDJPY" textcolor rgbcolor "white"
plot 'basic.csv' using 1:2:4:3:5:($5 < $2 ? -1 : 1) with candlesticks palette
relative.plt:
reset
set border linecolor rgbcolor "yellow"
set key textcolor rgbcolor "white"
set obj 1 rectangle behind from screen 0,0 to screen 1,1
set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "black"
set xdata time
set timefmt"%Y-%m-%d %H:%M:%S"
set xrange ["2013-01-15 00:00:00":"2013-02-15 23:59:59"]
set yrange [*:*]
set datafile separator ","
set palette defined (-1 'red', 1 'green')
set cbrange [-1:1]
unset colorbox
set style fill solid noborder
set boxwidth 1 relative
set title "AUDJPY" textcolor rgbcolor "white"
plot 'basic.csv' using 1:2:4:3:5:($5 < $2 ? -1 : 1) with candlesticks palette
When using set boxwidth absolute, the width is given in units of the x-axis, which in the case of dates is seconds. So, a width of 37500 is 10 hours.
You could also use an explicit width in the 6th column, and switch to -2 to get an automatic box width for certain columns. That however would require you to manipulate your data file by hand.
Another point: Is it essential for you to include the hours in some data points? This is what narrows the distance of some adjacent points. You could ignore the hours, which would give you a point distance of minimum one day. To strip the hours, use strptime in the using statement:
reset
set border linecolor rgbcolor "yellow"
set key textcolor rgbcolor "white"
set obj 1 rectangle behind from screen 0,0 to screen 1,1
set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "black"
set xdata time
set timefmt"%Y-%m-%d %H:%M:%S"
set xrange ["2013-01-15 00:00:00":"2013-02-15 23:59:59"]
set yrange [*:*]
set datafile separator ","
set palette defined (-1 'red', 1 'green')
set cbrange [-1:1]
unset colorbox
set style fill solid noborder
set boxwidth 60000 absolute
set title "AUDJPY" textcolor rgbcolor "white"
plot 'basic.csv' using (strptime('%Y-%m-%d', strcol(1))):2:4:3:5:($5 < $2 ? -1 : 1) with candlesticks palette
Result with 4.6.0:
Another script,
from candlestick_chart import Candle, Chart
# Add some candles
candles = [
Candle(133.520004, 133.610001, 126.760002, 129.410004),
Candle(128.889999, 131.740005, 128.429993, 131.009995),
Candle(127.720001, 131.050003, 126.379997, 126.599998),
Candle(128.360001, 131.630005, 127.860001, 130.919998),
Candle(132.429993, 132.630005, 130.229996, 132.050003),
]
# Create and display the chart
# Optional keyword arguments: title, width, height
chart = Chart(candles, title="Optional title")
# Set the chart title
chart.set_name("BTC/USDT")
# Set customs colors
chart.set_bear_color(1, 205, 254)
chart.set_bull_color(255, 107, 153)
chart.set_vol_bull_color(1, 205, 254)
chart.set_vol_bear_color(255, 107, 153)
# Set custom labels (empty string => label not displayed)
chart.set_label("highest", "ATH")
chart.set_label("lowest", "ATL")
chart.set_label("average", "")
chart.set_label("volume", "")
# Volume pane settings
chart.set_volume_pane_height(6)
chart.set_volume_pane_enabled(False)
# And, it is also responsive!
new_width = 200
new_height = 150
chart.update_size(new_width, new_height)
# By the way, did you know that you can add more candles in real-time?
chart.update_candles(candles[:3])
# Or completely replace current candles `enter code here`
chart.update_candles(candles[:3], reset=True)
chart.draw()

Placing label over mapped 3D graph in Gnuplot

I want the below desired effect
I am using a gnuplot script similar to this
reset
set term postscript eps enhanced "Helvetica" 30
set size square
set xlabel "X position"
set ylabel "Y position"
set pm3d map
set palette rgbformulae 22,13,-31
set xrange [0 : 22.0000000000]
set yrange [0 : 17.0000000000]
set zrange [0 : 0.1614027105]
set xtics 5
set ytics 0,4
set cbtics 0,0.020
set style line 1 lw 1
unset key
set dgrid3d 45,45
set style line 1 lt 1
set hidden3d
splot "data.data" u 1:2:3
set label "98.8" at 9,-2 textcolor lt 1
set label "1.2" at 9,6 textcolor lt 1
But when I do, the labels (98.8, and 1.2) don't get printed. If I provide a bogus data.data file, lets say with only a single (x,y,z) point, then nothing gets graphed and I can see the labels. Therefore, I am guessing that my graph is occluding my labels. How do I get the labels to be printed on top of my graph?
The default placement for labels is in back.
But you can specify that the label show up in front, e.g.:
set label "label in front" at 2.5,0.5 tc rgb "white" font ",30" front
Credit: the (very slightly modified) code for this was found at http://gnuplot.sourceforge.net/demo_svg_4.5/pm3dcolors.html and/or link(s) therefrom.
Also for further information on the placement of text in gnuplot, I found this reference to be very useful.

Resources