Gnuplot locally change label font color - colors

I have a gnuplot label for my plot
plot f(x) title 'Before(w)' with lines ls 1
In my label there is Before(w). I would like the color of a letter w to be red. How can I do it?
I was able to find code that changes the color of the whole label (http://www.gnuplot.info/demo_4.6/textcolor.html) but it is not what I want.
Thanks.
Working example
set terminal postscript eps size 3.5,2.62 enhanced color \
font 'Helvetica,20' linewidth 2
set output 'plot2.eps'
set style line 1 linecolor rgb '#0060ad' linetype 1 linewidth 2 #(gnuplotting)
f(x) = exp(-x*x)
plot f(x) title 'Before(w)' with lines ls 1

Related

Gnuplot svg: change data point color

I am using Gnuplot 5.2 patchlevel 2, and want to make an SVG scatter plot with three different datasets. I cannot change the color of the data points.
set term svg enh size 1800,1800 font "Times,20" rounded background rgb white'
set output 'plot.svg'
set style line 1 lc rgb 'red' pt 7 ps 1 lt 1 lw 2
plot 'data.file' w lp ls 1 ti "Set 1"
The data points remain black, but the lines are (correctly) red. This is something unexpected, it works in the other terminals.

Color repetition when using boxes in gnuplot

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

GNUplot - plot data file (simple X and Y columns) - setting suitable color and scale on a figure

I have a simple file with two columns:
1 0.005467
2 0.005333
3 0.005467
4 0.005467
5 0.005600
6 0.005600
7 0.005467
8 0.005467
In the first column I have the x-axis values, while on the second column I have y-axis values. I would like to plot a figure of this data. I wrote a gnuplot script for this:
#!/usr/bin/gnuplot
set xlabel "test"
set ylabel "value"
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"
set grid xtics lt 0 lw 1 lc rgb "#bbbbbb"
set autoscale
set terminal postscript portrait enhanced mono dashed lw 1 'Helvetica' 14
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "red"
set output 'out.eps'
plot 'data.txt' using 2:1 w points title "tests"
And, the output:
But of course, as a newbie in gnuplot, I have some troubles:
How to change the crosses on the fingure into dots?
How to change the color of the dots, to let's say, red? ( my command in my gnuplotscript seems not to work at all ...)
For the first test the adequate, accurate, exact value is 0.005467 but on my figure it doesnt look like so... I would like to place the dot on my figure for the first, second, third, (so on) test on the exact place, where is appropriate value.
How to add a grid to my figure? - SOLVED
How to get rid of the ugly text: 'data.txt' using 1:2 and replace it with a legend? - SOLVED
EDIT (SOLVED ISSUE NO 5)
plot 'data.txt' using 1:2 w points title "tests"
EDIT (SOLVED ISSUE NO 4)
set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"
set grid xtics lt 0 lw 1 lc rgb "#bbbbbb"
You should read a bit in the documentation about all your commands!
Several remarks:
If you want colored points, you shouldn't use the mono (i.e. the monochrome) option, but rather color.
Your definition of the line style is correct, but in order to use it you must use linestyle 1 when plotting. Otherwise the linetype 1 is used. Compare:
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "red"
plot x, 2*x linestyle 1
In order to see all the dots of a terminal, use the test command:
set terminal postscript eps enhanced color dashed lw 1 'Helvetica' 14
set output 'test.eps'
test
set output
You see, that for filled dots you must use pt 7.
I'm sure, that the points are shown at the correct values. Use
set ytics add (0.005467)
to see this.

grayscale histogram with gnuplot

I'm new to gnuplot and I want to draw a triple histogram for a set of data of any length.
Here is my code but the line set palette gray seems to have no effect -- everything is still in RGB. What am I missing here?
set terminal pdf enhanced
set output 'out.pdf'
set palette gray
set style data histogram
set style histogram cluster gap 1
set style fill solid 1
set auto x
set yrange [0:*]
plot 'in.dat' using 2:xtic(1) title col, \
'' using 3:xtic(1) title col, \
'' using 4:xtic(1) title col
The set palette command influences only images, pm3d surfaces and if used explicitely with e.g. linecolor palette.
The terminal option monochrome also doesn't help you, because that sets the color of all lines to black and uses different dash patterns.
You can e.g. redefine the color of the linetypes:
set linetype 1 lc rgb 'black'
set linetype 2 lc rgb '#555555'
set linetype 3 lc rgb '#999999'
plot 'in.dat' u 2:xtic(1) t col, '' u 3 t col, '' u 4 t col
Note, that reset doesn't revert this line type changes. For this you must restart gnuplot.
Alternatively, you could also use set terminal pdf monochrome and set style fill pattern.

Gnuplot change color of bars in histogram

is it possible to change the color of bars in a Gnuplot script dynamically?
I have the following script
reset
fontsize = 12
set term postscript enhanced eps fontsize
set output "bargraph_speedup.eps"
set style fill solid 1.00 border 0
set style histogram
set style data histogram
set xtics rotate by -45
set grid ytics linestyle 1
set xlabel "Benchmarks" font "bold"
set ylabel "Relative execution time vs. reference implementation" font "bold"
set datafile separator ","
plot 'bm_speedup.dat' using 2:xtic(1) ti "Speedup" linecolor rgb "#00FF00"
which generates this plot:
Is it possible to make the color of the bars which are below zero red?
Thanks,
Sven
You can mimic this behavior using the boxes style:
My test data:
zip 2
baz 2
bar -1
cat 4
foo -3
And then plotting with gnuplot:
set style line 1 lt 1 lc rgb "green"
set style line 2 lt 1 lc rgb "red"
set style fill solid
plot 'test.dat' u (column(0)):2:(0.5):($2>0?1:2):xtic(1) w boxes lc variable
# #xval:ydata:boxwidth:color_index:xtic_labels
You could split your data file into two parts, positive values and negative, and plot them separately:
plot 'bm_speedup_pos.dat' using 2:xtic(1) ti "Faster" linecolor rgb "#00FF00", \
'bm_speedup_neg.dat' using 2:xtic(1) ti "Slower" linecolor rgb "#FF0000"
Or, if you only need to generate a few graphs, a few times, a common technique is to generate the raw graph in gnuplot, then post-process it in an image editor to adjust the colors. If you go that route, I suggest having gnuplot generate the graph in SVG format, which will give you much better looking graphs than any of the bitmap formats.
Doesn't seem like histogram lets you do it. May be like this:
set boxwidth 0.3
f(v)=v<0?1:2
plot 'bm_speedup.dat' using 0:2:(f($2)):xticlabels(1) with boxes ti "Speedup" lc variable
Actually you can also use linecolor rgb variable and give the color like this:
plot 'bm_speedup.dat' using 2:xtic(1):($2 >= 0 ? 0x00FF00 : 0xFF0000) ti Speedup lc rgb variable

Resources