I have a data file of the format:
172.168.1.1 12
192.168.1.0 1
.......
They are IP addresses with corresponding connections to them. I want to draw a histogram of connection to each IP address. However, gnuplot consider the column one to be numeric and thus plots a histogram differently. Is there a way to tell gnuplot to consider the column 1 as string labels instead?
I haven't had this problem myself, but this might work:
plot "myfile" using 2:xticlabels(1)
This question can also be relevant for you.
Related
I would like to create a histogram to plot real values such as
values = [17.711934920693217, 21.962771788060337, 24.570616100324703, 18.862357360933803, 19.35670692079581, 16.21371067895039, 15.723282991698177, 13.420629746222984, 10.346425858632237].
I'm using pyplot.hist but all I obtain is an empty histogram. Is it possibile to plot these values directly?
I'm not exactly sure what you mean in your question by "real values", do you mean setting the heights of the bars? an expected result would be good.
However, you could possibly want to use plt.bar instead
plt.bar(range(len(values)), values)
I have a solist of 4 point patterns.
I then defined
names(solist)=c("a","b","c","d") as a vector of 4 string elements.
Now when I plot just the solist like plot(solist), I get the customized titles on the plot
I then created a hyperframe as h=hyperframe(experiments=solist)
Now when I plot like plot(h$experiments) , I have lost the names and the plots now have a default 1,2,3,4 as plot titles.
I do not know if this is how it should be or if I miss something. I would like to retain the names of the solist in the hyperframe so that when I plot the hyperframe, I have the same names as the solist.
Please guide.
A hyperframe does not allow the individual entries to have names. There can be row names and column names, but individual entries cannot have names.
If you had done row.names(h) <- c("a","b","c","d") then plot(h$experiments) would have shown these names as the titles of the plot panels.
PS: Avoid using solist as the name of an object. This could conflict with the function solist().
How can Newton's basin of attraction be created from a data file?
I got 10000 points in the range -2, 2 and their zeros for complex function z^3-1. I'd like to plot them with three different colors to create basin of convergence.
Data I've obtained from my program is available here. The format is like this:
(-0.422468,1.36075) (-0.5,0.866025)
(1.19376,1.1324) (1,-6.76273e-19)
...
First two numbers in "( )" are complex start points, the second two are the zero that it converges to. Zeros are exact to the level of e-10, I can easily change it to e-16.
From what I understand, I would try something like:
plot 'yourdata.dat' using 1:2:(arg($3+$4*{0,1})) '(%lf,%lf) (%lf,%lf)' palette
The string '(%lf,%lf) (%lf,%lf)' is the format of your data, so that gnuplot can read it as a file of four columns. Then, you can select the columns to be plotted with using 1:2:(arg(...)); in this case, the x-axis is the real part of the starting points (column 1), and the y-axis is its imaginary part (column 2). The third part of using, arg($3+$4*{0,1}), and the option palette are used to chose the color depending on the phase of the complex zero (columns $3 and $4).
I have a file with several columns of data (the number of columns N might me quite large). I want to plot all the columns as a function of the first one (that is, plot 'Data.txt' using 1:2, 'Data.txt' using 1:3, ..., 'Data.txt' using 1:N). The thing is, I want this command to work when I don't know the number of columns. Is that possible?
You can count the number of columns in your file using awk and then do a looped plot. There might be a function to get the number of columns in your data file already implemented in gnuplot but I do not know it. You can try this:
N=`awk 'NR==1 {print NF}' Data.txt`
plot for [i=2:N] "Data.txt" u 1:i
If your first row contains a comment (starting by #) change NR== to the appropriate value. If you have a variable number of columns for different rows then you might want to complicate the awk command.
#Paul shows a correct answer, but an even simpler variant is possible. You can use an open-ended iteration that stops when it runs out of columns:
plot for [n=1:*] "data.dat" using 1:n title sprintf("Column %d",n)
Seeing that this questions is very old, I still think it is worth revisiting, as you now (Version 5.2) have access to the number of columns in a file without relying on external tools.
DATA = 'path/to/datafile.txt'
stats DATA
will (among other stuff) store the number of columns in the variable STATS_columns, so now you can do something like:
N=STATS_columns
plot for [i=2:N] DATA using 1:i title DATA.' '.i with lines
which will plot all the columns (assuming the first column is used for the x-axis) with legend entries matching the filename plus the column number.
PS: Not sure when this feature was introduced, but it's there now. :)
You will need two script files:
==== main.plt ====
set <whatever>
N=1
load "loop.plt"
==== loop.plt ====
replot "data.dat" u 0:(column(N))
N+=N+1
if(N<4) reread
Function reread cause that the next line to read by gp will be loop.plt:1. Now you will plot first three columns of data.dat. Function replot adds plot to current image.
Or see: how to convert integer to string in gnuplot?.
I have a series of numbers in a file that I can already plot using gnuplot.
The tricky question: I have a bunch of ranges (positions), like
1-11
12-50
51-500
500-512
From this I can calculate the length of the actual range. Based on this lenght, I want to dynamically scale the x-axis for that actual range. Bigger length should produce more "compression" on the x-axis.
I am not sure I understand your question. Does
set xrange [51:500]
do what you want?