increasing yRange from negetive to positive in gnuplot - gnuplot

I want my yrange to be between -100 and 0, and here is my plot in gnuplot
I want the y axis to be from -100 increasing up to 0!
what should I do?!
BTW:
My plot is histogram!
when I set it to [-100:0] my plot is upside down, the bars are from up to down!!
set style data histogram
set yrange [-100:0]
set style fill solid 0.3
set bars front
plot 'mean.rssi' using 2:xticlabels(1) title columnheader
above is my code, histogram is plotted from 0 to -100, but I want to be from -100 to 0!
The file mean.rssi contains two columns, for example
Dlink -93

That isn't directly supported, histograms always have their base line at 0, positive values give boxes oriented upwards, negative values downwards.
Since your range is known, you should convert the range [-100:0] to the range [0:100] and relabel the y-axis:
set style data histogram
set yrange [0:100]
set ytics ('-100' 0)
set for [i=-100:0:20] ytics add (sprintf('%d', i) i + 100)
plot 'mean.rssi' using ($2 + 100):xticlabels(1)
Other solutions would use the boxes plotting style. If you could use this depends on whether you need the stacking features of the histogram style.

You can specify ranges with square brackes. For example, to specify both X and Y ranges you could do:
plot [-20:20][-50:50] sin(x)
which would set the X-range to [-20,20] and the Y-range to [-50,50].
To only set the Y-range, you can set the X-range to the empty brackets [], e.g.
plot [][-50:50] sin(x)
To only set the X-range you can do something similar, or just omit the Y-range completely:
plot [-20:20] sin(x)

Related

Can I plot 1D heatmap with gnuplot?

I'm trying to plot a 1D heatmap using two columns of data (x value and y value) in gnuplot. The linegraph plotted using my data is like this:
Linegraph:
However after some trying I can only achieve this:
What I've got:
And what I want to get is something like this. (Only example)
What I want:
The gnuplot script that I use is as follows:
set view map
set size ratio 0.2
unset ytics
unset key
splot 'test.dat' u 1:(1):2 palette
Could anyone help please?
So you want to use the y axis as a fake dimension in order to increase the width of your second line plot?
Sure, this is e.g. possible with boxxyerror with explicit ymin and ymax errors that fill the yrange.
set xr [-10:10]
set yr [0:1]
xspacing = 0.1
plot '+' u 1:(0.5):($1-xspacing):($1+xspacing):(0):(1):(sin($1)) w boxxyerror lc palette
In your case replace the sin(x) with the respective column of your data. With the special file '+' the x-width has no effect, but in your case you might need to play around with a proper xspacing in order to avoid white gaps between the points.
I would do it like this:
unset key
set xrange noextend
set offset 0,0,graph .05,graph .05
set palette cubehelix negative
plot 'foo.dat' using 0:3 with lines lc "black", \
'foo.dat' using 0:(70):3 with lines lc palette lw 10

How to plot multiple y-axes?

I saw this graph and only for the curiosity sake was wondering whether it was possible to plot figure with multiple y-axis as in the figure
Many thanks!
As andyras wrote, you can use the second y-axis if you only have two datasets. In this case, you also need to to
set ytics nomirror # remove the tickmarks of the left ayis on the right side
set y2tics # make the right y-axis 'visible'
If you want to plot more than one dataset, I would suggest to use multiplot. You can overlay several independent plots and put a unique offset to the y-axis for each of them.
However, you need to take care that the number of y-tics and y-tick positions is the same.
Plot:
(I did not care about the key here, this still needs adjustment)
Code:
set multiplot
set xrange[0:10]
# We need place to the left, so make the left margin 30% of screen
set lmargin screen 0.3
##### first plot
set ytics 0.4
set yrange[-1.2:1.2]
set ylabel "Voltage" textcolor rgb "red"
plot sin(x)
##### Second plot
set ytics 1
set yrange[-3:3]
set ytics offset -8, 0
set ylabel "Current" offset -8, 0 textcolor rgb "green"
plot 3*cos(x) linecolor 2
##### Third plot
set ytics 0.5
set yrange[-1.5:1.5]
set ytics offset -16, 0
set ylabel "Power" offset -16, 0 textcolor rgb "blue"
plot 3*sin(x)*cos(x) linecolor 3
unset multiplot
Yes, you can have two y axes for free, e.g.
plot x, x**2 axes x1y2
The axes specification lets you put things on x1y1, x2y1, etc. If you want more than two things plotted on the same y axes you have to normalize things yourself:
plot 'data1.dat' using 1:($2/MAX_1), \
'data2.dat' using 1:($2/MAX_2), \
'data3.dat' using 1:($s/MAX_3)
The variables MAX_X can be precalculated by using the stats command in gnuplot 4.6+, or you can put them in manually.

Gnuplot histogram x logscale

I'm using gnuplot in a bash script to draw several things.
For this special graphic, I need to print the amount of matrices (y axis) with the matrix size as the x-axis.
As the distribution can be pretty sparsed, I want to use a logscale for x and y. It works great with y, but gnuplot tells me I can't have a logscale for the x-axis when I'm using histogram style.
Any ideas to debug this? or on how to present the results using a similar way?
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set logscale xy
plot '$res/histo-$ld-$lr-$e-$r' using 2:xtic(1) title 'Run'
The error is :
line 0: Log scale on X is incompatible with histogram plots
Thanks in advance.
Edit : btw, I was using gnuplot 4.4 patchlevel 4 and just updated to the newest version (i.e. 4.6 patchlevel 5)
Gnuplot histograms work a bit differently from what you might think. The x-axis isn't numeric. In your case the value in the first row, second column is placed at an x-value of 0 with the y-value taken from the second column and a manual label taken from the first column, first row. The values of the second row are placed at x=1 etc.
You can try using the boxes plotting style, which is used with a 'conventional' x-axis and supports a logscale in x:
set logscale xy
set offset 0,0,1,1
set boxwidth 0.9 relative
set style fill solid noborder
plot 'data.dat' with boxes
With the data file data.dat
1 1000
2 300
5 150
20 10
135 3
this gives the result (with 4.6.5):
In order to have a fixed boxwidth and a varying box distance, you can use a third column to specify a box width as percentage of the x-value:
set logscale xy
set offset 0,0,1,1
set style fill solid noborder
plot 'data.dat' using 1:2:($1*0.5) with boxes
Putting the actual values on the x-axis works as follows:
set logscale xy
set offset 0,0,1,1
set style fill solid noborder
plot 'data.dat' using 1:2:($1*0.5):xtic(1) with boxes

Gnuplot - "zoom in" part of x-axis

I have a data row with lots of dots, plotted as markers. X-axis values range between 0 and 80 ms, and Y-values take discrete values of 1,2,..5. There are about 50000 points, so if I just plot them as usual, the Y-value changing dynamics is not clear, as you see for example a solid line forming at Y value 5, with a few dropouts at 3 and 4. I would like to modify my plot to zoom in the first millisecond - the half of the X-axis should be occupied by the range 0-1ms, and the rest 1-80ms. Any idea how to achieve this?
Use this:
set yrange [-1:1.3]
set xrange [0:12]
set x2range [40:150]
set xtics 0,1,5
set x2tics 100,10,150 mirror offset 0,-21.6
plot (x<5?sin(x):0/0) axis x1y1 tit "f(x)", (x>100?cos(x):0/0) axis x2y1 tit "g(x)"
Constant -21.6 is setting up xtics labels for second part but according to x2 (upper) axis... So you must fit this constant according to graph height and used terminal. Also you have to change range and tics settings to obtain continuous x axis.

How do I place tic marks along the top borders in a 3d plot?

I'm making some 3D surface plots in Gnuplot and it would be very useful to have tic marks along each border of my plot. In the attached sample plot, there are no tic marks along the top left or top right horizontal borders (borders 256 and 512). In order for vertical grid lines to be drawn on the back vertical planes, I need to have tic marks on these borders. How can I achieve this?
I have not found a way to solve this using the grid and border. However, there is a relatively simple workaround, which is useful only if you do not change your ranges every time you plot your data.
Basically you plot a constant surfaces on the back walls matching the line type and number and position of the grid lines in the x-y plane.
First, set up the ranges. I labeled them, because we will need the numbers later.
xmin=0 ; xmax = 100
ymin=0.01 ; ymax=1000
zmin=0 ; zmax=990
set xrange [xmin:xmax]
set yrange [ymin:ymax]
set zrange [zmin:zmax]
Setting the z axis intersection with x-y plane (ticslevel) and I guessed a view angle to visually match your example. We want to set these before multiplot.
set ticslevel 0.0
set view 60,45,1
Now comes the fun. For this part you have to know the number of grid lines in your x-y plane (same as number of major tics on x and y axes). We will plot the back grid walls first, so they are behind your data/function at the end. Also, I switch off the grid and border for this part, but they should exactly overlap if you leave them in.
set multiplot
unset grid
set border 0
Even though the y-axis has logarithmic scale, the grid is separated linearly (equidistant grid lines). So at this point I want linear scale on y axis. (If you set logscale y before this point, comment it out.) I don't want linear labels on the y-axis, because they are different on logarithmic scale, so I set the format accordingly.
set format y ""
set isosamples 6,9 # - set this to number of tics on y-axis,z-axis
Here is the only manual setting that might change when you plot on a different range. You need to set the numbers of isosamples to the numbers of tics on y-axis,z-axis.
To control how many lines gnuplot is going to use for each surface, we need to set both the isosamples (done above) and the ranges of dummy variables u,v. Notice the line type 0, which is the grid line type.
I plot my first wall at x = xmin:
set parametric
set urange [ymax:ymin]
set vrange [zmax:zmin]
splot xmin,u,v w lines lt 0
Similarly, we do the other wall at y = ymax.
set urange [xmin:xmax]
set vrange [zmin:zmax]
splot u,ymax,v w lines lt 0
unset parametric
Now that I have the walls, I can plot what you already have in the picture. Setting borders, tics, re-enable the y-axis label we disabled before, set the log-scale on y axis (now is a good time) and reset isosamples to the default values.
set xtics mirror
set ytics mirror
set ztics mirror
set grid ytics xtics back
set logscale y
set format y " %g"
set isosamples 10,10
And plot your data/function as you are used to.
splot 'data.txt' w lines
unset multiplot
And we are done....
Possible necessary modification:
I guess your x and y axes will be different from mine, since the reverse is easily achievable by something like view 60,135,1. This also switches x and y though. Your surfaces will then change coordinates.
You can try setting tics there using x2tics and y2tics.
Here is the documentation of Xtics.

Resources