How to create proportion x width graph which contains seconds - gnuplot

i have data file which contains data every seconds .
i want to present x width graph which each second data could be seen clearly .
what does my script right now is creating rectangle graph when all the small values are hardly seen , and the high values are sean clearly .
so now with the script im getting this image :
as you see only the high spikes are seen
but what i realy want is proportion graph that will look like this :
this is the script im using :
set title filename.' CPU usage'
set xdata time
set timefmt '%H:%M:%S'
set format x '%H:%M:%S'
set xlabel 'time'
set ylabel 'CPU Usage'
set style data lines
plot filename using 1:3 title '0.6'
pause -1

You can specify the size of the plot when specifying the terminal. For example,
set term pngcairo size 800, 200
creates an image that is 800 pixels wide and 200 pixels high. If you want to change the aspect ratio of the plot without changing the dimension of the entire image, try something like
set size ratio 0.2
Neither of those would make the small values more visible, though; for that set log y would probably more appropriate as pointed out in the comments above.

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}$.

Multiplot for creating zoom charts

I want to use multiplot in a way that there is one big chart and one small chart. The small chart in the magnified version of the big chart. There is a good example here but my scales are different from the example and I found that setting the correct size and origin values very hard!
I want to draw something like this
The data file contains simple integer numbers like
10000
20300
12340
10
40000
...
The xrange is [0:4000000] and yrange is [0:4000000] I want to zoom X from 100000 to 300000
Hard thing for me is how to put the small chart in the right of the big chart? top or bottom doesn't matter.
UPDATE:
When I set the origin of the second chart to set origin 0.8,0.8, I see that the second chart is on top right, but the canvas doesn't scale correctly.
set origin 0.6, 0.6
set origin 0.8, 0.8
You can either use set size in combination with set origin to scale and shift your plots. Or you could use set lmargin etc. to control the size of the plots with respect to the image size (i.e. the canvas size). (Of course you could also combine those parameters)
Here is a sample script which uses only the size and the origin. The values given to set size are in screen coordinates. So set size 1,1 is the default and the plot area plus all margins corresponds to the canvas size. With set size 0.5,1 you scale the plot's to 50% of the canvas width. Also set origin uses this kind of coordinates.
Since you want to place both plots side-by-side, You can use an image size with a large aspect ratio (set terminal pdfcairo size 4in,2in).
set term pdfcairo size 4,2
set output 'foobar.pdf'
set multiplot
unset tics
set border 3
set origin 0,0
set size 0.8,1
plot x**2
set origin 0.75,0.2
set size 0.25,0.3
plot x
unset multiplot
You can find the answer in this post or in this another plot. The trick is to play with set size and set origin

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

Column and row name formatting in gnuplot

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.

Resources