automatically set xrange in gnuplot - range

Is there any way to set automaticaly xrange in gnuplot base on how many lines have my datafile ?
I tried autoscale but it still let me few centimeters of free space at the end of my plot.
I mean something like
set xrange ["0":"EOF"]
datafile sample:
0|18:33:56|5.6094713|-2.5295162|0.05702305
1|18:33:56|5.506433|-1.9757175|0.25703526
2|18:33:56|5.7228355|-1.7813735|0.59802055
3|18:33:56|5.8039265|-1.6758609|0.97007275
4|18:33:56|5.675423|-1.581326|1.2965202
5|18:33:56|5.3796544|-1.4743104|1.4236889
Can I put some mark at the end of datafile and set it in gnuplot or ?

If your gnuplot's version is 4.6 or later, you can use stats command
stats 'datafile' using 1
set xrange [0:STATS_records]
You can also use other statistical variables such as STATS_min, STATS_max.
For more information, type help stats in your gnuplot's prompt.

To have a tightly fitted xrange, use
set autoscale xfix

Related

GnuPlot - 2D chart doesn't mark double values [duplicate]

I want to plot some stockpile data.
The data is located in a csv-file and I already got an almost accurate plot, so reading from file isn't the problem.
set terminal pdf
set output "gnuplot/".MATNUM."-2012.pdf"
set datafile separator ";"
stats 'Stock-2012.csv' every ::4::18 using MATNUM nooutput
set border 3
set tics nomirror
set xzeroaxis
set xrange[0:14]
set xtics 1,1,13
set xtics rotate 90
set ylabel MATUNIT
maxplot = sprintf("Amount max:\n%.2f ".MATUNIT, STATS_max)
plot 'Stock-2012.csv' every ::4::18 using ($0+1):MATNUM:xticlabels(2) with linespoints title "Amount", STATS_max with lines lc rgb 'blue' title maxplot
Where MATNUM and MATUNIT are commandline arguments, representing materialnumber (which is the columntitle in the datafile) and the unit in which the material is measured.
The x-values in my datafile are decimals, but gnuplot seems to cut off the fractional digits. For example 12,98 (commata are used as decimal separator, because it's a german stockpile) results in a datapoint at y=12.
I'm not sure but I think this happens only at the maximum and minimum y-value, as STATS_max is an integer every time.
What can I do to get my points at the right y-value?
Unfortunately you did not show any data from you file, but I guess you are using commas as decimal separators. In that case you need to set the right decimal sign for reading the input. You can use e.g.
set decimalsign locale
or use an explicit locale (this must be installed)
set decimalsign locale "de_DE.UTF-8"
Note, that setting an explicit character with set decimalsign ',' does not work because it usually affects only the output format of e.g. tics, but not the input behaviour.

Matlab R2014 issue with saving colormap from colormapeditor

Simple question: in Matlab R2013, Win7(64) (actually always it was like that) after changes made in colormapeditor one can copy the values of colormap just by typing colormap or get(gcf,'Colormap') or similar. But in the version R2014 I cannot do this - no matter what I change in colormapeditor, I get the same default colormap. See this in Matlab command line:
img=surf(peaks)
colormapeditor
(now, change for instance the limit colors to red). Now use:
colormap
get(gcf,'Colormap')
you got the same default UNCHANGED colormap. However if you close colormapeditor and invoke it again it remembers changed colors.
What I'm doing wrong? Is this :New MATLAB Graphics System" responsible for that?
Thank you for help.
Yacek.
PS:
The same states if you use fig=figure first and than try get(fig,'Colormap') or fig.Colormap etc. The command colormapeditor remembers changes, but one cannot save them.
It looks like the colormap is now associated with the axes rather than the figure. So,
cmap = colormap(gca);
will retrieve the map you're looking for.

gnuplot/tk: how to use tkcanvas support gnuplot command like set style fill set xtics rotate

Now I installed the gnuplot version 4.6 and want to draw some histogram chart using the tkcanvas terminal, but find some commands don't work:
set style fill solid 1.0
But the bar is still empty inside
title
Maybe it is related to the first issue. but in the legend part, beside the title text no bar placed beside to show which color it denotes.
set xtics rotate by -45
The labels along x axis has no rotation
Here is a short example:
set term tk
set style data histograms
set style histogram clustered
set style fill solid 1.0 border lt -1
set xtics rotate by -45
plot for [col=2:5] "histogramdata.txt" using col:xticlabels(1) title columnheader(col)
OK, based on my study I find what the issue. yes, when use tkcanvas as the terminal, the set style fill solid and set xtics rotate both failed. Them can work well for x11 terminals
so the name for this post should be tkcanvas cann't support gnuplot command like: set style fill....
Any idea?
You are doing nothing wrong, the tkcanvas terminal simply doesn't support filled polygons and rotated text, as the test command also tells you:
To see this, use the simple script
set terminal tkcanvas
set output 'test.file'
test
And then, after invoking wish, execute the following Tcl/Tk commands:
source test.file
canvas .c
pack .c
gnuplot .c
which on my system gives

Legend for different curves on different places in gnuplot png terminal

I want to place the titles of two curves on different places. For example for the first curve "set key top right" and for the second curve "set key bottom left" in PNG terminal. Tryind different combinations I got nothing. Where is an error in the following file ? Thank you!
set key top right
plot sin(x)/x
unset key
set key bottom left
replot sin(x)
set term png
set output "file.png"
replot
In general you cannot do this. One workaround is to use multiplot to stack the plots. But, if done properly, this requires you to use fixed margins, so that you may not have a very flexible solution:
set terminal pngcairo
set output 'file.png'
set lmargin 5
set bmargin 2
set multiplot
plot sin(x)/x lt 1
unset tics
unset border
set key bottom left
plot sin(x) lt 2
unset multiplot
You could also use a combination of set arrow and set label commands, e.g.,
set arrow 1 from 6,0.9 to 9,0.9 nohead lt 1
set label 1 'sin(x)/x' at 5.5,0.9 right
set arrow 2 from -4,-0.3 to -7,-0.9 nohead lt 2
set label 2 'sin(x)/x' at -7.5,-0.9 right

removing units from plot

I try to remove the Matlab-given units from this plot but I don't find a way:
figure(1)
hold on
set(gcf,'PaperUnits','centimeters',...
'PaperSize',[15 9],...
'PaperPosition',[0 0 15 9]);
pzmap(LB); sgrid; grid on; axis equal;
title('');
xlabel('\sigma [rad/s]')
ylabel('\omega [rad/s]')
hold off
After that commands the xlabel looks like this: \sigma [rad/s] (seconds^-1). The seconds comes with pzmap. How can I remove them?
I found, some strange behavour:
If generate code by the figure plot manager I get this:
% Create xlabel
xlabel('\sigma [rad/s] (seconds^{-1})','Units','pixels');
Why???
Now I get it - without pzmap/pzplot
pol = pole(sys)
figure(1)
plot(real(pol(:)),imag(pol(:)),'x')
title('');
xlabel('\sigma [rad/s]');
ylabel('\omega [rad/s]');
sgrid
pzmap is a high-level convenience function, but it's not the best choice for this (it's also stored in a folder of obsolete functions in R2013a, so it may get marked for official removal in the future). Instead, let's create an example plot using pzplot directly instead of pzmap. This is still a plot function that does a lot under the hood, but it returns a handle, h, to the plot:
sys = rss(3,2,2);
h = pzplot(sys);
sgrid;
axis equal;
We can via the options of a pzplot with getoptions:
p = getoptions(h)
To set the labels and units as you desire, you might try this, using setoptions:
p.Title.String = '';
p.XLabel.String = '\sigma';
p.YLabel.String = '\omega';
setoptions(h,p);
I believe that the units of 'seconds-1' that the plot displays is equivalent to the 'rad/s' that you want to specify. I know that the two look is very different (I prefer being specific about radians myself), but that's a disadvantage of using such a plot function that tries to do everything for you. If you wanted to remove the default string or add another option, you'd likely have to do some low level hacking. An easier way around, might be to use the "Generate Code..." command ("Generate M-File..." in older versions") under the "File" menu in the figure's toolbar and edit the plot labels there (there's also a programmatic option for this on the File Exchange). Or you could output to postscript and edit that.
Alternatively, you can use pzoptions to create a list of options to pass to pzplot or pzmap (undocumented in the latter case):
p = pzoptions;
p.Title.String = '';
p.XLabel.String = '\sigma';
p.YLabel.String = '\omega';
sys = rss(3,2,2);
pzplot(sys,p);
sgrid;
axis equal;
You'll see that that for some reason the text size is much smaller in this case. pzplot and pzmap must set the font size to 10 themselves. You could easily do this.
Fore more on customizing this and related Control toolbox plots, see this article.
After intense low-level digging, there is actually a pretty simple way to override the default behavior.
p = pzplot(sys);
p.AxesGrid.XUnits = 'rad/s';
p.AxesGrid.YUnits = 'rad/s';
Changes appear to take effect immediately. I have even tried setting the value to nothing, i.e.
p.AxesGrid.XUnits = '';
and it effectively removes the annoying parenthesis with the units. Technically, matlab creates a custom-class element they store under the name AxesGrid in the resppack.mpzplot class instance, with some standard LTI-behavior. You can probably work around some stuff by "injecting" a script with the same name as one of the standard library functions, so that it will be called instead, and change things in there, but this is the closest I have come to removing those annoying units in a few lines.
As a side info, the AxesGrid object is initialized in
...\controllib\graphics\#resppack\#pzplot\initialize.m
should you want to check it out.