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
Related
I'm using gnuplot to create a graph calling it from powershell.
I do the following as the beginning of the script
reset
set term windows color enhanced size 22cm, 12cm font 10
But each time i get error when trying load the file
gnuplot> load 'draw.sh'
gnuplot> set terminal windows color enhanced size 22cm, 12cm font 10
^
"draw.sh" line 2: size requires 'width,heigth'
Why is there an error and how to fix it?
The original script included:
reset
set term postscript enhanced color size 22cm, 12cm font 10
And this did not give the error. I need the terminal for windows, the original script was run on Mac. I don't know why this isn't working.
From help term windows
... size defines the width and height of the window's drawing area in
pixels, ...
Thus, because monitor units are in pixel, remove the unit cm.
set terminal windows color enhanced size 640, 320 font 10
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
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. :)
I use FORTRAN 77 code to generate data (saved as filename.dat) of simple physics situations containing x-y co-ordinates like a projectile.
My data files usually have 2 or 3 columns like so:
1 1
2 2
3 3
4 4
5 5
I can plot (2d and 3d) using Gnuplot just fine but I want to animate the point and make it look like a real projectile on the graph and then save it as a .gif file.
I am new to bash scripts so please assume I do not know a single thing about scripts, if it involves using those.
Thanks!
Problem solved. This is the code I am using:
set terminal gif animate delay 100
set output 'output.gif'
stats 'data.dat' nooutput
set xrange [-0.5:1.5]
set yrange [-0.5:5.5]
do for [i=1:int(STATS_blocks)] {
plot 'data.dat' index (i-1) with circles
}
Gnuplot version 4.6 or higher is required for this to work. This code must be entered in gnuplot. This requires the data to be in the following format:
1 1
2 2
3 3
4 4
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