I want to rotate the xtics by 45 degree. In another word the direction is /. Problem is the tics will appear inside the chart area, I want to put them outside of chart. See the figure:
You must adjust both the alignment (can be right, center or left) and the offset (x,y coordinates with respect to the default tics position) of the xtics.
Here is an example, which demonstrates the three different possiblities. The offset must be adjusted manually, in order to get it right:
set xrange [0.5:3.5]
set bmargin 5
set multiplot layout 1,3
set xtics ('first' 1, 'second' 2, 'third' 3) rotate by 45 right
set title 'right aligned'
plot x
set xtics center offset 0,-1
set title 'centered'
replot
set xtics left offset 0,-2
set title 'left aligned'
replot
unset multiplot
This gives (with 4.6.4):
Related
gnuplot adds grid lines even on axes, it can cause unpleasant effects:
set logscale x
set xrange [0.01:100]
set xtics font ",12"
set x2tics font ",12"
set mxtics 10
set ytics font ",12"
set y2tics font ",12"
set grid xtics mxtics ytics lt 0 lw 3, lt 0 lw 0.5 behind
set grid
plot sin(x)
Especially if one then plots the above to eps, it looks like there are both logarithmically spaced and linearly spaced tics on the x-axis. Is there any nice way to get rid of the grid lines at axes? A workaround would be to make the axes thicker, but that is not the way I want. I really want to delete those grid lines.
To explain what I mean
The linearly spaced tics that are seen in the picture are actually the dotted grid, so it has nothing to do with tics...
As shown, there are both log and linear tics along x. That is because both the x axis and the x2 axis are contributing tics to both the top and bottom borders. You can turn that off with
set tics nomirror
Are you asking how to make the range of the tics smaller than the range of the axes? In the plot you show, that would be
set yrange [-1:1]
set ytics -0.8, 0.2, 0.8
set ytics add (-1 2, 1, 2)
The last command adds back explicit tics at y=-1 and y=1 without generating a corresponding grid line. See documentation for set xtics list
I am using multiplot to plot four graphs. My code is given below
set term postscript eps enhanced color
set pm3d map
set pm3d corners2color c1
set size square
set out 'defect2.eps'
unset colorbox
set colorbox horiz user origin 0.1,0.7 size 0.8,0.02
set cbrange [-1.6:0]
set xtics 25
set ytics 25
set lmargin at screen 0.1
set rmargin at screen 0.9
set multiplot layout 1,4
set xlabel "i" font "Times-italic,20"
set ylabel "j" font "Times-italic,20"
spl 'defect.dat' notitle
unset ylabel
spl 'defect_2.dat' notitle
spl 'defect_3.dat' notitle
spl 'defect_4.dat' notitle
unset multiplot
set out
This produces a following plot
However, individual plots in the picture are not properly placed. I cannot see ylabel for the first plot as it is hidden behind the screen whereas there are large blank gaps between those plots. Is there any way to reduce these gaps, increase size of these plots and show the labels properly?
Thanks in advance.
The Problem is your margin setting. The margin defines the size of the white stripe between the box containing the plot and the border of the window.
This means, tic and axis labels are printet on the Martin area! And your 10% of window width is not enough, so the labels are clipped.
So you can adjust the margins to shift all plots more to the left or adjust label font sites and offsets (Miguel's comment).
I want to plot two charts (reading the same data points) using multiplot. The purpose is to put the second (smaller) chart in the right of the first (bigger) chart.
The code is
set term post eps enhanced color blacktext size 4,4 solid "Times-Roman" 14
set output 'cla.ps'
set multiplot
# draw bottom and left lines
unset border
unset xtics
unset ytics
set border 3
# increasing the canvas size
set rmargin 50
set tmargin 2
# put the big chart, it will not use the whole space
set origin 0,0
set size 1.2,0.5
plot 'test.txt' u 1 with points lc rgb "black"
# put the small char in the right
set origin 0.6,0.2
set size 0.2,0.2
plot 'test.txt' u 1 with points lc rgb "black"
# always unset multiplot
unset multiplot
Problem is, the second chart is shown in a mirror fashion (horizontal flip). But I didn't such an option. How can I fix that?
That should give you a nice warning explaining that: warning: Terminal canvas area too small to hold plot. Check plot boundary and font sizes.
With set rmargin 50 you set the right margin to be 50 character widths. That applies also to the second plot unless you use e.g. set rmargin -1 to reset it to automatic calculation.
But I don't see any sense to set both the size and the rmargin. Setting the rmargin does not increase the canvas size, like you suggest in your comments.
Here is a working example:
set term post eps enhanced color blacktext size 4,2 solid "Times-Roman" 14
set output 'cla.ps'
set multiplot
# draw bottom and left lines
unset tics
set border 3
# put the big chart, it will not use the whole space
set origin 0,0
set size 0.8,1
plot x**2
# put the small char in the right
set origin 0.75,0.2
set size 0.25,0.3
plot x
# always unset multiplot
unset multiplot
That gives you the output (tested with 4.6.5):
I need to plot a function on a coordinate system that has its origin at the center of the screen (or somewhere near the center, but not necessarily in the center) and I need to draw axes so that they cross at the origin. Axes should have labels and tics as well, and arrows.
I have no idea how to do this efficiently, so far in my code I manually set offsets for my tics, and draw arrows manually using offsets as well. I also set offsets on the axes labels. All this is very fragile, and offsets change depending on the terminal settings.
Would someone please help me with a sample code or an explanation how to do this the right way?
Well, using _zeroaxis is the "right" way to go to get the tics and labels in: setting the _range gives you the symmetry to make 0,0 centre ... and once you know the _range, you can draw arrows on manually.
set xzeroaxis
set xtics axis
set xrange [-10:10]
set arrow 1 from -9,0 to -10,0
set arrow 2 from 9,0 to 10,0
set yzeroaxis
set ytics axis
set yrange [-1:1]
set arrow 3 from 0,-.9 to 0,-1
set arrow 4 from 0,.9 to 0,1
set border 0
plot sin(x)
Hack attack!
set term pngcairo truecolor size 300,300 font "Arial,12"
set out 'plot.png'
# x,y min/max and center
xmin = -10
xc = 0
xmax = 10
ymin = -2
yc = 0
ymax = 2
# default borders
tm = 1
bm = 1
rm = 4
lm = 4
# arrow scale factor to cover last tic
af = 1.05
set arrow from xc,yc to xmin*af,yc filled size 0.6,30
set arrow from xc,yc to xmax*af,yc filled size 0.6,30
set arrow from xc,yc to xc,ymax*af filled size 0.6,30
set arrow from xc,yc to xc,ymin*af filled size 0.6,30
set multiplot layout 2,2
## Plot 1, top left
set key top left
set xr [xmin:xc]
set yr [yc:ymax]
set tmargin tm
set bmargin 0
set rmargin 0
set lmargin lm
set border 9
unset ytics
set xtics nomirror
plot sin(x)
## Plot 2, top right
unset key
set xr [xc:xmax]
set lmargin 0
set rmargin rm
set border 3
set ytics nomirror
replot
## Plot 3, bottom left
set xr [xmin:xc]
set yr [ymin:yc]
set bmargin bm
set tmargin 0
set lmargin lm
set rmargin 0
set border 12
unset tics
replot
## Plot 4, bottom right
set xr [xc:xmax]
set lmargin 0
set rmargin rm
set border 6
set ytics nomirror
replot
unset multiplot
I get this output:
That said, you might look into the zeroaxis option. There is a demonstration here. Sadly this option doesn't draw the axis at zero, but just puts a line at that position.
I would not say my method is 'efficient,' but there is probably not too much effort to modify this for your purposes apart from changing the function/data being plotted since most of the work is done by replot commands. I don't know an option to make gnuplot put arrows at the end of axes or change where the axes are drawn natively.
In addition to Jim's answer, if required the tics and axes can be brought to the front
# bring the grid over the plot
set grid front
# remove grid if not required
unset grid
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 ...