I am using 'gnuplot' to plot a line graph with point:
set style data linespoints
set xlabel "number"
set ylabel "Dollars"
set yrange [0:250]
how can I increase the width of my graph, so that as I have more 'x', i want my graph to more of a rectangle instead of a square?
And how can I increase the interval of my 'y-axis'? now, it just draw a mark for every 50 in my y axis?
To add to the discussion here, there's also set size ratio ...
so that you can set the aspect ratio of your plot.
Here's an excerpt from help set size
:
ratio
causesgnuplot
to try to create a graph with an aspect ratio of (the ratio of the y-axis length to the x-axis length) within the portion of the plot specified by<xscale>
and<yscale>
.The meaning of a negative value for is different. If =-1, gnuplot tries to set the scales so that the unit has the same length on both the x and y axes (suitable for geographical data, for instance). If =-2, the unit on y has twice the length of the unit on x, and so on.
For this to really work, you'll probably need to set the output driver to some reasonable size:
set term png size 800,400 #800 pixels by 400 pixels
or:
set term post size 8,4 #8 inches by 4 inches
This is all terminal dependent, so its worth it to look up the terminal's help to see what units it uses, etc.
It sounds like you want your output to dynamically adjust in size to the data being plotted. Here is a script that does that:
#!/usr/bin/env gnuplot
# don't make any output just yet
set terminal unknown
# plot the data file to get information on ranges
plot 'data.dat' title 'My Moneys'
# span of data in x and y
xspan = GPVAL_DATA_X_MAX - GPVAL_DATA_X_MIN
yspan = GPVAL_DATA_Y_MAX - GPVAL_DATA_Y_MIN
# define the values in x and y you want to be one 'equivalent:'
# that is, xequiv units in x and yequiv units in y will make a square plot
xequiv = 100
yequiv = 250
# aspect ratio of plot
ar = yspan/xspan * xequiv/yequiv
# dimension of plot in x and y (pixels)
# for constant height make ydim constant
ydim = 200
xdim = 200/ar
# set the y tic interval
set ytics 100
# set the x and y ranges
set xrange [GPVAL_DATA_X_MIN:GPVAL_DATA_X_MAX]
set yrange [GPVAL_DATA_Y_MIN:GPVAL_DATA_Y_MAX]
# set the labels
set title 'Dollars in buckets'
set xlabel 'number'
set ylabel 'Dollars'
set terminal png size xdim,ydim
set output 'test.png'
set size ratio ar
set style data linespoints
replot
For these example data:
0 50
50 150
100 400
150 500
200 300
I get the following plot:
It is about square, as it should be (I defined 100 units in x to be equal to 250 units in y, and the data span the range [(0,200),(50,500)]). If I add another data point (400,300), the output file is wider, as expected:
To answer your other question, you can set the y tic increment thus:
set ytics <INCREMENT>
The script above gives an example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With