I have the following data:
N Computed Value of pi
y, x
1, 8.0
10, 3.6
100, 3.36
1000, 3.212
10000, 3.152
100000, 3.14316
1000000, 3.14266
10000000, 3.1420448
100000000, 3.14190876
1000000000, 3.141573084
And I am trying format y axis in terms of 10^x
I used the following code:
set terminal pngcairo size 1280,800 enhanced font 'Helvetica,24'
set output "fig.png"
# Title, axis label, range and ticks
set title "Simulations"
set xlabel "Number of Iterations(n)"
set ylabel "Computed values"
# Legend location and grid
set key top left
set grid
set ytics out nomirror
set xtics out nomirror
set format y "10^{%L}"
# Plot the data
plot data.dat" using 2:1 title "" with linesp lw 2 pt 7 ps 1.5
But i am getting the following output:
Please help
Thanks
I had to guess what you really want because there were some inconsistencies. Here is what I believe brings you where you want, changes commented in the source file.
# Title, axis label, range and ticks
set title "Simulations"
set xlabel "Number of Iterations(n)"
set ylabel "Computed values"
# Legend location and grid
set datafile separator comma # gnuplot looks for spaces
# you must tell it about the comma
unset key # same as title "" as you have in your plot command
set grid
set ytics out nomirror
set xtics out nomirror
set logscale x # I guess that's what you want and how it should be
set format x "10^{%L}" # yr x axis is labeled iterations, so I guess
# that's what you want
# Plot the data
plot [][2:10] "data.dat" using 1:2 with linesp lw 2 pt 7 ps 1.5
# swapped 2:1 so that the iterations are on the x axis
# introduced a range for y so that it is better to see
# 'title ""' removed, see 'unset key'
This gives you
May not be exactly what you want but should move you to the next level I hope.
Related
I am trying to graph roughly 15k different data points. I have tried all of the different variations that I can think of to reduce the number of xtics, but I can't seem to change the frequency that they are drawn.
Here's my gnuplot file:
reset
# need to call with two variables -e "filename='...'" -e "machine='...'"
set title machine." Activity ".filename
set datafile separator ","
set autoscale x
set autoscale y
set autoscale y2
set yrange [0:*]
set y2range [0:*]
set y2tics
set style data lines
set ylabel "% CPU"
set xlabel "Time"
set y2label "Memory (MB)"
set bmargin 7 # room for the xtic label
set term pngcairo size 960,720
set output filename.".png"
# I've also tried autofreq and explicit labels
set xtics axis out rotate 90 scale 0.5 (20101939, 1000000, 25102219)
plot filename \
using 2:xtic(1) title "CPU" with points pt 1 axes x1y1, \
"" using ($3 / 1024 / 1024):xtic(1) title "Memory" with points pt 1 axes x1y2
The format of my data is:
datetime(ddHHMMss), %cpu, mem-in-bytes, pid, process-alias, process-name
My data looks like the following (roughly sampled every 30 seconds for 15k records):
20101939,0,137932800,6172,process-alias,process-name
20102009,0.15623667978147077,139509760,6172,process-alias,process-name
20102039,0.15623669540380838,139866112,6172,process-alias,process-name
20102109,0.41663098777764329,141488128,6172,process-alias,process-name
20102139,0.052078915131769939,141455360,6172,process-alias,process-name
Despite my xtics command with explicit start, interval, and end, my graph always ends up with the xtic labels being overlapped. Here's what it looks like:
To filter the tic labels, replace xtic(1) with a criterion for printing a non-blank label. For example, this will print every 25th label.
plot filename \
using 2:xtic( int($0)%25 ? "" : strcol(1) ) title "CPU" with points pt 1
int($0) is the line number; strcol(1) is the content of column 1 read as a string
I have a data file which keeps all the x, y coordinates and radius values for drawing circles. Each circle stand for a region. Up to now I drew the circles. But I want to assign specific legend to each line in the data file. Because after drawing regions, I want to put some points on this regions depend on the region number. However I couldn't figure out how to do it. Is there anyone who know how to assign a specific legend to the circles depend on its line number in the data file. The data file looks like
X Y R Legend
5 6 0.1 1
....
and so on. I want to use the last column as title to assign to the circles. Is there any way to do that?
It depends how exactly you want to show the corresponding "title". Let's assume that the data file circles.dat contains following data:
5 6.0 0.1 1
5 5.5 0.1 2
4 5.0 0.2 3
One option would be to plot the circles and use the fourth column as labels which are placed at the centers of the individual circles. This can be directly achieved with the with labels plotting style as:
set terminal pngcairo
set output 'fig1.png'
fName = 'circles.dat'
unset key
set xr [3:6]
set yr [4:7]
set size square
set tics out nomirror
set xtics 3,1,6
set mxtics 2
set ytics 4,1,7
set mytics 2
plot \
fName u 1:2:3 w circles lc rgb 'red' lw 2, \
'' u 1:2:4 w labels tc rgb 'blue'
This produces:
Alternatively, one might want to put those labels into the legend of the graph. Perhaps there is a more elegant solution, nevertheless one way is to
plot each line of the data file separately and extract the fourth column (to be used as key title) manually:
set terminal pngcairo
set output 'fig2.png'
fName = 'circles.dat'
unset key
set xr [3:6]
set yr [4:7]
set size square
set tics out nomirror
set xtics 3,1,6
set mxtics 2
set ytics 4,1,7
set mytics 2
set key top right reverse
stat fName nooutput
plot \
for [i=0:STATS_records-1] fName u 1:2:3 every ::i::i w circles t system(sprintf("awk 'NR==%d{print $4}' '%s'", i+1, fName))
This gives:
I'm trying make simple histogram with this file '.dat'
Moment "Energy consumed (MWh)"
"Apr-16" 2011.4
"May-16" 1869.6
"Jun-16" 1899.0
"Jul-16" 1659.0
"Aug-16" 1740.6
"Sep-16" 1670.0
For this purpose I have written the following script
#!/usr/bin/gnuplot
set term postscript
set terminal pngcairo nocrop enhanced size 700,700 font "arial,18"
set termoption dash
set output out
set boxwidth 0.5 absolute
set border 0
set style fill solid 1.00 border lt -1
set key off
set style histogram clustered gap 1 title textcolor lt -1
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror autojustify
set xtics norangelimit
set xtics ()
unset ytics
set title titulo
set yrange [0.0000 : limite] noreverse nowriteback
show style line
set style line 1 lt 1 lc rgb color lw 1
## Last datafile plotted: "immigration.dat"
plot fuente using (column(0)):2:xtic(1) title titulo ls 1 with boxes, '' using 0:2:2 with labels
In this case out is the output filename, titulo is the label that appears on the top of the image output, limite is the value that I use as biggest value on y-axi, and fuente is the source filename.
The result is this
I am trying display the values over the bar with some offset because I need the values over the bars and not inside the bars. I would need separate I am trying with code like:
plot fuente using (column(0)):2:xtic(1) title titulo ls 1 with boxes, '' using 0:($2 + 0.5):2 with labels
because I have seen many sites where they get it doing $2 + 0.5 but this it doesn't work for me.
What should I do? Please help me I am completly lost. Thanks in advance.
Use the offset parameter for the with labels plotting styles. With this you can add a vertical offset which you specify e.g. in character or graph units:
plot fuente using 0:2:xtic(1) with boxes, '' using 0:2:2 with labels offset 0, char 1
Sidenote: Adding the constant value of 0.5 to the y-value (like $2 + 0.5) doesn't work for you, because the 0.5 is in units of the y-axis, and very small compared to your yrange.
I have the following graph:
first data set display searches.
second data set display clicks.
y1 shows searches scale, y2 shows click scale.
on the x1 I have time values displayed.
I wish to display clicks values (each hour) on x2 (the upper axis).
When I add the command set x2tics it displays the searches data and not the clicks like I wished.
How do I change it so it will display the clicks unit?
Gnuplot script:
set xlabel "Time"
set ylabel "Times"
set y2range [0:55000]
set y2tics 0, 1000
set ytics nomirror
set datafile separator "|"
set title "History of searches"
set xdata time # The x axis data is time
set timefmt "%Y-%m-%d %H:%M" # The dates in the file look like 10-Jun-04
set format x "%d/%m\n%H:%M"
set grid
set terminal png size 1024,768 # gnuplot recommends setting terminal before output
set output "outputFILE.png" # The output filename; to be set after setting
# terminal
load "labelsFILE"
plot 'goodFILE' using 1:3 lt 2 with lines t 'Success' , 'clicksFILE' using 1:2 lt 5 with lines t 'Clicks right Y' axis x1y2
replot
Graph:
graph http://img42.imageshack.us/img42/1269/wu0b.png
Ok, so to get started, here is how you can set a label with the number of clicks as follows (using you data file names):
plot 'goodFILE' using 1:3 lt 2 with lines t 'Success',\
'clicksFILE' using 1:2 lt 5 with lines t 'Clicks right Y' axis x1y2,\
'' using 1:2:(sprintf("%dk", int($2/1000.0))) with labels axis x1y2 offset 0,1 t ''
Just add this as plotting command, and it should work just fine.
To illustrate, how the labels might look like, here is an example with some dummy data:
set terminal pngcairo
set output 'blubb.png'
set xlabel "Time"
set ylabel "Times"
set y2label "Clicks per hour"
set y2range [0:10000]
set yrange [0:1]
set ytics nomirror
set y2tics
set key left
set samples 11
set xrange[0:10000]
plot '+' using 1:1:(sprintf("%dk", int($1/1000.0))) every ::1::9 with labels axis x1y2 offset 0,1 t '',\
'' using 1:1 with linespoints axis x1y2 pt 7 t 'Clicks per hour'
Which gives you:
I have created a plot made up of four subplots; each subplot is a bar chart. Above the smaller bars I want to print how many units on the y-scale the bar represents. To do this I use 'set label', which works fine if I create individual files for the subplots, but not if I use multiplot. In this case the labels are successively printed on top of each other (i.e. those of the first subfigure also appear in the second, etc.).
Here is a truncated version of my gnuplot script:
set terminal postscript eps size 26cm,16cm font "Helvetica,18"
set out 'all_Figures.eps'
set multiplot
set multiplot layout 2,2
set bars fullwidth
set data style boxes
set boxwidth 0.5
set style fill solid 1.0 border -1
set border 3 front linetype -1 linewidth 1.000
set xtics border in scale 0,0.5 nomirror norotate offset character 0, 0, 0
set ytics border in scale -1,0 nomirror norotate offset character 0, 0, 0
set nogrid
set datafile separator ","
# ** First Plot **
set label "36" at first 2, 130 center
set label "86" at first 3, 160 center
set size .4,.3
plot 'allPDB_perc.csv' using 2:xticlabels(1) notitle
# ** Second Plot **
set size .4,.3
set label "10" at first 3, 236 center
set label "3" at first 4, 236 center
plot 'allPDB_num_dom.csv' using 2:xticlabels(1) notitle
unset multiplot
Is someone able to tell me how to clear the previous subfigure's data labels prior to generation of the current labels? Thanks a lot in advance!
Oh dear >_< I simply had to unset the labels after plotting, like so:
# ** Plot 1 **
set label ...
plot 'datafile.dat'
unset label
# ** Plot 2 **
set label ...