I'm new with gnuplot loops, and I don't know why is it crashing...
I want to make a plot with 10 different .txt data files and after that 10 different plot from these .txt-s. (Sorry for my english)
note: I am using win 8.1 -> I know I should use gnuplot with Ubuntu but that's the situation for now...
So here is my script:
cd'C:\RégiPC\asztal222\TDK\fittnessmodell\fittnessmodell\Incidencia s0 pk emel\001'
set title "Fitness előny nélkül pk=0.7+=0.03"
set term png size 1280,768
set key tmargin left
set xlabel "Idő"
set ylabel "Populációméret"
set output "Incidencia_N_10.png"
p for[i=0:9] 'Incidencia_'.i.'.txt' u 1:2 title 'N'.i
// here I want to do 10 different curves in one plot
unset output
do for[i=0:9]
{
set output 'Incidencia_minden_'.i.'.png'
p 'Incidencia_'.i.'.txt' u 1:2 title 'N'.i , 'Incidencia_'.i.'.txt' u 1:3 title 'nacd'.i,'Incidencia_'.i.'.txt' u 1:4 title 'nscd'.i,'Incidencia_'.i.'.txt' u 1:5 title 'nscdplusd'.i
unset output
} // in this do for loop I want to do 10 different plots from 10 different .txt files
Please help and sorry if it is too trivial...
Thank you and Happy New Year!!!!
Good evening sir!
I use Ubuntu 14.04 and your code works fine with some change listed below.
1.) If you want to comment something you should use # instead of //.
2.) A problem occurs in the do for loop. You accidentally put the braces into a new line which is incorrect according to my gnuplot (version 4.6). The correct way to use it:
do for [i=0:9] {
set output 'Incidencia_minden_'.i.'.png'
p 'Incidencia_'.i.'.txt' u 1:2 title 'N'.i , 'Incidencia_'.i.'.txt' u 1:3 title 'nacd'.i,'Incidencia_'.i.'.txt' u 1:4 title 'nscd'.i,'Incidencia_'.i.'.txt' u 1:5 title 'nscdplusd'.i
unset output
}
After these changes the code don't make any error or crash in my computer.
I don't know if this works on Windows. You have to try it. :)
Related
I am plotting data with y-errorbars on a pdfcairo terminal and have a problem to properly size the data points:
plot "test.data" u ($6) : 10 : 11 with yerrorbars pt 7 ps 0.5 t
ps 1 gives too large a point and decreasing ps gives strange results. Interestingly, on a windows terminal everything looks ok, but the pdfcairo terminal makes problems. What is wrong?
Hmm. I see a problem also but I do not know what causes it.
Workaround
Plot the data twice, once to show the error bars and once to show the variable size points. Here is a screenshot of the pdf output using gnuplot 5.4.4
set term pdfcairo
set output 'yerrorbar.pdf'
set sample 51
set xrange [0:1]
set key left reverse
plot '+' using 1:1:(0.2) with yerrorbar lc 'blue' pt 7 ps 0, \
'+' using 1:1:1 with points lc 'blue' pt 7 ps variable
I'm trying to customize my progress bars in Conky (battery_bar, fs_bar...) in order to have a layout other than the default one, which looks like:
Following this answer I managed to create a filesystem usage bar, and with some code modifying, a battery status one, looking like this.
This bar is generated following the following script, a variation of the one suggested for in the previous answer:
#!/bin/bash
cat /sys/class/power_supply/BAT0/capacity | awk 'NR==1{
n = ($1+0)/2; yellow = 20; red = 40;
if(n>=red) {
r = "${color ff0000}";
for(;n>=red;n--)
r = r "\\#"
}
if(n>=yellow){
y = "${color ffff00}";
for(;n>=yellow;n--)
y = y "\\#"
}
g = "${color 00ff00}";
for(;n>0;n--)
g = g "\\#";
print g y r
}'
My problem is that the bar's length is constant, and it will constantly resize the Conky window until it's able to show the 100% of its capacity, full size. This obviously forces my Conky window size to be at least the length of those custom bars, deforming the screen.
As far as I have experimented, I can see that Conky's default bars are 'responsive' to the windows size they are given, and never cause problems in this aspect; as they resize themselves without a problem. I would like to know how are they programmed in order to apply the same algorithm to my code the cleanest way.
One thing you can do fairly easily is add some programming in lua to change the font size just before drawing the bar. The size would be calculated from the window width divided by 50. If using proportional fonts you might need some small scale factor to account for the fact that a font of a given size might have a # character of a different width.
Create a file to hold the lua script, say ~/mylua.lua with the following
-- called with (50) return "${font DejaVu Sans Mono:size=13.6}"
function conky_mysetfont(numchars)
if conky_window.width<=0 then return "" end
fontname = "DejaVu Sans Mono"
scale = 1.2
fontsize = conky_window.text_width/tonumber(numchars)*scale
-- print("result=",fontsize) -- debug
return "${font "..fontname..":size="..fontsize.."}"
end
The -- starts a comment. If you remove the one in front of print, you
should see something like result= 13.6 on stdout if you run conky
from the terminal. The function takes a parameter, the length of your bar,
ie 50 characters. It returns a conky command string like ${font
somefont:size=13.6}. .. is a concatenation operator. The above choses a fixed-width font DejaVu Sans Mono and an approximate scale of 1.2.
In your ~/.conkyrc, add in the conky.config = {...} part (for 1.10) a line
lua_load = '~/mylua.lua',
to load in your code. In the conky.text = [[...]] part, replace the line
where call your script, eg
${execpi 30 ~/mydf /}
with
${lua_parse conky_mysetfont 50}
${execpi 30 ~/mydf /}
$font
i.e. call your lua function, passing the number of characters, your
original script, then reset the original default font and size.
In conky 1.9 when you resize the window with the mouse, this code
will change the font size to match, but in 1.10 the size changes only when
the window changes size due to some internal trigger. It seems this is a
regression.
Note that many people don't have problems with resizing because they
display conky on their fixed-size desktop background.
Also, once you start using lua, an alternative to using text for bars
is to get lua to draw any sort of graphics such as coloured lines and
boxes. You can read about this in the wiki, and see amazing
examples
of what is possible.
possibly not 100% an answer to your question but you may give it a try
I am using conky 1.10.6 on a raspberry pi with KDE Desktop.
I am using one line to display most of the file systems (vfat partition excluded with option -x).
${execpi 60 df -h --output=source,target -x vfat| grep '^/dev/' | cut --characters=6- | awk '{ print $1," ", $2,"${alignr}${fs_size " $2 "}","${alignr}${color blue}${fs_bar 11,100 " $2"}\n\n\n,${alignr}${voffset -39}${color white}${fs_used_perc " $2 "}%" }'}
Result:
cheers
How can I create a legend with whitespaces in the column header with autotitle? E.g. the first two lines of the data file:
T "x high" "x low"
0.1 3.14 0.0554
The legend should be:
T
x high
x low
Unfortunately gnuplot interprets it like this:
T
x
high
The quotes are simply ignored and the second column header is split into two. I couldn't find any information about this on the internet.
For me, which gnuplot version 4.6 the following works:
set key autotitle columnheader
plot 'file.dat' using 1:2 , '' using 1:3
and gives the legend
x high
x low
There is no problem with quoting.
Ok, I know this question might sound silly, but I cannot find out why the demo from the gnuplot official website (you can see an example on the left hand side in the picture below) looks different (and much nicer) than what I get from running the same demo on my machine (on a wxt terminal).
Is there a configuration file (something like a ~/.gnuplotrc) where a theme has been specified? If so, does anyone know what theme has been used here?
Here you have an image where you can compare the website and the locally-made versions
Moreover, just an off topic curiosity, is anyone using gnuplot seriously, or it's basically used to plot simple batch plots and for Octave?
It is very likely that the person who made the demo (likely Ethan Merritt) has defined his/her own set of default line colors, which are reflected in the demo images. You can do this yourself (see help set linetype). Example from gnuplot e-mail list:
# Ethan A Merritt - my preference for gnuplot colors
# 2 3 4 5 6 8 are borrowed from the colors_podo set
#
set linetype 1 lc rgb "dark-violet" lw 1
set linetype 2 lc rgb "#009e73" lw 1
set linetype 3 lc rgb "#56b4e9" lw 1
set linetype 4 lc rgb "#e69f00" lw 1
set linetype 5 lc rgb "#f0e442" lw 1
set linetype 6 lc rgb "#0072b2" lw 1
set linetype 7 lc rgb "#e51e10" lw 1
set linetype 8 lc rgb "black" lw 1
set linetype 9 lc rgb "gray50" lw 1
set linetype cycle 9
There are no built-in gnuplot themes, only sets of settings which change colors.
And yes, I do use gnuplot seriously! I use it both for simple plotting and for scientific publication.
There are nice palettes available at https://github.com/Gnuplotting/gnuplot-palettes and https://github.com/aschn/gnuplot-colorbrewer
These define line styles that you can use explicitly, but with some shell escaping tricks you can make them override the default linetypes, with something like this in your .gnuplot:
palettefile(n) = sprintf("<sed 's/set style line/set linetype/' /path/to/gnuplot-gnuplot-palettes/%s.pal", n)
load palettefile("rdbu")
You can then call load palettefile(palettename) (where palettename is one of the ones available in the palette repository) whenever you want to change the default palette, so gets quite close to the theming notion mentioned above.
It looks like you are using an older version - the demos are probably made with version 5, which has a new default palette. Your colors look like version 4 or below.
The new version has a lot of new, more powerful features. The new cariolatex terminal can produce really nice publication quality plots out of the box, or with very few tweaks.
The most recent versions of gnuplot (5) have the left hand colour palette by default (at least the wxt terminal). They mention it helps readers with colour blindness.
I suggest you type in: help set colorsequence.
p.s. I also use gnuplot always for all my scientific publications.
Although the result is similar to that of andyras, here is another solution:
as the default colours depend on the terminal type, switch to the desired terminal type with set term and then type
show linetype
I'm using aquaterm 1.0.1 through octave and gnuplot - on my mac - to generate printable plots. When aquaterm generates my plots, it has a habit of cutting off or cropping all of the titles and axis labels.
Is there another imaging program that works with octave that won't have this problem? Or are there other fixes I haven't thought of?
I prefer the plot results from aquaterm more than x11. I wrote an m-file script, which is really a kludge, to fix this problem so aquaterm is useable. It seems like the title and xlabel text strings are written one line too high and too low in the figure window. Note -this script doesn't change the ylabel. If the magnitude of the printed y-coordinate values are too large, it tends to move the ylabel off the left side of the page. Anyway here is my kludge, just run it after all figures are complete.
function fixAxes
%---------------------------------------
%// Kludge to fix scaling of all figures
%// until GNU or I can find real fix.
%// Octave3.2.3 computes the scaling wrong
%// for this mac, such that the title
%// and xlabel are not displayed.
%---------------------------------------
s = get(0,'showhiddenhandles');
set(0,'showhiddenhandles','on');
newpos = [0.13 0.135 0.775 0.75]; %// default is [0.13 0.11 0.775 0.815]
figs = get(0,'children');
if (~isempty(figs))
for k=1:length(figs)
cax = get(figs(k),'currentaxes');
pos = get(cax,'position');
if ~(pos(1) == newpos(1) && ...
pos(2) == newpos(2) && ...
pos(3) == newpos(3) && ...
pos(4) == newpos(4))
set(cax,'position',newpos);
set(0,'currentfigure',figs(k));
drawnow();
endif
endfor
endif
set(0,'showhiddenhandles',s);
%---------------------------------------
endfunction
%---------------------------------------
While I don't know why aquaterm cuts of parts of your plot, you can try using X11 terminal. In Octave, you can say setenv GNUTERM 'x11' to do so.