Manual scaling of axis (poltting with boxes) in gnuplot - linux

I'm trying to plot a really long list, which represents frequency of some data. The x axis goes from 1 to 1881, and the y goes from 1 to 1978. I tried plotting with the following configurations:
set log y 5
set log x 32
set xtics 2
set ytics 5
plot "freq.dat" w boxes
But i get the following result:
Which is clearly not good because there are these intersections of the boxes. I want to have some kind of scale that have a lot more space between 10 and 150 than the outside of this area. How can i do that? I've tried every combination of logs and xtics and couldn't make it look good. The y axis seems good to me, the only problem is the spacing of x-axis.
Also, i want to know how to do this in gnuplot specifically (if possible).
Thanks.

It seems to me that your script overrides somewhere the default boxwidth. The default behavior is:
By default, adjacent boxes are extended in width until they touch
each other. A different default width may be specified using the set boxwidth command. Relative widths are interpreted as being a
fraction of this default width.
So for example this:
set terminal pngcairo enhanced
set output 'fig.png'
set log x 2
set log y 5
set yr [0.2:3125]
set xr [1:512]
set boxwidth 1 relative
set xtics 1,2,512 out nomirror
set ytics 1,5,3125 out nomirror
unset key
#set style fill pattern 6
plot 'freq.dat' w boxes lc rgb 'royalblue' lw 1.1
then yields:

Related

Gnuplot bar diagram different color with value on top of bar

My data set is simple:
CPU 5.7
Memory 3.7
I want to plot a simple bar diagram with different colors for each value and the corresponding values should be shown on top of each bar. I also want to plot the ylabel and the legend. It should almost look like the the following diagram:
Is this possible in gnuplot? There seems to be hardly any document for doing this in gnuplot. Plotting bars with historgram seems easy but styling with different colors, the value on top and the legends part is turning out to be a bit tricky for me. Can someone please help me?
Thanks in advance.
Maybe the following comes quite close:
This is the gnuplot script:
set terminal pngcairo
set output "data.png"
set title "CPU and Memory"
set nokey
set boxwidth 0.8
set style fill solid
set xrange [-1:2]
set xtics nomirror
set yrange [0:7]
set grid y
set ylabel "Time"
plot "data.dat" using 0:2:3:xtic(1) with boxes lc rgb var ,\
"data.dat" using 0:($2+0.5):2 with labels
The pseudo column 0, which is the current line number, is used as x value.
I have added a third column to your data which contains the color as rgb value.
The value on top of the bars is printed by the with labels command. It requires a using with three values: x, y, string. The part ($2+0.5) takes the y-value from the second column and adds 0.5.
The identifiers "CPU" and "Memory" are printed below the corresponding bar instead of using a separate key.
And this is the modified datafile:
CPU 5.7 0x4472c4
Memory 3.7 0xed7d31

How to label the x axis with exact values

I have drawn the bar chart above using the following code:
set terminal jpeg medium
set output "bar.jpeg" # shall be the name of the chart
set xlabel "full configuration time in msec"
set ylabel "Task rejection rate (%)"
set boxwidth 0.5
set style fill solid
#set autoscale
plot "data.data" using 1:2 with boxes
My file data.data looks like this:
2 9
5 24
7 46
10 66
15 100
I want the exact values 2,5,7,10,15 to appear along the x axis with the corresponding value along the y axis and to use a color other than red. What changes do I have to make to my code? I also need to remove that "data.data" using 1:2 from the top right corner...
Any suggestions?
To remove the key, use unset key.
The markers at the bottom of the graph are called xtics. If you want them to appear every 1, rather than every 2, then you could use set xtics 1. Depending on exactly what you wanted to do, you can customise the xtics even more. In gnuplot if you do help xtics there's plenty of information on that.
To change the colour of your boxes, you can use the lc (line colour) property. I have used a hexadecimal #RRGGBB format but you can also use names of colours like green, blue, etc. Look at help linecolor for more info on that.
Incorporating all of those changes into your script:
set xlabel "full configuration time in msec"
set ylabel "Task rejection rate (%)"
set boxwidth 0.5
set style fill solid
unset key
set xtics 1
plot "data.data" using 1:2 with boxes lc rgb '#52bb23'
By the way, I used the pngcairo terminal rather than the jpeg one as I think it looks better. Try set term to see what terminals are available to you.
In addition to #TomFenech's answer: If you want to show only the x-values specified in the data file, you can use the xtic function. Note, that in this case the defined x-format has no effect and the value is taken 'as-is':
set xlabel "Full configuration time in msec"
set ylabel "Task rejection rate (%)"
set boxwidth 0.5
set style fill solid
set xtics out nomirror
plot "data.data" using 1:2:xtic(1) with boxes notitle

adding space between x axis and xtics in gnuplot histogram

Currently I created graphs with small size. The spacing really important at this case. I want to add more vertical space between my xticlabels and x axis.
I have tried to set the x bar with
set xtics offset 0,graph 0.05
my gnuplot output:
The data and gnuplot script still same with my previous question here.
You can do the following:
First add a little bit of bmargin by
set bmargin 3
Since you need to add vertical space between your xticlabels and x-axis, you need to adjust the Y-offset, which can be done by the following
set xtics offset 0,-1,0
You can play around with the values to suite your need.

Limit the number of ytics and keep mytics when using logscale

This question is somewhat similar to Limit the number of ytics while using automatic ytics placement but doesn't get answered in that thread.
I used the following code to generate my graph gnuplot:
set yrange[.125:512]
set logscale y 2
set ytics 2
set mytics 16
set grid mytics ytics
set key off
plot '20131019_square.log' using 2:xticlabels(1) with linespoints linestyle 2
resulting in graph_1. (post it in comment because this is my first post <10 rep)
I find the ytics somewhat dense, so I change set ytics 2 to set ytics 8
resulting in graph_2
In this second graph the spacing is fine, but mytics behaves incorrect (I need logspacing) and the tics numbering I really want to use is (.03125,0.125,.5,2,8,32,128,512) what I can obtain using set ytics to (.03125,0.125,.5,2,8,32,128,512)
resulting in graph_3
Everything is correct in the last one, but I'll lose my minor ytics. (This is normal behavior for gnuplot, but I would like to get the tics of this graph_3.)
Any ideas on how to get graph_3 with mytics?
You can have minor tics only for automatically generated major tics like you get with:
set ytics 0.03125,4
With logscale set, the increment (here 4) is treated as a multiplier for the starting value (here 0.03125).
A full, minimal script would then be
set logscale y 2
set yrange[0.03125:512]
set ytics 0.03125,4
set mytics
set xrange[0:10]
plot x

Creating a microphone polar pattern plot in gnuplot

I would like to create a microphone polar pattern plot that has a scale of -20 (in the center) out to +5 in steps of 5. I have found similar code but nothing that allows for the scales to be negative.
Multiple patterns will then need to added to the plot covering a few different frequencies, I have degree values (0-360) and corresponding dB values (-25 - +5).
This is what the plot should look like (though with slightly different scales):
The closest gnuplot I have found to this is here: How to get a radial(polar) plot using gnu plot?
Perhaps this could be modified to suit my needs?
I would also like 0 degrees to be found at the top of the plot rather than on the right.
I am new to using gnuplot so I am not particularly familiar with its code, therefore it has been difficult for me to modify the code with any great success (so far anyway).
So you want to plot a polar function, e.g. r(theta) = 1 + sin(theta).
Plotting the function is quite easy, just do
set polar
plot 1+sin(t)
A simple polar grid can be plotted with
set grid polar
but that has the raxis and the rtics on a different position than where you wanted. It is not problem to specify custom labels. But angular labels aren't supported, so you need to set them manually. And the border and the other axes and tics must be unset.
To get the very same image as you showed, use the following script:
set terminal pngcairo size 700,600 font ',10'
set output 'cardioid.png'
set angle degree
set polar
set size ratio 1
set tmargin 3
set bmargin 3
set style line 11 lc rgb 'gray80' lt -1
set grid polar ls 11
unset border
unset xtics
unset ytics
r=1
set rrange [0:r]
set rtics 0.166 format '' scale 0
set label '0°' center at first 0, first r*1.05
set label '180°' center at first 0, first -r*1.05
set label '90°' right at first -r*1.05, 0
set label '270°' left at first r*1.05, 0
set for [i=1:5] label at first r*0.02, first r*((i/6.0) + 0.03) sprintf("%d dB", -30+(i*5))
unset raxis
plot 0.5*(1+sin(t)) linewidth 2 t ''
With the result:
That includes some offsets for the labels, which depend on the terminal, the canvas size and the font size. So you may need to adapt them.
I had to increase the top and bottom margins a bit (here by 3 character heights) in order to have enough space for the angular labels. They aren't included in the automatic margin calculations, because the don't belong to an axis.
Unfortunately Christoph's answer is wrong.
You can see that if you check where the plot curve crosses the 5db circle.
What should be plotted is
20*log10(A+B*cos(t))
where A+B = 1 and A - B determines the (nominal) directivity pattern.
The first diagram seems to be for A=B=0.5 which makes for a cardioid pattern.

Resources