Column and row name formatting in gnuplot - linux

I prepared a code to graph my script's csv output. They are column separated values.
I used code below to do that:
#!/usr/bin/gnuplot -persist
set datafile separator ":"
set terminal png nocrop font small size 640,480
set output 'mychart.png'
set style data histograms
set title "some graph title"
set xlabel "some x asis name"
set ylabel "some ya axis name"
plot "/home/username/Desktop/test.csv" using 2:xticlabels(1) notitle
This will draw the graph successfully. However I have two problems here. One in x axis, there are big numerical values such as 50000000, 6000000 so graph shows them in exponential format such as 5E+9 6E+8. But I would like to see full number. Second, in y axis, there are almost 20 alphanumeric values (some network parameter names) and each of them with at least 25-30 character. So they won't show up properly. Is there a way to write them with a smaller font and an angle?
Thanks

To change the format of the numbers shown on the y-axis, use e.g.
set format y '%.0f'
The labels of the xtics can be rotated (rotate by 45), aligned differently (right) and they can use a different font size (font), e.g.
set xtics right rotate by 45 font ',8'
See also rotating and justifying tics in gnuplot.
You may need to adjust the bottom border to have enough space for the labels, e.g. with
set bmargin 6
BTW: You should use the pngcairo terminal (available since version 4.4), which produced much nicer graphs than the png terminal.

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

Editing y axis range in Gnuplot

I have a plot with exponential y axis range. I'm using multiplot command by inserting two images in one row. So due to this wide y axis range I'm loosing some space which I could use it to show my plots in a better way. I want basically something like this
How could i do this? I think for doing this I have do some math operations in the y axis range. Also what is the most convenient command to insert ( xE-10) at top left of the plot.
reset
set terminal epslatex size 16cm,18cm color colortext
set output new.tex
set key off
set format $%g$
set title "sinx"
set ylabel "[kNm]"
plot 1000000*sin(x)
This is not my exact code but it looks similar to this. The plot I have presented is a part of the multiplot code and I use 7 input files with time series data of 300 seconds at a time step of 0.02. The point I want to edit the y axis range (use some mathtematical expressions) and also include the term ( xE-10 ) on the top of the plot something like this
You can manually add the exponent with a set label .... For instance, the following function takes large values within the given interval:
plot[0:50] exp(x)
We can place the "x 10^21" manually in the desired place after dividing the plotted quantity by it:
set label 1 "{/Symbol \264} 10^{21}" at graph 0,1.025 left
plot[0:50] exp(x)/1e21
You have to be careful with the exact placement of the exponent since it might lie outside the plotting area, in which case you should lower the top margin with set tmargin .... Also, to use the "times" symbol, you need to pass the enhanced option to your terminal. With the epslatex terminal, you can use latex syntax: $\times 10^{21}$.

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.

Gnuplot : How to specify the graph width in pixels?

I would like to plot the output of a dataset so that there is one pixel per sample, on the X axis. e.g. if I have a dataset of 500 samples then I would like to ensure that the X axis is 500 pixels wide. Does anyone know how to do this with Gnuplot ?
Thanks very much,
John
This request makes sense only for bitmap terminals. In order to get a plotting area with a fixed size, you must both set a respective terminal size and fixed margins. The following script gives a plotting area of 500px width. This includes the 1px thick border lines, which are also part of the plotting area, what you can see, with set border back:
set terminal pngcairo size 600,500
set lmargin at screen 80.0/600
set rmargin at screen 579.0/600
set border back
set output 'output.png'
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