I am just learning gnuplot and I want to plot a sensor signal with a grid, but no matter what I try the grid is always dotted and I want the grid to be solid line. I try setting linetype to -1 to no avail, can someone help me?
example
set grid xtics lt -1 lw 1 lc rgb "#880000"
set grid ytics lt -1 lw 1 lc rgb "#880000"
plot [-10:10] sin(x),atan(x),cos(atan(x))
I just uninstall and reinstall GNUPLOT again and now is working.. no idea what was the problem, but that was the fix.
Thank you for all the help.
Related
I understand that we can omit the key in GNUplot using unset key. If I want to insert a small image to signify the key onto a XY 2-D plot, how to do it? In MS-Excel, it is just a matter of copying an image and pasting it on to the plot and adjusting its placement and size. Can such a thing be done in GNUPlot too? By what plot option? I am attaching a sample a of what I expect in a multiplot I made (the plot on the top left). And I have the small molecule image as a png file. I have also listed the code below. Please help me. Thanks.
reset
set size 1,1
set multiplot
unset key
#CPD
set size 0.5,0.5
set origin 0,0.5
unset title
plot 'Practice1.dat' using 1:2 w points lw 3 lc rgb 'red'
plot 'Practice1.dat' using 1:6 smooth csplines lw 3 lc rgb 'red'
#Ethene
set size 0.5,0.5
set origin 0.5,0.5
set title 'Ethene'
plot 'Practice1.dat' using 1:3 w l lw 3 lc rgb 'blue'
#Benzene
set size 0.5,0.5
set origin 0,0
set title 'Benzene'
plot 'Practice1.dat' using 1:4 smooth csplines lw 3 lc rgb 'green'
#H2
set size 0.5,0.5
set origin 0.5,0
set title 'H2'
plot 'Practice1.dat' using 1:5 w l lw 3 lc rgb 'black'
The image will be a plot in itself.
plot "image.png" binary filetype=png center=(975,40) dx=200 w rgbimage, \
'Practice1.dat' using 1:2 w points lw 3 lc rgb 'red', \
'Practice1.dat' using 1:6 smooth csplines lw 3 lc rgb 'red'
Note that you should avoid having several plot commands without changing origin/size in multiplot, as the labels and borders are overlaid and this may change their appearance depending on terminal (because e.g of antialiasing), hence the usage of , and the splitting of the command on multiple lines (with \)
Note also that set multiplot could have done the layout of your simple 2x2 plot all by itself for you, set multiplot layout 2,2
Is there an elegant (i.e. not by writing plot 0 with a black line) way to emphasize OX? In other words, to highlight part of the grid.
Thanks.
Use set xzeroaxis:
set xzeroaxis lt 1 lc rgb 'black' lw 2
plot x
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!
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
I have two pairs of datasets, which I need to plot using Gnuplot.
I want the first pair to be plotted in red, one solid and one dashed. The second pair, I want to plot in blue, one solid and one dashed.
I've experimented with set style line several times, but I cannot get this exact behaviour. My last attempt (attached) plots the first pair in red (solid) and the second pair in blue (dotted).
Any help will be greatly appreciated.
set style line 1 lt 1 lw 3 pt 3
set style line 2 lt 1 lw 3 pt 3
set style line 3 lt 3 lw 3 pt 3
set style line 4 lt 3 lw 3 pt 3
plot 'data1.dat' using 1:3 w l ls 1,\
'data1.dat' using 1:4 w l ls 2,\
'data2.dat' using 1:3 w l ls 3,\
'data2.dat' using 1:4 w l ls 4
You need to use linecolor instead of lc, like:
set style line 1 lt 1 lw 3 pt 3 linecolor rgb "red"
"help set style line" gives you more info.
I've ran into this topic, because i was struggling with dashed lines too (gnuplot 4.6 patchlevel 0)
If you use:
set termoption dashed
Your posted code will work accordingly.
Related question:
However, if I want to export a png with:
set terminal png, this isn't working anymore. Anyone got a clue why?
Turns out, out, gnuplots png export library doesnt support this.
Possbile solutions:
one can simply export to ps, then convert it with pstopng
according to #christoph, if you use pngcairo as your terminal (set terminal pngcairo) it will work
You can also set the 'dashed' option when setting your terminal, for instance:
set term pdf dashed
Here is the syntax:
set terminal pdf {monochrome|color|colour}
{{no}enhanced}
{fname "<font>"} {fsize <fontsize>}
{font "<fontname>{,<fontsize>}"}
{linewidth <lw>} {rounded|butt}
{solid|dashed} {dl <dashlength>}}
{size <XX>{unit},<YY>{unit}}
and an example:
set terminal pdfcairo monochrome enhanced font "Times-New-Roman,12" dashed
You might want to look at the Pyxplot plotting package http://pyxplot.org.uk which has very similar syntax to gnuplot, but with the rough edges cleaned up. It handles colors and line styles quite neatly, and homogeneously between x11 and eps/pdf terminals.
The Pyxplot script for what you want to do above would be:
set style 1 lt 1 lw 3 color red
set style 2 lt 1 lw 3 color blue
set style 3 lt 2 lw 3 color red
set style 4 lt 2 lw 3 color blue
plot 'data1.dat' using 1:3 w l style 1,\
'data1.dat' using 1:4 w l style 2,\
'data2.dat' using 1:3 w l style 3,\
'data2.dat' using 1:4 w l style 4`
Edit: Sorry, this won't work for you. I just remembered the line color thing is in 4.2. I ran into this problem in the past and my fix was to upgrade gnuplot.
You can control the color with set style line as well. "lt 3" will give you a dashed line while "lt 1" will give you a solid line. To add color, you can use "lc rgb 'color'". This should do what you need:
set style line 1 lt 1 lw 3 pt 3 lc rgb "red"
set style line 2 lt 3 lw 3 pt 3 lc rgb "red"
set style line 3 lt 1 lw 3 pt 3 lc rgb "blue"
set style line 4 lt 3 lw 3 pt 3 lc rgb "blue"
I know the question is old but I found this very helpful http://www.gnuplot.info/demo_canvas/dashcolor.html . So you can choose linetype and linecolor separately but you have to precede everything by "set termoption dash" (worked for me in gnuplot 4.4).