Is there any way to have gnuplot color the tic marks in the x and/or y axis? I'm using a background png file which is quite dark and I'd like the inner tics to show in white over it, not the default black.
The tics seem to inherit their color from the border:
set style line 50 lt 1 lc rgb "red" lw 2
set border ls 50
plot sin(x)
The tic labels get their color from the textcolor option of tics:
set tics textcolor rgb "red"
(The string "white" should work too, but that wouldn't look very nice in my demonstration since my background is white).
There is no way to change just the tic-color. However, if you want, you can change the tic/border color and then add a new border on top:
set arrow from graph 0,graph 1 to graph 1,graph 1 nohead ls -1 lc rgb "black" front
set arrow from graph 1,graph 1 to graph 1,graph 0 nohead ls -1 lc rgb "black" front
set arrow from graph 1,graph 0 to graph 0,graph 0 nohead ls -1 lc rgb "black" front
set arrow from graph 0,graph 0 to graph 0,graph 1 nohead ls -1 lc rgb "black" front
Whilst this post is quite old, I though I'd offer my 2cents because I have a valid addition to the above.
If you immediately follow the set border command with unset border, then the colour of the tics & their labels remains in the colour you set, and the border just gets removed. For example,
set border linecolor rgb "gray75"
unset border
This way, you can at least change the colour of the tics & their labels (here, off-white), & your background remains dark & untainted by an unsightly (off-white) border, which is what the OP asked for?
Thus, no need to manually redraw the border in the previous answer. Still, the best answer above was useful to me so I will uptick!
Related
In gnuplot, we can set the tick scale, but this only affects the length of the ticks.
How can we change the width of the ticks?
I don't see any option in the tags of xtics or ytics that would set the appropriate width.
As theozh says, the tics are drawn using the 'border' line type. If necessary I suppose you could turn off the border, set the border linetype to whatever you want the tics to be, and then use a graph-sized rectangle to replace the border.
set border lc "black" lw 0.25 # thin lines for the tics
set border 0 # don't draw the normal border
set tics scale 3.0 # longer than usual tics
set obj 1 rectangle from graph 0,0 to graph 1,1
set obj 1 lc "black" lw 2.5 # heavy line for the "border"
set obj 1 fillstyle empty
set grid x y
plot sinc(x)
Check help border. My guess would be that the tic width can probably not set independently of the border. Well, you could play with multiple graphs with different borders and tics on top of each other. Check help multiplot.
Code:
### set tic width
reset session
set border lw 3
set xtics scale 4
set ytics scale 1
plot x
### end of code
Result:
I would like to create a color bar plot of a single variable that draws a box to the left in red if the variable is negative and green to the right if positive.
I am failing to get rid of the y axis completely. There shall be no marking of it whatsoever. Second the x-axis and tics is hidden behind the box. I need it visible. Third the plot of the line at 0 is really unnecessary as I have already drawn all I need but gnuplot wants a plot cmd with some sort of argument. I tried plot 0 lt bgnd but that left an ugly white line in my box. I guess I can live with that. Arrows at the ends of the x-axis would be nice, too.
This is the current state of the code. (the variable v will later come from the outside world as command line argument)
v= 7.3
if (v<0){boxcolor= 'red'}
if (v>=0){boxcolor= 'green'}
unset border
unset ytics
unset key
set yzeroaxis
set xzeroaxis
set xtics axis
unset ytics
set xrange [-10:10]
set object 1 rect from 0.0,-0.5 to v,0.5 back fillcolor rgb boxcolor
plot 0
Result currently:
You are probably looking for something like this:
Update: improved version
using graph and first coordinates for the arrow (check help coordinates), hence independent of the actual x-range.
using xzeroaxis (check help xzeroaxis)
Script:
### only x-axis with arrows
reset session
set border 0
unset ytics
v= 7.3
boxcolor = (v<0) ? 'red' : 'green'
set xrange [-10:10]
set xtics axis mirror
set xzeroaxis lt 1 lc "black"
set object 1 rect from 0.0,-0.5 to v,0.5 behind fillcolor rgb boxcolor
set arrow 1 from graph -0.03, first 0 to graph 1.03, first 0 heads filled
plot cos(x)
### end of script
Result:
Another answer: This one uses the built-in axis variants rather than an arrow:
set border 0
unset key
# In newer gnuplot versions there is a keyword "nodraw"
# Here we define a synonym that works with older versions also
hide = -4
set yzeroaxis lt hide lc hide
set xzeroaxis lt black
set tics front
unset ytics
set xtics axis
# define rectangle here
set object 1 rect from 0,-.5 to 5,.5 behind fs noborder fc "green"
#
plot 0 with lines lc "black"
My data file has just two columns.The following MWE on those columns produces boxes with repeated colors. Is it possible to produce unique colors for each box?
reset
set term postscript eps size 5.5,4.5 enhanced color solid lw 2\
font "arial,28"
set key right
set xtics rotate -45 font ",20"
set style fill solid 1 border -1
plot 'rankdefcount.dat' using ($0):2:($0):xticlabels(1) \
notitle w boxes lc variable
quit
Here is the output I got:
After few attempts and help from the SO experts, I came up with the following solutions; none of them perfect, though.
Solution 1: ( with a random repetition using rand and rgb calls)
reset
set term postscript eps size 5.5,4.5 enhanced color solid lw 2 font \
"arial,28"
set key right
rgb(r,g,b)=int(255*r)*65536+int(255*g)*256+int(255*b)
do for [i=1:31] {
myrand=rand(int(rand(0)*i*100)+i*100)
set style line i linecolor rgb rgb(rand(0),rand(0),rand(0))
}
set xtics rotate -45 font ",20"
set style fill solid 1 border -1
plot 'rankdefcount.dat' using ($0):2:($0):xticlabels(1) \
notitle w boxes lc variable
quit
Here is the corresponding output:
With palette definition (solution 2):
reset
set term postscript eps size 5.5,4.5 enhanced color solid lw 2 font \
"arial,28"
set key right
set palette color model HSV
set palette defined (0 0 1 1,1 1 1 1)
set palette defined ( 0 0 1 0, 1 0 1 1, 6 0.8333 1 1, 7 0.8333 0 1)
set boxwidth 0.5
unset colorbox
set xtics rotate -45 font ",20"
set style fill solid 1 border -1
plot 'rankdefcount.dat' using ($0):2:($0):xticlabels(1) \
notitle w boxes lc palette
quit
This is the output:
For another solution (solution 3), replace the definition above with the following lines:
set palette color model HSV
set pm3d explicit at b
set palette rgbformulae 3, 2, 2
This is what I got:
You may try and redefine as much linetypes as boxes you want to show. The code should go before the plot.
colors="black red orange #fa8072 ...." #[as much colors as needed]
do for [L=1:words(colors)]{
set linetype L lc rgb word(colors,L)
}
You can find colors for gnuplot here.
http://www.uni-hamburg.de/Wiss/FB/15/Sustainability/schneider/gnuplot/colors.htm
in the following code I try to achieve the following:
1) As can be seen, the description 'talkative' does not appear. Is this really the y2axis? Or does y2axis not account for splot but only for plot?
Or do I have to label a border ?
2) How do I get tics only at the axis of interest?
3) A small detail: A close look reveals that the blue dot is transparent, but not the red and green dot. How to also make the blue dot filled?
set ticslevel 0
set xrange [0:1]
set yrange [0:1]
set zrange [0:1]
set object 1 polygon from \
0, 0, 1 to \
0, 1, 0 to \
1, 0, 0 to \
0, 0, 1
set view 56, 77
set style line 1 lc rgb "blue" pt 7 ps 2
set style line 2 lc rgb "red" pt 7 ps 2
set style line 3 lc rgb "green" pt 7 ps 2
unset xtics
unset ytics
unset ztics
set border 1+2+16
set xlabel "listening" offset +4,0
set y2label "talkative"
set zlabel "sleeping" rotate offset -1,-2
splot \
'-' with points ls 1 title "",\
'-' with points ls 2 title "",\
'-' with points ls 3 title ""
1 0 0
e
0 1 0
e
0 0 1
e
Unfortunately not a solution, but some explanations:
Yes, splot doesn't have an x2 and y2 equivalent. You can set a ylabel and shift it:
set ylabel 'talkative' offset graph -1.5
You mean getting tics only at the 'talkative' axis? That isn't possible out-of-the-box. You can have tics only on the y-axis (which gnuplot selects to always the the one in the front), or on both front and back y-axis.
That seems to be a bug to me. Usually you can set the border to be behind everything with set border back, but that doesn't work in this situation (tested with 4.6.5 and 5.0RC2). And it's also strange that it involves only one axis.
There are no second axes for splots. You can see this when you rotate the plot with the mouse: The drawn border, the tics and the label are jumping from one side to the other. You can also see the intention: If the volume is quite full of plot data, the axes in the rear would be hidden by your plots. So as soon as this can happen, gnuplot switches to axes in the front. There seems to be no way around.
(btw: when drawing the full border box, you have 4 axes in each direction. And there is definitively no y3tics or y4tics...)
set xtics nomirror
It's not really transparent, as only the "front border" is visible on the dot. The other lines (and also tick labels) are behind the dot. set border back should help, but it doesn't. The setting has an effect only for plot , not for splot. The data is plottet between front and rear axes, and so, the data hides the rear axes, but the front axes are drawn in front of the data.
In general, this all makes sense, but for special cases, there are options to tweak the plot as you want. However, only for plot ...
I want to fill a bar with both a color background and a pattern. Is it possible in Gnuplot?
I am using Gnuplot 4.6.5
The code I have now:
# set terminal pngcairo transparent enhanced font "arial,10" fontscale 1.0 size 500, 350
# set output 'histograms.2.png'
set boxwidth 0.9 absolute
set style fill solid 1.00 border lt -1
set key inside right top vertical Right noreverse noenhanced autotitles nobox
set style histogram clustered gap 1 title offset character 0, 0, 0
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror rotate by -45 offset character 0, 0, 0 autojustify
set xtics norangelimit font ",8"
set xtics ()
set title "US immigration from Northern Europe\nPlot selected data columns as histogram of clustered boxes"
i = 22
set yrange [0:2000]
set style line 1 lc rgb 'orange';
set style line 2 lc rgb 'pink';
plot for [i=2:7] 'data.dat' using i:xtic(1) ti col ls i%2+1;
The data file:
Region Denmark France Demark-Women France-women Demark-man France-men
1891-1900 1000 1100 500 600 500 500
1901-1910 1500 1600 1000 600 500 1000
Here are the links to download the script: https://dl.dropboxusercontent.com/u/45318932/histograms2.plt and data file: https://dl.dropboxusercontent.com/u/45318932/data.dat
The script gives me:
What I want is:
It would be much appreciated if someone can help me improve the code to produce the second figure. Thanks.
That one is very tricky because you cannot change the background color of the fill patterns. And by default the background color of the patterns is white, and not transparent or empty.
The only terminal which can be manipulated adequately is the lua tikz terminal. Here, I first draw all the color boxes, and later in a second iteration the fill patterns. To have a new iteration, I use the newhistogram option, which however causes a gap in the legend.
To remove the white background of the fill patterns, I remove the relevant parts from the output stream with sed. Quite hacky, but it works:
set terminal lua tikz standalone size 5in, 3in color
set output '| sed ''s/\\gpfill{color=gpbgfillcolor}//g'' > histograms.tex'
set boxwidth 0.9 absolute
set style fill solid 1.00 border lt -1
set key inside right top vertical Right noreverse noenhanced autotitles nobox
set style histogram clustered gap 1 title offset character 0, 0, 0
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror rotate by -45 offset character 0, 0, 0 autojustify
set xtics norangelimit font ",8"
set xtics ()
set title "US immigration from Northern Europe\nPlot selected data columns as histogram of clustered boxes"
i = 22
set yrange [0:2000]
set xrange [-1:2]
set style line 1 lc rgb 'orange';
set style line 2 lc rgb 'pink';
plot for [i=2:7] 'data.dat' using i:xtic(1) ti columnhead(i > 3 ? 10 : i) ls i%2+1 fillstyle solid noborder,\
newhistogram at -1, \
'' using 2 ti 'total' lt -1 fillstyle empty,\
'' using 3 notitle lt -1 fillstyle empty,\
'' using 4 title 'women' lt -1 fillstyle pattern 5,\
'' using 5 notitle lt -1 fillstyle pattern 5,\
'' using 6 title 'men' lt -1 fillstyle pattern 6,\
'' using 7 notitle lt -1 fillstyle pattern 6
set output
system('pdflatex histograms.tex')
Result with 4.6.5:
Just found out, that you can specify the patterns to have no background color like
... fillstyle pattern 6 transparent
For which terminals that works depends on the gnuplot version:
plot x with filledcurves x1 fillstyle solid fc rgb '#990000',\
x with filledcurves x1 fillstyle pattern 4 transparent lc rgb 'white'
Result (with svg terminal and version 4.6.5):