in gnuplot 5.0 patchlevel 1 on my old server I used:
set term pngcairo transparent truecolor size 190,40
set output "some.png"
unset bmargin
set bmargin 0
set lmargin 0
set rmargin 0
set tmargin 0
unset border
unset xtics
unset ytics
unset y2tics
unset key
unset title
unset colorbox
set timefmt '%Y-%m'
set xdata time
set style fill transparent solid 0.25 noborder
tt = "`date +%Y-%m-%d\ %H:%M`"
TIMEFMT = "%Y-%m-%d %H:%M"
now_secs = strptime(TIMEFMT,tt)
two_years_past = now_secs - 3600.0*24*365*2
eval(sprintf('set xrange ["%s":]',strftime(TIMEFMT,two_years_past)))
set autoscale yfix
plot "datafile" using 1:2 with filledcurves below x1 lw 1 lc rgb "#a7eeeeee" title ''
...it produced a graph with y range correctly auto-scaled.
But on my new server with gnuplot 5.0 patchlevel 3 installed it does not work anymore. It seems they screwed something in the code. The yrange is computed from all x timedata, not over the selected xrange only.
I have no idea how to correct the yrange in this case. It could be computed using the stats command, but the "xdata time" must be switched off before, but in that case I do not know, how to set the right xrange for the stats command.
Regards
Pavel
EDIT:
minimal datafile:
2014-01 2
2014-06 6
2015-01 4
2015-06 8
2016-01 6
2016-06 10
I can reproduce your y-range autoscale issue with gnuplot<=5.0.1 and all versions >5.0.1 to 5.4.0.
Although, gnuplot is not scaling to the full y-data-range as you assumed, but apparently filledcurves x1 seems to always (auto)scale to 0 unless there is y-data <0.
To me, this looks more like a bug than a feature. I don't see a reason why filledcurves should always autoscale to 0.
In contrary to this behaviour, the plotting style with boxes will still autoscale in y to the minimum as you want it.
So, as a workaround to keep your desired behaviour you need to add two lines:
stats $Data u 2 nooutput
set yrange[STATS_min:]
The x-range is already limited when executing the stats command, hence you will get the y-minimum in STATS_min which you can use to set the y-range.
By the way: I cleaned up your script a bit. Why making a platform-dependent system call for getting the current time, if you have the gnuplot function time()? Check help time.
Script: (works identical for all gnuplot versions >=5.0.0)
### adjust time range via current time with proper y autoscale
reset session
$Data <<EOD
2020-01 12
2020-06 6
2021-01 4
2021-06 8
2022-01 6
2022-06 10
EOD
t0 = time(0) # now, i.e. seconds from Jan, 1st 1970 00:00:00
TwoYearsInSec = 3600*24*365*2 # two years in seconds
myTimeFmt = "%Y-%m"
set format x "%Y\n%m" timedate
set style fill transparent solid 0.25 noborder
set xrange [t0-TwoYearsInSec:t0]
set multiplot layout 2,1
set title "undesired y-autoscaling to 0 with filledcurves"
plot $Data u (timecolumn(1,myTimeFmt)):2 w filledcurves above x1 lc rgb 0xff0000 not
set title "workaround to scale to y-minimum"
stats $Data u 2 nooutput
set yrange[STATS_min:]
replot
unset multiplot
### end of script
Result: (created with gnuplot 5.4.0)
Related
My gnuplot script plot a bar graph for 2D data either in monochrome or color format:
set term pngcairo size 800,600
set termoption noenhanced
set tics font "Helvetica,10"
#set xtics noenhanced
set ylabel "Fraction, %"
set xlabel "H-bond donor/aceptor, residue"
set yrange [0:1]
set ytics 0.1
set grid y
set key off
set boxwidth 0.9
set style fill solid 0.5
# TWO OPTIONS FOR BAR VISUALISATIONS!! NB: ADD HERE TRIGGER FROM COLOR_DATA TRIGGER
# 1 - use it with non-colored bars"
#plot "\$data" using 0:2:xtic(1) with boxes, "" using 0:2:2 with labels offset 0,1
# 2 - or use it with colored bars:
plot \$data using 0:2:3:xtic(1) with boxes lc rgb var, \
'' using 0:2:2 with labels offset 0,1
The problem when I have just one bar, one the graph it occupiers all the graph on X:
Would it be possible to set some minimum dimension for the bars to make the dimensions of a single bar similar for a situations with two bars, for instance:
My understanding is the following: if you have only one box:
maybe gnuplot tries to autoscale and the automatic boxwidth is small relative to the autorange (hence just a thin line).
if you set a certain boxwidth, autoscale with scale to the given boxwidth (hence the graph filled with the box).
you could set a fixed xrange, but then you are loosing the benefits of autoscale. Instead you can use set offets (check help offsets).
if you have more than 1 box autoscale will work.
Script:
### boxwidth with boxes style
reset session
$Data1 <<EOD
1 Abc
EOD
$Data2 <<EOD
1 Abc
2 Xyz
EOD
set style fill solid 0.3
set key out
set rmargin screen 0.7
set yrange[0:]
set ytics 0.5
set multiplot layout 4,1
plot $Data1 u 0:1:xtic(2) w boxes ti "No special settings"
set boxwidth 0.9
plot $Data1 u 0:1:xtic(2) w boxes ti "set boxwidth"
set offsets 1,1,0,0
plot $Data1 u 0:1:xtic(2) w boxes ti "set offsets"
set offsets 0,0,0,0
plot $Data2 u 0:1:xtic(2) w boxes ti "more than 1 box"
unset multiplot
### end of script
Result:
I am trying to plot an inlet graph which is shown in Figure. Being an inlet graph it is needed to show x tics and y ticks of relatively big sizes for clear visibility. But when I increase the fonts as,
set xtics font ", 40"
tics overlaps with axis. I increased the plot size set term png size 1000, 1000 but still the issue persists. Kindly suggest if there is a way to move the tics below or to a desired position in graph.
Edit:
The gnuplot script looks like this,
set term png size 1000, 1000
set output "b_vs_N.png"
set style fill solid
set style circle radius 0.001
FIT_LIMIT=1.e-14
set yrange [0.15:0.25]
set style fill solid
set style circle radius 0.001
set xtics 10
set ytics 0.03
set border 15 back lw 6
set xtics font ", 40"
set ytics font ", 22"
set ylabel "b" enhanced font "1 {,40}"
set xlabel "N_i" font "1 {,40}"
set lmargin 12
set bmargin 4
set palette model HSV
set palette rgb 3,2,2
set palette maxcolors 12
set view map
AA(x)=a+b*x+c*x**2
fit AA(x) "data.txt" using 1:2 via c, b, a
plot "data.txt" using 1:2 lt 1 pt 11 ps 2.0 lc rgb "black" notitle, AA(x) w lines lw 2 lc rgb "sienna1" notitle
Your example is uncomplete without code and therefore difficult to reproduce. Please check help xtics. There is the option offset.
Maybe the following example helps to solve your issue.
In the example below no special offset seems to be necessary, i.e. offset 0,0, but you can shift and adjust the labels in x and y direction.
Code:
### tic label offset
reset session
set multiplot
plot sin(x)/x
set origin 0.07, 0.6
set size 0.3,0.3
set xrange [0:10]
set xtics 5 out font ",20" offset 0,0
plot x**2
unset multiplot
### end of code
Result:
I have a problem with how offsets work in gnuplot v5.4 compared to v5.2.
I tried to make the following graph (v5.2):
To create this graph, I used the following code...
set style line 1 lc rgb '#808080' lt 1 lw 2
set border 0 ls 1
set arrow from 0, graph 0 to 5, graph 0 nohead front ls 1
set arrow from graph 0,first 0 to graph 0, first 5 nohead front ls 1
set xtics nomirror
set ytics nomirror
set lmargin 10
set bmargin 3.5
set xrange [0:5]
set yrange [0:5]
set offsets graph 0.1, graph 0.1, graph 0.1, graph 0.1
plot 'example.txt'
... and data.
#x y
0 3.88222
1 4.20754
2 4.424
3 2.41443
4 1.95107
5 2.79098
In v5.4, this code results in a graph without offsets:
The documentation unfortunately does not address custom ranges.
I am not sure if this is a bug, a problem with my code or if the feature of using offsets and custom ranges got removed in gnuplot v5.4 altogether.
Thank you in advance!
The documentation section for "offset" is not good in gnuplot version 5.
My understanding is that the current (version 5.4) behavior is
offsets only affect auto-scaling
explicit axis ranges take precedence over auto-scaling, so offsets have no effect if there is an explicit range for that axis
The style of plot shown in the query is best achieved in gnuplot 5.4 by using the keyword rangelimited, e.g. set tics rangelimited if you want this on all axes
The commands below work the same way in gnuplot versions 5.0 and 5.2 as they do in version 5.4, so I am thinking that this example shows not a sudden change between the two versions but rather a gradual accumulation of small differences between versions 4 and 5. I will file a bug report pointing out the inadequacy of the current documentation section on "offset".
Revised code
# Modified for gnuplot version 5.4
set xtics rangelimited nomirror
set ytics rangelimited nomirror
set border 3
set offsets graph 0.1, graph 0.1, graph 0.1, graph 0.1
plot 'example.txt' with points
A strange observation which I can reproduce. The following further minimized code behaves differently in gnuplot 5.2 and gnuplot 5.4
reset session
set xrange[0:5]
set yrange[0:5]
set offset graph 0.1, graph 0.1, graph 0.1, graph 0.1
plot x
I'm not sure why it is different. The following a bit cumbersome workaround will lead to the same result in gnuplot 5.2. and gnuplot 5.4 with the cost of replotting. But I hope there will be an easier solution which is currently not obvious to me. Maybe there is another setting in gnuplot 5.4 which "recovers" this 5.2 behaviour.
Code:
### "manual" offset for gnuplot 5.4
reset session
$Data <<EOD
#x y
0 3.88222
1 4.20754
2 4.424
3 2.41443
4 1.95107
5 2.79098
EOD
set style line 1 lc rgb '#808080' lt 1 lw 2
set border 0 ls 1
set arrow from 0, graph 0 to 5, graph 0 nohead front ls 1
set arrow from graph 0,first 0 to graph 0, first 5 nohead front ls 1
set xtics nomirror
set ytics nomirror
set lmargin 10
set bmargin 3.5
set xrange [0:5]
set yrange [0:5]
xRange(a) = GPVAL_X_MAX -GPVAL_X_MIN
yRange(a) = GPVAL_Y_MAX - GPVAL_Y_MIN
xOffMin(a) = GPVAL_X_MIN - a*xRange(a)
xOffMax(a) = GPVAL_X_MAX + a*xRange(a)
yOffMin(a) = GPVAL_Y_MIN - a*yRange(a)
yOffMax(a) = GPVAL_Y_MAX + a*yRange(a)
plot $Data
set xrange [xOffMin(0.1):xOffMax(0.1)] # graph 0.1
set yrange [yOffMin(0.1):xOffMax(0.1)] # graph 0.1
replot
### end of code
Result: (gnuplot 5.2 and gnuplot 5.4)
Addition:
Well, you are setting a fixed x- and y-range and then you add 10% extra offset. So, you either could set directly set xrange[-0.5:5.5] and set yrange[-0.5:5.5] or do a calculation as in the code below. But, I agree if it worked as in gnuplot 5.2 where you set the ranges and then add 10% extra offset would be much more convenient.
reset session
xMin=0
xMax=5
yMin=0
yMax=5
OffLeft = 0.1
OffRight = 0.1
OffTop = 0.1
OffBottom = 0.1
xRange = xMax-xMin
yRange = yMax-yMin
set xrange[xMin-OffLeft *xRange : xMin+OffRight*xRange]
set yrange[xMin-OffBottom*yRange : yMin+OffTop *yRange]
plot x
My GNUplot 5.2 plot of:
$heights << EOD
dad 181
mom 170
son 100
daughter 60
EOD
set terminal png
plot '$heights' using 2:xtic(1) with boxes
As you can see "daughter" doesn't start at zero. I tried set yzeroaxis from the documentation but that didn't appear to have any impact.
BONUS: How do I remove that $heights using 2:xtic(1) line?
Fabiola's answer is correct but can be improved to show additional options
set yrange [0:*] # start at zero, find max from the data
set boxwidth 0.5 # use a fixed width for boxes
unset key # turn off all titles
set style fill solid # solid color boxes
plot '$heights' using 2:xtic(1) with boxes
You can use the command Xrange and Yrange to set the limits of axis:
set yrange [0:200]
set xrange [-1:4]
plot '$heights' using 2:xtic(1) with boxes notitle
The additional argument notitle removes the key.
I could not find a solution to the following issue I am facing. All SO questions on multi-axis talk about line plots, but I am looking for histograms.
The y-range for the bars are different, so one set of bars are not really seen because of the scale. Here is the data:
Metric A B
M1 0.613416301 0.543734744
M2 0.000195961 0.000100190
Here is the MWE:
reset
set term postscript eps size 5.5,4.5 enhanced color font 'Arial-Bold' 25
set out 'histplot.eps'
set key right
set style histogram cluster gap 2
set style data histograms
set style fill pattern 1.00 border
set y2range [0.0001:0.0002]
plot 'histplot.dat' using 2 ti col, '' u 3:xticlabels(1) ti col
quit
This is the sample output (one set of bars over M2 is not seen):
What I prefer is to have a second y-axis (to the right side of the plot) with a range appropriate to the second row of my data file. Is this possible? Any help is greatly appreciated.
Normally you can plot severyl histograms beneath each other using newhistogram. However, it seems like this is buggy when using patterns as fillstyle:
reset
set style histogram cluster gap 1
set style data histograms
set style fill pattern 1.00 border
set yrange [0:*]
set ytics nomirror
set y2range [0:*]
set y2tics
set key right autotitle columnheader
plot 'histplot.dat' u 2 every ::::0, '' u 3:xtic(1) every ::::0,\
newhistogram lt 1 at 1,\
'histplot.dat' u 2 every ::1::1 axes x1y2, '' u 3:xtic(1) every ::1::1 axes x1y2
Alternatively you can use multiplot and plot the two histograms directly beneath each other:
reset
set style histogram cluster gap 1
set style data histograms
set style fill pattern 1.00 border
set yrange [0:*]
set ytics nomirror
set multiplot layout 1,2
set rmargin at screen 0.5
set lmargin 9
unset key
plot 'histplot.dat' using 2 every ::::0 ti col, '' u 3:xticlabels(1) every ::::0 ti col
set rmargin 9
set lmargin at screen 0.5
unset ytics
set y2range [0:*]
set y2tics
set key right
plot '' using 2 every ::1::1 axes x1y2 ti col, '' u 3:xtic(1) every ::1::1 axes x1y2 ti col
unset multiplot
If you don't want the separating black line, you can use set border 7 for the first and set border 13 for the second plot.