Gnuplot: How to plot a 45 degree line? - gnuplot

I want to plot data from two different years and insert a 45 degree line so you can easily see if the value increased or decreased. X- and Y-axis will be from 0 to 1.
Thanks in advance for any help, much appreciated!

As Thor says, 45 degrees can be plotted simply by using plot x.
For a more general solution, you can use tan.
For example, to plot all lines from 0 degrees to 85 degrees
set angles degrees
set xrange [0:1]
set yrange [0:1]
plot x*tan(0), x*tan(5), x*tan(10), x*tan(15), x*tan(20), x*tan(25), x*tan(30), x*tan(35), x*tan(40), x*tan(45), x*tan(50), x*tan(55), x*tan(60), x*tan(65), x*tan(70), x*tan(75), x*tan(80), x*tan(85)

Related

gnuplot stock chart using date on x axis

I am trying to use gnuplot for the first time.
I am completely new to gnuplot. Please forgive any basic mistakes.
I am trying to plot a stock chart.
My data looks like the following:
Date Open High Low Close
21/04/2017 31.81 32.09 31.67 31.95
20/04/2017 31.55 32.02 31.45 31.91
19/04/2017 31.3 31.71 30.99 31.57
18/04/2017 31.78 31.84 31.06 31.3
17/04/2017 31.3 31.97 31.21 31.8
13/04/2017 31.26 31.48 31.16 31.19
12/04/2017 31.13 31.38 30.98 31.24
11/04/2017 31.37 31.66 30.86 31.2
I am using the following settings to plot the lines. I got them from another website.
set xdata time
set timefmt "%d/%m/%Y"
set xrange ["21/04/2015":"21/04/2017"]
set format x "%d/%m/%Y"
plot [0:100] 'chart.dat' using 0:2:3:4:5 notitle with financebars
However, the x-axis just has 01/01/1970. See attached pic.
Any assistance would be greatly appreciated. Thanks.
The plot command plot [0:100] ... using 0:2:3:4:5 takes column 0 for x, column 0 corresponds to the line number instead of the time column.
This command should work:
plot 'chart.dat' using 1:2:3:4:5 notitle with financebars

How to properly reverse rrange in gnuplot?

I try to reverse the rrange of a polar gnuplot plot. According to the documentation (p. 173f) this can be achieved by swapping min and max values of the range definition or by using the reverse keyword in autoscale mode.
Neither one nor the other variant gives the results that I want.
The code:
set polar
set grid polar 30
set angle degrees
set size square
# case 1
set rrange [0:90]
# case 2
set rrange [90:0]
# case 3
set rrange [*:*] reverse
plot "-" u 1:2 w p pt 7 ps 3
0 30
30 60
60 45
e
The results:
The first picture shows a range of [0:90], the second one the range of [90:0] where no point is visible at all.
Plot three shows the output of the reverse setting.
As the documentation for rrange states
[...] no point with radius greater than < rmax > will be plotted.
the behavior of case 2 is totally comprehensible. On the other hand, case 3 should give the same result according to the following:
The reverse option reverses the direction of an autoscaled axis. For example, if the data values range from 10 to 100, it will autoscale to the equivalent of set xrange [100:10].
There seems to be some inconsistency between the documentation and the actual behavior of gnuplot.
This leads me to my question: How can I plot a diagram with the radius axis ranging from 90 in the middle to 0 at the outer circle?
EDIT
A small explanation of the application background:
What I want to visualize is a 2D top view of a sphere with equally spaced latitudes (Azimuthal equidistant projection). There, the center represents a pole with 90 degrees of latitude which decreases along the radius.
As a side comment, note also that the behaviour of the reverse keyword has been changed in Gnuplot 5 vs Gnuplot 4:
http://gnuplot.info/ReleaseNotes_5_0.html
"set xrange [0:1] reverse" does not work any more, you have to write instead "set xrange [1:0]".

How do I use gnuplot to plot a simple 2d vector arrow?

This is my first time trying to use gnuplot, and I can't find any instructions on how to accomplish this. The closest I found was this:
http://gnuplot.sourceforge.net/docs_4.2/node259.html
plot 'file.dat' using 1:2:3:4 with vectors head filled lt 2
but I can't find any explanation about "file.dat".
So can somebody give a simple example of how to draw a simple 2d vector arrow? Thanks.
gnuplot has a very good help/documentation build in. Just type help plot or help vector to learn more on how to plot vectors in gnuplot.
The 2D vectors style draws a vector from (x,y) to (x+xdelta,y+ydelta).
A small arrowhead is drawn at the end of each vector.
4 columns: x y xdelta ydelta
This means, your input file should have 4 columns, where the first two columns define the starting (x,y)-position of the vector/arrow and the last two its (x,y) direction:
# file.dat
0 0 .5 .5
0 1 -.5 .5
1 1 1 0
Now typing the following command
plot "file.dat" using 1:2:3:4 with vectors filled head lw 3
gives the following output:
Drawing vectors with the set arrow command
Consider using the set arrow command, if you only need to draw a few vectors/arrows (e.g. to highlight some points in the plot).
set arrow 1 from pi/2,1 to pi/2,0
set arrow 2 from pi*3/2,-1 to pi*3/2,0
plot[0:2*pi] sin(x)
You can create 'file.dat' in a spreadsheet save it as text and put it in the path of gnuplot by using the cd command to point gnuplot to its location. If that does not agree with you, look at the examples using '+' and '++' and '-' in the gnuplot manual. These are a "virtual data file." Note that the first two are for one and two column data points i.e. (x) or (x,y). You will have to use $1 and $2 as variables for calculating dx and dy. It is obligatory to set the xrange and yrange variables and the isosamples for density for this to work.
Something like....
set isosamples 30
set samples 30
set xrange [-10:10]
set yrange [-10:10]
plot '++' using 1:2:(0.1*sin($1)):(0.1*cos($2)) with vectors

GNU plot on non uniform data in x axis with fix interval

9 1782.091513,
24 4731.999530,
36 6377.046661,
80 9377.983901,
108 9158.024005,
210 4314.926970,
540 56799.564,
2000 67908.2343,
7000 45345.657,
12000 34234.3624,
Plotting this giving me a graph on which i am not able to see the small values. I want to fix the interval b/w each value of x axis. So that graph will be visible on full table.
You can set your axes to be logarithmic:
set logscale x
set logscale y
Logscale is probably what you actually want here as pointed out by choroba. A second (less standard) way to plot this is to use the values in the first column as the xticlabels.
plot 'yourdatafile' u 2:xticlabels(1)
This will result in a plot where the values are equally spaced on the x-axis, labelled with the corresponding x positions from the datafile.

gnuplot: smooth line in polar coordinates

I tried to plot some data in polar coordinates with gnuplot and then draw a smooth line.
data.dat:0 10
20 15
40 40
60 80
80 140
100 140
120 80
140 40
160 15
180 10
gnuplot:
set polar
set angle degrees
set grid
set grid polar
plot "data.dat" smooth csplines
I expected gnuplot to draw ovoid curve between points, but it drew strange line from left to right ignoring polar coordinates. Do you think there is any solution?
csplines are cubic so that's the best you can get with them. Try
plot 'data.dat' smooth bezier
but even then, you can't achieve much with such a small data set.
There is another trick you can try but it improves things only a little: you first output a table of the data generated by smooth bezier normal plot and then plot them polar:
# save smooth bezier data
set table
set output 'b_data.dat'
plot 'data.dat' smooth bezier
# plot
unset table
set term x11
set polar
set angle degrees
set grid
set grid polar
plot "b_data.dat" w lines

Resources